mirror of
https://e.coding.net/circlecloud/CTZLauncher.git
synced 2024-11-25 02:38:49 +00:00
修改界面背景 线程处理Http事件...
This commit is contained in:
parent
676019830d
commit
757daff238
@ -108,6 +108,9 @@
|
||||
<ItemGroup>
|
||||
<Resource Include="IZ.ico" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="image\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
@ -15,13 +15,13 @@ using System.Threading;
|
||||
|
||||
namespace CityCraft
|
||||
{
|
||||
public class HttpArgs
|
||||
{
|
||||
public enum HttpMethod
|
||||
{
|
||||
GET,
|
||||
POST
|
||||
}
|
||||
public class HttpArgs
|
||||
{
|
||||
public string Url { get; set; }
|
||||
public string Host { get; set; }
|
||||
public int Port { get; set; }
|
||||
@ -32,10 +32,22 @@ namespace CityCraft
|
||||
public string UA { get; set; }
|
||||
public HttpMethod Method { get; set; }
|
||||
}
|
||||
|
||||
public enum HttpReadyState
|
||||
{
|
||||
未初始化,
|
||||
载入,
|
||||
载入完成,
|
||||
交互,
|
||||
完成
|
||||
}
|
||||
public class HttpHelper
|
||||
{
|
||||
public static int State = 0;
|
||||
public static HttpReadyState readyState = HttpReadyState.未初始化;
|
||||
public static int Status = 0;
|
||||
public static string responseBody = "";
|
||||
public static string responseText = "";
|
||||
public static byte[] responseByte = null;
|
||||
public static HttpArgs args = new HttpArgs();
|
||||
public static string ErrMsg = string.Empty;
|
||||
/// <summary>
|
||||
/// 提交方法
|
||||
@ -48,14 +60,19 @@ namespace CityCraft
|
||||
/// <param name="geturl">请求地址</param>
|
||||
/// <param name="cookieser">Cookies存储器</param>
|
||||
/// <returns>请求返回的Stream</returns>
|
||||
public string Get(string url)
|
||||
public void Send(HttpMethod method, string url)
|
||||
{
|
||||
HttpArgs args = ParseURL(url);
|
||||
args.Method = HttpArgs.HttpMethod.GET;
|
||||
string strhtml = InternalSocketHttp(args);
|
||||
return strhtml;
|
||||
readyState = HttpReadyState.载入;
|
||||
ParseURL(url);
|
||||
args.Method = method;
|
||||
new Thread(new ThreadStart(ReciveData)).Start();
|
||||
}
|
||||
|
||||
public void ReciveData()
|
||||
{
|
||||
responseBody = InternalSocketHttp();
|
||||
readyState = HttpReadyState.完成;
|
||||
}
|
||||
/// <summary>
|
||||
/// Post方法
|
||||
/// </summary>
|
||||
@ -76,9 +93,10 @@ namespace CityCraft
|
||||
/// </summary>
|
||||
/// <param name="strUrl">url字符串</param>
|
||||
/// <returns>host字符串</returns>
|
||||
private HttpArgs ParseURL(string strUrl)
|
||||
private void ParseURL(string strUrl)
|
||||
{
|
||||
HttpArgs args = new HttpArgs();
|
||||
if (args == null)
|
||||
args = new HttpArgs();
|
||||
|
||||
args.Host = "";
|
||||
args.Port = 80;
|
||||
@ -91,7 +109,7 @@ namespace CityCraft
|
||||
//http://www.alibaba.com/products/Egg_Laying_Block_Machine/1.html
|
||||
int iIndex = strUrl.IndexOf(@"//");
|
||||
if (iIndex <= 0)
|
||||
return null;
|
||||
args = null;
|
||||
//www.alibaba.com:80/products/Egg_Laying_Block_Machine/1.html
|
||||
string nohttpurl = strUrl.Substring(iIndex + 2);
|
||||
string address = nohttpurl;
|
||||
@ -115,13 +133,12 @@ namespace CityCraft
|
||||
args.Host = address;
|
||||
args.Port = 80;
|
||||
}
|
||||
return args;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Socket
|
||||
|
||||
string InternalSocketHttp(HttpArgs args)
|
||||
string InternalSocketHttp()
|
||||
{
|
||||
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
|
||||
{
|
||||
@ -132,7 +149,7 @@ namespace CityCraft
|
||||
socket.Connect(args.Host, args.Port);
|
||||
if (socket.Connected)
|
||||
{
|
||||
byte[] buff = ParseHttpArgs(args);
|
||||
byte[] buff = ParseHttpArgs();
|
||||
if (socket.Send(buff) > 0)
|
||||
{
|
||||
List<byte> responseBytes = new List<byte>();
|
||||
@ -143,7 +160,9 @@ namespace CityCraft
|
||||
responseBytes.AddRange(new List<byte>(buffer));//添加数据到List
|
||||
iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);//继续接收数据
|
||||
}
|
||||
return ParseResponse(responseBytes.ToArray()/*转换List为数组*/, args);
|
||||
responseByte = responseBytes.ToArray();
|
||||
readyState = HttpReadyState.载入完成;
|
||||
return ParseResponse(responseByte);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -155,28 +174,27 @@ namespace CityCraft
|
||||
}
|
||||
}
|
||||
|
||||
private string ParseResponse(byte[] responseBytes, HttpArgs args)
|
||||
private string ParseResponse(byte[] responseBytes)
|
||||
{
|
||||
string responseStr = Encoding.UTF8.GetString(responseBytes);
|
||||
string[] splitStr = responseStr.Split(new char[4] { '\r', '\n', '\r', '\n' }, 2);
|
||||
if (splitStr.Length == 2)
|
||||
int splitindex = responseStr.IndexOf("\r\n\r\n");
|
||||
if (splitindex > 0)
|
||||
{
|
||||
string responseHeader = splitStr[0];
|
||||
string responseBody = splitStr[1];
|
||||
|
||||
string responseHeader = responseStr.Substring(0, splitindex);
|
||||
string responseBody = responseStr.Substring(splitindex + 4);
|
||||
if (responseHeader.StartsWith("HTTP/1.1 400"))
|
||||
{
|
||||
State = 400;
|
||||
Status = 400;
|
||||
return string.Empty;
|
||||
}
|
||||
else if (responseHeader.StartsWith("HTTP/1.1 404"))
|
||||
{
|
||||
State = 404;
|
||||
Status = 404;
|
||||
return string.Empty;
|
||||
}
|
||||
else if (responseHeader.StartsWith("HTTP/1.1 302") || responseHeader.StartsWith("HTTP/1.1 301"))
|
||||
{
|
||||
State = 302;
|
||||
Status = 302;
|
||||
int start = responseHeader.ToUpper().IndexOf("LOCATION");
|
||||
if (start > 0)
|
||||
{
|
||||
@ -185,18 +203,19 @@ namespace CityCraft
|
||||
args.Url = sArry[0].Remove(0, 10);
|
||||
if (args.Url == "")
|
||||
return string.Empty;
|
||||
return InternalSocketHttp(args); //注意:302协议需要重定向
|
||||
return InternalSocketHttp(); //注意:302协议需要重定向
|
||||
}
|
||||
}
|
||||
else if (responseHeader.StartsWith("HTTP/1.1 200")) //读取内容
|
||||
{
|
||||
State = 200;
|
||||
Status = 200;
|
||||
//解压
|
||||
DecompressWebPage(ref responseBytes, responseHeader);
|
||||
//转码
|
||||
responseBody = DecodeWebStringByHttpHeader(responseBytes, responseHeader);
|
||||
responseBody = DecodeWebStringByHtmlPageInfo(responseBytes, responseBody);
|
||||
}
|
||||
int splitindex = responseBody.IndexOf("\r\n\r\n");
|
||||
splitindex = responseBody.IndexOf("\r\n\r\n");
|
||||
if (splitindex > 0)
|
||||
responseBody = responseBody.Substring(splitindex + 4);
|
||||
else
|
||||
@ -295,10 +314,10 @@ namespace CityCraft
|
||||
return strResponse;
|
||||
}
|
||||
|
||||
private byte[] ParseHttpArgs(HttpArgs args)
|
||||
private byte[] ParseHttpArgs()
|
||||
{
|
||||
StringBuilder bulider = new StringBuilder();
|
||||
if (args.Method == HttpArgs.HttpMethod.POST)
|
||||
if (args.Method == HttpMethod.POST)
|
||||
{
|
||||
bulider.AppendLine(string.Format("POST {0} HTTP/1.1", args.Url));
|
||||
bulider.AppendLine("Content-Type: application/x-www-form-urlencoded");
|
||||
@ -325,7 +344,7 @@ namespace CityCraft
|
||||
if (!string.IsNullOrEmpty(args.Cookie))
|
||||
bulider.AppendLine(string.Format("Cookie: {0}", args.Cookie));
|
||||
|
||||
if (args.Method == HttpArgs.HttpMethod.POST)
|
||||
if (args.Method == HttpMethod.POST)
|
||||
{
|
||||
bulider.AppendLine(string.Format("Content-Length: {0}\r\n", Encoding.Default.GetBytes(args.Data).Length));
|
||||
bulider.Append(args.Data);
|
||||
|
@ -1,12 +1,20 @@
|
||||
<Window x:Class="CTZLauncher.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:s="clr-namespace:System;assembly=mscorlib"
|
||||
ResizeMode = "NoResize"
|
||||
MouseMove="Window_MouseMove"
|
||||
Title="MainWindow" Height="768" Width="1024" Background="#FF3A3A3A" AllowsTransparency="True" WindowStyle="None" Visibility="Visible" HorizontalContentAlignment="Center" HorizontalAlignment="Center" Icon="ico.ico" VerticalAlignment="Center" VerticalContentAlignment="Center" WindowStartupLocation="CenterScreen" Initialized="Window_Initialized" Loaded="Window_Loaded">
|
||||
Title="MainWindow" Height="768" Width="1024" Background="#FF3A3A3A" AllowsTransparency="True" WindowStyle="None" Visibility="Visible" HorizontalContentAlignment="Center" HorizontalAlignment="Center" Icon="ico.ico" VerticalAlignment="Center" VerticalContentAlignment="Center" WindowStartupLocation="CenterScreen" Initialized="Window_Initialized" Loaded="Window_Loaded" FontFamily="Microsoft YaHei">
|
||||
|
||||
<Window.Resources>
|
||||
<!-- s:Double表示了变量类型 x:key表示了变量名 -->
|
||||
<s:Double x:Key="m_nFontSize">
|
||||
32
|
||||
</s:Double>
|
||||
|
||||
<!--
|
||||
<ControlTemplate x:Key="CornerButton" TargetType="{x:Type Button}">
|
||||
<Border BorderBrush="#FFA1A1A1" BorderThickness="1" CornerRadius="10" Background="{TemplateBinding Background}">
|
||||
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" CornerRadius="10" Background="{TemplateBinding Background}">
|
||||
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
@ -15,39 +23,50 @@
|
||||
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center" Background="#FFA1A1A1"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
-->
|
||||
<ControlTemplate x:Key="CornerButton" TargetType="{x:Type Button}">
|
||||
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="1" CornerRadius="0" Background="{TemplateBinding Background}">
|
||||
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
<ControlTemplate x:Key="CornerTextBox" TargetType="{x:Type TextBox}">
|
||||
<Border BorderBrush="#FFA1A1A1" BorderThickness="3" CornerRadius="0" Background="#FFA1A1A1">
|
||||
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center" Background="#FFA1A1A1"/>
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Window.Resources>
|
||||
<Grid Name="outline" Background="#FF3A3A3A" Height="768" Width="1024" VerticalAlignment="Top" MouseLeftButtonDown="outline_MouseLeftButtonDown">
|
||||
<Grid Margin="20,0" Background="#FF3A3A3A" Height="60" VerticalAlignment="Top">
|
||||
<Label x:Name="barl1" Content="主导航" HorizontalAlignment="Left" Margin="15,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barl2" Content="主导航" HorizontalAlignment="Left" Margin="120,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barl3" Content="主导航" HorizontalAlignment="Left" Margin="220,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barl4" Content="主导航" HorizontalAlignment="Left" Margin="325,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barr4" Content="主导航" HorizontalAlignment="Right" Margin="0,15,15,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barr3" Content="主导航" HorizontalAlignment="Right" Margin="0,15,120,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barr2" Content="主导航" HorizontalAlignment="Right" Margin="0,15,220,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barr1" Content="主导航" HorizontalAlignment="Right" Margin="0,15,325,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Grid Name="outline" Background="#FF3299CC" Height="768" Width="1024" VerticalAlignment="Top" MouseLeftButtonDown="outline_MouseLeftButtonDown">
|
||||
<Grid Margin="20,0" Background="#FF3299CC" Height="60" VerticalAlignment="Top" >
|
||||
<Label x:Name="barl1" Content="论坛" HorizontalAlignment="Left" Margin="15,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barl2" Content="资源下载" HorizontalAlignment="Left" Margin="120,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barl3" Content="新手指南" HorizontalAlignment="Left" Margin="220,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barl4" Content="赞助我们" HorizontalAlignment="Left" Margin="325,15,0,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barr4" Content="主导航" HorizontalAlignment="Right" Margin="0,15,15,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barr3" Content="主导航" HorizontalAlignment="Right" Margin="0,15,120,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barr2" Content="主导航" HorizontalAlignment="Right" Margin="0,15,220,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Label x:Name="barr1" Content="主导航" HorizontalAlignment="Right" Margin="0,15,325,0" VerticalAlignment="Top" Width="100" Height="30" FontSize="15" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="White" MouseDown="barclick_MouseDown"/>
|
||||
<Image HorizontalAlignment="Left" Height="50" Margin="430,5,0,0" VerticalAlignment="Top" Width="50" Source="ico.ico" RenderTransformOrigin="0.56,0.24"/>
|
||||
<Label Content="魔方" HorizontalAlignment="Left" Height="50" Margin="480,5,0,0" VerticalAlignment="Top" Width="74" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" FontSize="35" />
|
||||
</Grid>
|
||||
<Grid Margin="20,60,20,20" Background="White">
|
||||
<Grid Margin="0,0,0,300">
|
||||
<Grid Margin="30,20,0,20" HorizontalAlignment="Left" Width="550" >
|
||||
<Image Source="image/gg.jpg" />
|
||||
<Border BorderBrush="Black" BorderThickness="2" CornerRadius="5"/>
|
||||
<Image Margin="0,0" Source="ico.ico" Height="200"/>
|
||||
</Grid>
|
||||
<Grid Margin="0,20,30,20" HorizontalAlignment="Right" Width="350">
|
||||
<Border BorderBrush="Black" BorderThickness="2" CornerRadius="5"/>
|
||||
<Grid>
|
||||
<Grid Margin="30,20,30,0" Height="200" VerticalAlignment="Top">
|
||||
<Label Content="————— XX XX 帐 号 —————" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0" HorizontalContentAlignment="Center" FontFamily="微软雅黑" FontSize="15"/>
|
||||
<Label Content="————— XX XX 帐 号 —————" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0" HorizontalContentAlignment="Center" FontSize="15"/>
|
||||
<TextBox Name="username" Template="{StaticResource CornerTextBox}" Height="34" Width="220" TextWrapping="Wrap" Text="" VerticalAlignment="Center" HorizontalAlignment="Center" HorizontalContentAlignment="Center" FontFamily="微软雅黑" Foreground="White" FontSize="20" Margin="33,40,33,126" />
|
||||
<Label Content="————— XX XX 密 码 —————" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,80" HorizontalContentAlignment="Center" FontFamily="微软雅黑" FontSize="15"/>
|
||||
<Label Content="————— XX XX 密 码 —————" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,80" HorizontalContentAlignment="Center" FontSize="15"/>
|
||||
<TextBox Name="password" Template="{StaticResource CornerTextBox}" Height="34" Width="220" TextWrapping="Wrap" VerticalAlignment="Center" HorizontalAlignment="Center" HorizontalContentAlignment="Center" FontFamily="微软雅黑" Foreground="White" FontSize="20" Margin="33,110,33,56" />
|
||||
<Button Margin="225,110,35,56" Template="{StaticResource CornerButton}" Height="30" Width="30" HorizontalAlignment="Center" Content="?" />
|
||||
<Button Margin="222,112,38,58" Template="{StaticResource CornerButton}" Height="30" Width="30" HorizontalAlignment="Center" Content="?" />
|
||||
</Grid>
|
||||
<Grid Margin="30,20,30,30" Height="100" VerticalAlignment="Bottom">
|
||||
<Button Margin="10,35,165,35" Template="{StaticResource CornerButton}" Width="111" HorizontalAlignment="Center" Content="登录" Click="Login_Click" />
|
||||
<Button Margin="165,35,10,35" Template="{StaticResource CornerButton}" Width="111" HorizontalAlignment="Center" Content="注册" />
|
||||
<Button Margin="12,24,167,35" Template="{StaticResource CornerButton}" Width="111" HorizontalAlignment="Center" Content="登录" Click="Login_Click" Background="Green" />
|
||||
<Button Margin="167,24,12,35" Template="{StaticResource CornerButton}" Width="111" HorizontalAlignment="Center" Content="注册" Background="Green" />
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
@ -72,7 +91,6 @@
|
||||
<ListBoxItem Content="新闻" Height="30" FontSize="25"/>
|
||||
<ListBoxItem Content="新闻" Height="30" FontSize="25"/>
|
||||
<ListBoxItem Content="新闻" Height="30" FontSize="25"/>
|
||||
|
||||
</ListBox>
|
||||
</TabItem>
|
||||
<TabItem Header="公告" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="20" />
|
||||
@ -82,21 +100,18 @@
|
||||
<Grid Margin="0,20,30,20" HorizontalAlignment="Right" Width="350" Grid.ShowGridLines="True">
|
||||
<Border BorderBrush="Black" BorderThickness="2" CornerRadius="5">
|
||||
</Border>
|
||||
<Label Margin="0,30,240,0" Content="最大内存" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="Black"/>
|
||||
<TextBox Name="maxmem" Template="{StaticResource CornerTextBox}" Text="" Height="30" Width="200" TextWrapping="Wrap" Margin="120,30,30,188" FontSize="20" />
|
||||
<Label Margin="0,30,240,0" Content="最大内存" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black"/>
|
||||
<TextBox Name="maxmem" Template="{StaticResource CornerTextBox}" Text="" Height="30" Width="200" TextWrapping="Wrap" Margin="120,30,30,188" FontSize="20" TextChanged="maxmem_TextChanged" />
|
||||
<ComboBox Name="javacombo" Height="30" Width="200" FontSize="15" Margin="120,65,30,0" VerticalAlignment="Top"/>
|
||||
<Label Margin="0,65,240,0" Content="JAVA版本" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black"/>
|
||||
<ComboBox Name="gamecombo" Height="30" Width="200" FontSize="15" Margin="120,100,30,0" VerticalAlignment="Top"/>
|
||||
<Label Margin="0,100,240,0" Content="游戏版本" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" FontSize="17" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="Black"/>
|
||||
<Button Name="StartGame" Content="启动游戏" Template="{StaticResource CornerButton}" Background="Gray" HorizontalAlignment="Right" Margin="0,0,30,30" Width="120" Height="70" VerticalAlignment="Bottom" FontSize="20" Click="StartGame_Click"/>
|
||||
<ComboBox Name="javacombo" Height="30" Width="200" FontSize="20" Margin="120,65,30,0" VerticalAlignment="Top"/>
|
||||
<Label Margin="0,65,240,0" Content="JAVA版本" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="Black"/>
|
||||
<ComboBox Name="gamecombo" Height="30" Width="200" FontSize="20" Margin="120,100,30,0" VerticalAlignment="Top"/>
|
||||
<Label Margin="0,100,240,0" Content="游戏版本" HorizontalAlignment="Right" VerticalAlignment="Top" Width="100" Height="30" FontSize="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="Black"/>
|
||||
|
||||
<Button x:Name="SelServer" Content="选择服务器" Template="{StaticResource CornerButton}" Background="Gray" Margin="30,0,200,50" Height="50" Width="100" FontSize="15" Click="StartGame_Click" VerticalAlignment="Bottom"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Button Template="{StaticResource CornerButton}" Width="30" HorizontalAlignment="Right" Content="r" Background="#FFE05A5A" Height="30" VerticalAlignment="Top" FontFamily="Webdings" Click="close_Click" />
|
||||
</Grid>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</Window>
|
||||
|
@ -18,6 +18,7 @@ using KMCCC.Modules;
|
||||
using KMCCC.Modules.JVersion;
|
||||
using CityCraft;
|
||||
using System.IO;
|
||||
using System.Windows.Threading;
|
||||
|
||||
namespace CTZLauncher
|
||||
{
|
||||
@ -41,8 +42,7 @@ namespace CTZLauncher
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("请将启动器放置于.minecraft同级目录...");
|
||||
this.Close();
|
||||
Directory.CreateDirectory(".minecraft");
|
||||
}
|
||||
|
||||
}
|
||||
@ -61,6 +61,7 @@ namespace CTZLauncher
|
||||
}
|
||||
if (!gamecombo.Items.IsEmpty)
|
||||
gamecombo.SelectedIndex = 0;
|
||||
maxmem.Text = "2048";
|
||||
}
|
||||
|
||||
private void Window_MouseMove(object sender, MouseEventArgs e)
|
||||
@ -103,10 +104,30 @@ namespace CTZLauncher
|
||||
private void Login_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
HttpHelper http = new HttpHelper();
|
||||
String result = http.Get("http://127.0.0.1:2000/isregistered?username=" + username.Text);
|
||||
http.Send(HttpMethod.GET,"http://127.0.0.1:2000/isregistered?username=" + username.Text);
|
||||
while(http.readyState!=HttpReadyState.完成){
|
||||
DoEvent();
|
||||
}
|
||||
String result = http.responseBody;
|
||||
Console.WriteLine("服务器返回结果" + result);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
|
||||
/// </summary>
|
||||
public void DoEvent()
|
||||
{
|
||||
DispatcherFrame frame = new DispatcherFrame();
|
||||
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
|
||||
Dispatcher.PushFrame(frame);
|
||||
}
|
||||
public object ExitFrame(object f)
|
||||
{
|
||||
((DispatcherFrame)f).Continue = false;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
@ -118,7 +139,7 @@ namespace CTZLauncher
|
||||
Console.WriteLine("StartGame");
|
||||
LaunchOptions option = new LaunchOptions();
|
||||
option.Mode = LaunchMode.MCLauncher;
|
||||
option.MaxMemory = 2048;
|
||||
option.MaxMemory = int.Parse(maxmem.Text);
|
||||
option.Authenticator = new OfflineAuthenticator(username.Text); // offline
|
||||
option.Version = launcher.GetVersion(gamecombo.Text);
|
||||
launcher.JavaPath = javacombo.Text;
|
||||
@ -130,11 +151,30 @@ namespace CTZLauncher
|
||||
Console.WriteLine(arg2);
|
||||
}
|
||||
|
||||
private void close_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
this.Close();
|
||||
}
|
||||
|
||||
private void maxmem_TextChanged(object sender, TextChangedEventArgs e)
|
||||
{
|
||||
|
||||
//屏蔽中文输入和非法字符粘贴输入
|
||||
TextBox textBox = sender as TextBox;
|
||||
TextChange[] change = new TextChange[e.Changes.Count];
|
||||
e.Changes.CopyTo(change, 0);
|
||||
|
||||
|
||||
|
||||
int offset = change[0].Offset;
|
||||
if (change[0].AddedLength > 0)
|
||||
{
|
||||
double num = 0;
|
||||
if (!Double.TryParse(textBox.Text, out num))
|
||||
{
|
||||
textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength);
|
||||
textBox.Select(offset, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user