1
0
mirror of https://e.coding.net/circlecloud/CTZLauncher.git synced 2024-11-14 00:48:48 +00:00

修改界面背景 线程处理Http事件...

This commit is contained in:
j502647092 2015-07-30 20:42:54 +08:00
parent 676019830d
commit 757daff238
4 changed files with 611 additions and 534 deletions

View File

@ -108,6 +108,9 @@
<ItemGroup> <ItemGroup>
<Resource Include="IZ.ico" /> <Resource Include="IZ.ico" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="image\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.

View File

@ -1,364 +1,383 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Net; using System.Net;
using System.Net.Security; using System.Net.Security;
using System.Net.Sockets; using System.Net.Sockets;
using System.Security.Authentication; using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
namespace CityCraft namespace CityCraft
{ {
public class HttpArgs public enum HttpMethod
{ {
public enum HttpMethod GET,
{ POST
GET, }
POST public class HttpArgs
} {
public string Url { get; set; } public string Url { get; set; }
public string Host { get; set; } public string Host { get; set; }
public int Port { get; set; } public int Port { get; set; }
public string Accept { get; set; } public string Accept { get; set; }
public string Referer { get; set; } public string Referer { get; set; }
public string Cookie { get; set; } public string Cookie { get; set; }
public string Data { get; set; } public string Data { get; set; }
public string UA { get; set; } public string UA { get; set; }
public HttpMethod Method { get; set; } public HttpMethod Method { get; set; }
} }
public enum HttpReadyState
public class HttpHelper {
{ ,
public static int State = 0; ,
public static string ErrMsg = string.Empty; ,
/// <summary> ,
/// 提交方法
/// </summary> }
#region HttpWebRequest & HttpWebResponse public class HttpHelper
{
/// <summary> public static HttpReadyState readyState = HttpReadyState.;
/// Get方法 public static int Status = 0;
/// </summary> public static string responseBody = "";
/// <param name="geturl">请求地址</param> public static string responseText = "";
/// <param name="cookieser">Cookies存储器</param> public static byte[] responseByte = null;
/// <returns>请求返回的Stream</returns> public static HttpArgs args = new HttpArgs();
public string Get(string url) public static string ErrMsg = string.Empty;
{ /// <summary>
HttpArgs args = ParseURL(url); /// 提交方法
args.Method = HttpArgs.HttpMethod.GET; /// </summary>
string strhtml = InternalSocketHttp(args); #region HttpWebRequest & HttpWebResponse
return strhtml;
} /// <summary>
/// Get方法
/// <summary> /// </summary>
/// Post方法 /// <param name="geturl">请求地址</param>
/// </summary> /// <param name="cookieser">Cookies存储器</param>
/// <param name="posturl">请求地址</param> /// <returns>请求返回的Stream</returns>
/// <param name="bytes">Post数据</param> public void Send(HttpMethod method, string url)
/// <param name="cookieser">Cllkies存储器</param> {
/// <returns>请求返回的流</returns> readyState = HttpReadyState.;
public string Post(string url, ParseURL(url);
byte[] bytes, args.Method = method;
CookieContainer cookies, new Thread(new ThreadStart(ReciveData)).Start();
Encoding encoding) }
{
return null; public void ReciveData()
} {
responseBody = InternalSocketHttp();
/// <summary> readyState = HttpReadyState.;
/// 根据Url得到host }
/// </summary> /// <summary>
/// <param name="strUrl">url字符串</param> /// Post方法
/// <returns>host字符串</returns> /// </summary>
private HttpArgs ParseURL(string strUrl) /// <param name="posturl">请求地址</param>
{ /// <param name="bytes">Post数据</param>
HttpArgs args = new HttpArgs(); /// <param name="cookieser">Cllkies存储器</param>
/// <returns>请求返回的流</returns>
args.Host = ""; public string Post(string url,
args.Port = 80; byte[] bytes,
args.Referer = ""; CookieContainer cookies,
args.Cookie = ""; Encoding encoding)
args.Url = ""; {
args.Accept = "text/html";//,application/xhtml+xml,application/xml,application/json;"; return null;
args.UA = "Mozilla/5.0+(Compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)"; }
//http://www.alibaba.com/products/Egg_Laying_Block_Machine/1.html /// <summary>
int iIndex = strUrl.IndexOf(@"//"); /// 根据Url得到host
if (iIndex <= 0) /// </summary>
return null; /// <param name="strUrl">url字符串</param>
//www.alibaba.com:80/products/Egg_Laying_Block_Machine/1.html /// <returns>host字符串</returns>
string nohttpurl = strUrl.Substring(iIndex + 2); private void ParseURL(string strUrl)
string address = nohttpurl; {
iIndex = nohttpurl.IndexOf(@"/"); if (args == null)
if (iIndex > 0) args = new HttpArgs();
{
//www.alibaba.com:80 args.Host = "";
address = nohttpurl.Substring(0, iIndex); args.Port = 80;
args.Url = nohttpurl.Substring(iIndex); args.Referer = "";
} args.Cookie = "";
iIndex = nohttpurl.IndexOf(@":"); args.Url = "";
if (iIndex > 0) args.Accept = "text/html";//,application/xhtml+xml,application/xml,application/json;";
{ args.UA = "Mozilla/5.0+(Compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)";
string[] tempargs = address.Trim().Split(char.Parse(":"));
args.Host = tempargs[0]; //http://www.alibaba.com/products/Egg_Laying_Block_Machine/1.html
args.Port = int.Parse(tempargs[1]); int iIndex = strUrl.IndexOf(@"//");
} if (iIndex <= 0)
else args = null;
{ //www.alibaba.com:80/products/Egg_Laying_Block_Machine/1.html
//www.alibaba.com:80 string nohttpurl = strUrl.Substring(iIndex + 2);
args.Host = address; string address = nohttpurl;
args.Port = 80; iIndex = nohttpurl.IndexOf(@"/");
} if (iIndex > 0)
return args; {
} //www.alibaba.com:80
#endregion address = nohttpurl.Substring(0, iIndex);
args.Url = nohttpurl.Substring(iIndex);
#region Socket }
iIndex = nohttpurl.IndexOf(@":");
string InternalSocketHttp(HttpArgs args) if (iIndex > 0)
{ {
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) string[] tempargs = address.Trim().Split(char.Parse(":"));
{ args.Host = tempargs[0];
try args.Port = int.Parse(tempargs[1]);
{ }
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000); else
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000); {
socket.Connect(args.Host, args.Port); //www.alibaba.com:80
if (socket.Connected) args.Host = address;
{ args.Port = 80;
byte[] buff = ParseHttpArgs(args); }
if (socket.Send(buff) > 0) }
{ #endregion
List<byte> responseBytes = new List<byte>();
byte[] buffer = new byte[1024]; #region Socket
int iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);
while (iNumber > 0)//使用了Connection: Close 所以判断长度为0 时停止接受 string InternalSocketHttp()
{ {
responseBytes.AddRange(new List<byte>(buffer));//添加数据到List using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);//继续接收数据 {
} try
return ParseResponse(responseBytes.ToArray()/*转换List为数组*/, args); {
} socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 1000);
} socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 5000);
} socket.Connect(args.Host, args.Port);
catch (Exception e) if (socket.Connected)
{ {
ErrMsg = e.Message; byte[] buff = ParseHttpArgs();
} if (socket.Send(buff) > 0)
return string.Empty; {
} List<byte> responseBytes = new List<byte>();
} byte[] buffer = new byte[1024];
int iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);
private string ParseResponse(byte[] responseBytes, HttpArgs args) while (iNumber > 0)//使用了Connection: Close 所以判断长度为0 时停止接受
{ {
string responseStr = Encoding.UTF8.GetString(responseBytes); responseBytes.AddRange(new List<byte>(buffer));//添加数据到List
string[] splitStr = responseStr.Split(new char[4] { '\r', '\n', '\r', '\n' }, 2); iNumber = socket.Receive(buffer, buffer.Length, SocketFlags.None);//继续接收数据
if (splitStr.Length == 2) }
{ responseByte = responseBytes.ToArray();
string responseHeader = splitStr[0]; readyState = HttpReadyState.;
string responseBody = splitStr[1]; return ParseResponse(responseByte);
}
if (responseHeader.StartsWith("HTTP/1.1 400")) }
{ }
State = 400; catch (Exception e)
return string.Empty; {
} ErrMsg = e.Message;
else if (responseHeader.StartsWith("HTTP/1.1 404")) }
{ return string.Empty;
State = 404; }
return string.Empty; }
}
else if (responseHeader.StartsWith("HTTP/1.1 302") || responseHeader.StartsWith("HTTP/1.1 301")) private string ParseResponse(byte[] responseBytes)
{ {
State = 302; string responseStr = Encoding.UTF8.GetString(responseBytes);
int start = responseHeader.ToUpper().IndexOf("LOCATION"); int splitindex = responseStr.IndexOf("\r\n\r\n");
if (start > 0) if (splitindex > 0)
{ {
string temp = responseHeader.Substring(start, responseHeader.Length - start); string responseHeader = responseStr.Substring(0, splitindex);
string[] sArry = Regex.Split(temp, "\r\n"); string responseBody = responseStr.Substring(splitindex + 4);
args.Url = sArry[0].Remove(0, 10); if (responseHeader.StartsWith("HTTP/1.1 400"))
if (args.Url == "") {
return string.Empty; Status = 400;
return InternalSocketHttp(args); //注意302协议需要重定向 return string.Empty;
} }
} else if (responseHeader.StartsWith("HTTP/1.1 404"))
else if (responseHeader.StartsWith("HTTP/1.1 200")) //读取内容 {
{ Status = 404;
State = 200; return string.Empty;
DecompressWebPage(ref responseBytes, responseHeader); }
//转码 else if (responseHeader.StartsWith("HTTP/1.1 302") || responseHeader.StartsWith("HTTP/1.1 301"))
responseBody = DecodeWebStringByHttpHeader(responseBytes, responseHeader); {
responseBody = DecodeWebStringByHtmlPageInfo(responseBytes, responseBody); Status = 302;
} int start = responseHeader.ToUpper().IndexOf("LOCATION");
int splitindex = responseBody.IndexOf("\r\n\r\n"); if (start > 0)
if (splitindex > 0) {
responseBody = responseBody.Substring(splitindex + 4); string temp = responseHeader.Substring(start, responseHeader.Length - start);
else string[] sArry = Regex.Split(temp, "\r\n");
responseBody = string.Empty; args.Url = sArry[0].Remove(0, 10);
return responseBody; if (args.Url == "")
} return string.Empty;
return string.Empty; return InternalSocketHttp(); //注意302协议需要重定向
} }
#endregion }
else if (responseHeader.StartsWith("HTTP/1.1 200")) //读取内容
#region Helper {
Status = 200;
/// <summary> //解压
/// 解压网页 DecompressWebPage(ref responseBytes, responseHeader);
/// </summary> //转码
/// <param name="responseBytes">网页字节数组含http头</param> responseBody = DecodeWebStringByHttpHeader(responseBytes, responseHeader);
/// <param name="iTotalCount">数组长度</param> responseBody = DecodeWebStringByHtmlPageInfo(responseBytes, responseBody);
/// <param name="strHeader">Http头字符串</param> }
/// <param name="iStart">网页正文开始位置</param> splitindex = responseBody.IndexOf("\r\n\r\n");
private void DecompressWebPage(ref byte[] responseBytes, string strHeader) if (splitindex > 0)
{ responseBody = responseBody.Substring(splitindex + 4);
Regex regZip = new Regex(@"Content-Encoding:\s+gzip[^\n]*\r\n", RegexOptions.IgnoreCase); else
responseBody = string.Empty;
if (regZip.IsMatch(strHeader)) return responseBody;
{ }
responseBytes = Decompress(responseBytes); return string.Empty;
} }
} #endregion
/// <summary> #region Helper
/// 解压gzip网页
/// </summary> /// <summary>
/// <param name="szSource">压缩过的字符串字节数组</param> /// 解压网页
/// <returns>解压后的字节数组</returns> /// </summary>
private byte[] Decompress(byte[] szSource) /// <param name="responseBytes">网页字节数组含http头</param>
{ /// <param name="iTotalCount">数组长度</param>
MemoryStream msSource = new MemoryStream(szSource); /// <param name="strHeader">Http头字符串</param>
//DeflateStream 也可以这儿 /// <param name="iStart">网页正文开始位置</param>
GZipStream stream = new GZipStream(msSource, CompressionMode.Decompress); private void DecompressWebPage(ref byte[] responseBytes, string strHeader)
byte[] szTotal = new byte[40 * 1024]; {
long lTotal = 0; Regex regZip = new Regex(@"Content-Encoding:\s+gzip[^\n]*\r\n", RegexOptions.IgnoreCase);
byte[] buffer = new byte[8];
int iCount = 0; if (regZip.IsMatch(strHeader))
do {
{ responseBytes = Decompress(responseBytes);
iCount = stream.Read(buffer, 0, 8); }
if (szTotal.Length <= lTotal + iCount) //放大数组 }
{
byte[] temp = new byte[szTotal.Length * 10]; /// <summary>
szTotal.CopyTo(temp, 0); /// 解压gzip网页
szTotal = temp; /// </summary>
} /// <param name="szSource">压缩过的字符串字节数组</param>
buffer.CopyTo(szTotal, lTotal); /// <returns>解压后的字节数组</returns>
lTotal += iCount; private byte[] Decompress(byte[] szSource)
} while (iCount != 0); {
byte[] szDest = new byte[lTotal]; MemoryStream msSource = new MemoryStream(szSource);
Array.Copy(szTotal, 0, szDest, 0, lTotal); //DeflateStream 也可以这儿
return szDest; GZipStream stream = new GZipStream(msSource, CompressionMode.Decompress);
} byte[] szTotal = new byte[40 * 1024];
long lTotal = 0;
/// <summary> byte[] buffer = new byte[8];
/// 根据Http头标记里面的字符编码解析字符串 int iCount = 0;
/// </summary> do
/// <param name="responseBytes">网页内容字节数组(除http头以外的内容)</param> {
/// <param name="iTotalCount">网页内容字节数组长度</param> iCount = stream.Read(buffer, 0, 8);
/// <param name="strHeader">http头的字符串</param> if (szTotal.Length <= lTotal + iCount) //放大数组
/// <returns>转好的字符串</returns> {
private string DecodeWebStringByHttpHeader(byte[] responseBytes, string strHeader) byte[] temp = new byte[szTotal.Length * 10];
{ szTotal.CopyTo(temp, 0);
string strResponse = ""; szTotal = temp;
if (strHeader.Contains("charset=GBK") || strHeader.Contains("charset=gb2312")) }
{ buffer.CopyTo(szTotal, lTotal);
strResponse = Encoding.GetEncoding("GBK").GetString(responseBytes); lTotal += iCount;
} } while (iCount != 0);
else byte[] szDest = new byte[lTotal];
strResponse = Encoding.UTF8.GetString(responseBytes); Array.Copy(szTotal, 0, szDest, 0, lTotal);
return strResponse; return szDest;
} }
/// <summary> /// <summary>
/// 根据网页meta标记里面的字符编码解析字符串 /// 根据Http头标记里面的字符编码解析字符串
/// </summary> /// </summary>
/// <param name="responseBytes">网页内容字节数组(除http头以外的内容)</param> /// <param name="responseBytes">网页内容字节数组(除http头以外的内容)</param>
/// <param name="iTotalCount">网页内容字节数组长度</param> /// <param name="iTotalCount">网页内容字节数组长度</param>
/// <param name="strResponse">网页内容字符串, 可能已经根据其它转码要求转换过的字符串</param> /// <param name="strHeader">http头的字符串</param>
/// <returns>转好的字符串</returns> /// <returns>转好的字符串</returns>
private string DecodeWebStringByHtmlPageInfo(byte[] responseBytes, string strResponse) private string DecodeWebStringByHttpHeader(byte[] responseBytes, string strHeader)
{ {
Regex regGB2312 = new Regex(@"<meta[^>]+Content-Type[^>]+gb2312[^>]*>", RegexOptions.IgnoreCase); string strResponse = "";
Regex regGBK = new Regex(@"<meta[^>]+Content-Type[^>]+gbk[^>]*>", RegexOptions.IgnoreCase); if (strHeader.Contains("charset=GBK") || strHeader.Contains("charset=gb2312"))
Regex regBig5 = new Regex(@"<meta[^>]+Content-Type[^>]+Big5[^>]*>", RegexOptions.IgnoreCase); {
if (regGB2312.IsMatch(strResponse) || regGBK.IsMatch(strResponse)) strResponse = Encoding.GetEncoding("GBK").GetString(responseBytes);
strResponse = Encoding.GetEncoding("GBK").GetString(responseBytes); }
if (regBig5.IsMatch(strResponse)) else
strResponse = Encoding.GetEncoding("Big5").GetString(responseBytes); strResponse = Encoding.UTF8.GetString(responseBytes);
return strResponse; return strResponse;
} }
private byte[] ParseHttpArgs(HttpArgs args) /// <summary>
{ /// 根据网页meta标记里面的字符编码解析字符串
StringBuilder bulider = new StringBuilder(); /// </summary>
if (args.Method == HttpArgs.HttpMethod.POST) /// <param name="responseBytes">网页内容字节数组(除http头以外的内容)</param>
{ /// <param name="iTotalCount">网页内容字节数组长度</param>
bulider.AppendLine(string.Format("POST {0} HTTP/1.1", args.Url)); /// <param name="strResponse">网页内容字符串, 可能已经根据其它转码要求转换过的字符串</param>
bulider.AppendLine("Content-Type: application/x-www-form-urlencoded"); /// <returns>转好的字符串</returns>
} private string DecodeWebStringByHtmlPageInfo(byte[] responseBytes, string strResponse)
else {
{ Regex regGB2312 = new Regex(@"<meta[^>]+Content-Type[^>]+gb2312[^>]*>", RegexOptions.IgnoreCase);
bulider.AppendLine(string.Format("GET {0} HTTP/1.1", args.Url)); Regex regGBK = new Regex(@"<meta[^>]+Content-Type[^>]+gbk[^>]*>", RegexOptions.IgnoreCase);
} Regex regBig5 = new Regex(@"<meta[^>]+Content-Type[^>]+Big5[^>]*>", RegexOptions.IgnoreCase);
if (regGB2312.IsMatch(strResponse) || regGBK.IsMatch(strResponse))
bulider.AppendLine(string.Format("Host: {0}:{1}", args.Host, args.Port)); strResponse = Encoding.GetEncoding("GBK").GetString(responseBytes);
if (regBig5.IsMatch(strResponse))
bulider.AppendLine("User-Agent: " + args.UA); strResponse = Encoding.GetEncoding("Big5").GetString(responseBytes);
//"User-Agent: Mozilla/5.0+(Compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)";Mozilla/5.0 (Windows NT 6.1; IE 9.0) return strResponse;
if (!string.IsNullOrEmpty(args.Referer)) }
bulider.AppendLine(string.Format("Referer: {0}", args.Referer));
private byte[] ParseHttpArgs()
//bulider.AppendLine("Connection: close"); {
StringBuilder bulider = new StringBuilder();
bulider.AppendLine("Connection: Close"); if (args.Method == HttpMethod.POST)
{
if (!string.IsNullOrEmpty(args.Accept)) bulider.AppendLine(string.Format("POST {0} HTTP/1.1", args.Url));
bulider.AppendLine(string.Format("Accept: {0}", args.Accept)); bulider.AppendLine("Content-Type: application/x-www-form-urlencoded");
}
if (!string.IsNullOrEmpty(args.Cookie)) else
bulider.AppendLine(string.Format("Cookie: {0}", args.Cookie)); {
bulider.AppendLine(string.Format("GET {0} HTTP/1.1", args.Url));
if (args.Method == HttpArgs.HttpMethod.POST) }
{
bulider.AppendLine(string.Format("Content-Length: {0}\r\n", Encoding.Default.GetBytes(args.Data).Length)); bulider.AppendLine(string.Format("Host: {0}:{1}", args.Host, args.Port));
bulider.Append(args.Data);
} bulider.AppendLine("User-Agent: " + args.UA);
else //"User-Agent: Mozilla/5.0+(Compatible;+Baiduspider/2.0;++http://www.baidu.com/search/spider.html)";Mozilla/5.0 (Windows NT 6.1; IE 9.0)
{ if (!string.IsNullOrEmpty(args.Referer))
bulider.Append("\r\n"); bulider.AppendLine(string.Format("Referer: {0}", args.Referer));
}
//bulider.AppendLine("Connection: close");
string header = bulider.ToString();
return Encoding.Default.GetBytes(header); bulider.AppendLine("Connection: Close");
}
#endregion if (!string.IsNullOrEmpty(args.Accept))
bulider.AppendLine(string.Format("Accept: {0}", args.Accept));
}
if (!string.IsNullOrEmpty(args.Cookie))
public class MilliTimer bulider.AppendLine(string.Format("Cookie: {0}", args.Cookie));
{
private static double times { get; set; } if (args.Method == HttpMethod.POST)
public static void start() {
{ bulider.AppendLine(string.Format("Content-Length: {0}\r\n", Encoding.Default.GetBytes(args.Data).Length));
times = getTotalMilliseconds(); bulider.Append(args.Data);
} }
else
public static double getTimes() {
{ bulider.Append("\r\n");
return getTotalMilliseconds() - times; }
}
string header = bulider.ToString();
return Encoding.Default.GetBytes(header);
public static double getTotalMilliseconds() }
{ #endregion
return DateTime.Now.Subtract(DateTime.Parse("1970-1-1")).TotalMilliseconds;
} }
}
public class MilliTimer
{
private static double times { get; set; }
public static void start()
{
times = getTotalMilliseconds();
}
public static double getTimes()
{
return getTotalMilliseconds() - times;
}
public static double getTotalMilliseconds()
{
return DateTime.Now.Subtract(DateTime.Parse("1970-1-1")).TotalMilliseconds;
}
}
} }

View File

@ -1,12 +1,20 @@
<Window x:Class="CTZLauncher.MainWindow" <Window x:Class="CTZLauncher.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
ResizeMode = "NoResize" ResizeMode = "NoResize"
MouseMove="Window_MouseMove" 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> <Window.Resources>
<!-- s:Double表示了变量类型 x:key表示了变量名 -->
<s:Double x:Key="m_nFontSize">
32
</s:Double>
<!--
<ControlTemplate x:Key="CornerButton" TargetType="{x:Type Button}"> <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" /> <ContentPresenter Content="{TemplateBinding ContentControl.Content}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Border> </Border>
</ControlTemplate> </ControlTemplate>
@ -15,39 +23,50 @@
<ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center" Background="#FFA1A1A1"/> <ScrollViewer x:Name="PART_ContentHost" VerticalAlignment="Center" Background="#FFA1A1A1"/>
</Border> </Border>
</ControlTemplate> </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> </Window.Resources>
<Grid Name="outline" Background="#FF3A3A3A" Height="768" Width="1024" VerticalAlignment="Top" MouseLeftButtonDown="outline_MouseLeftButtonDown"> <Grid Name="outline" Background="#FF3299CC" Height="768" Width="1024" VerticalAlignment="Top" MouseLeftButtonDown="outline_MouseLeftButtonDown">
<Grid Margin="20,0" Background="#FF3A3A3A" Height="60" VerticalAlignment="Top"> <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="20" Background="{x:Null}" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontFamily="STXingkai" Foreground="White" MouseDown="barclick_MouseDown"/> <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="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="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="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="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="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="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="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="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="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="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="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="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="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="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"/> <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" /> <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>
<Grid Margin="20,60,20,20" Background="White"> <Grid Margin="20,60,20,20" Background="White">
<Grid Margin="0,0,0,300"> <Grid Margin="0,0,0,300">
<Grid Margin="30,20,0,20" HorizontalAlignment="Left" Width="550" > <Grid Margin="30,20,0,20" HorizontalAlignment="Left" Width="550" >
<Image Source="image/gg.jpg" />
<Border BorderBrush="Black" BorderThickness="2" CornerRadius="5"/> <Border BorderBrush="Black" BorderThickness="2" CornerRadius="5"/>
<Image Margin="0,0" Source="ico.ico" Height="200"/>
</Grid> </Grid>
<Grid Margin="0,20,30,20" HorizontalAlignment="Right" Width="350"> <Grid Margin="0,20,30,20" HorizontalAlignment="Right" Width="350">
<Border BorderBrush="Black" BorderThickness="2" CornerRadius="5"/> <Border BorderBrush="Black" BorderThickness="2" CornerRadius="5"/>
<Grid> <Grid>
<Grid Margin="30,20,30,0" Height="200" VerticalAlignment="Top"> <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" /> <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" /> <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>
<Grid Margin="30,20,30,30" Height="100" VerticalAlignment="Bottom"> <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="12,24,167,35" Template="{StaticResource CornerButton}" Width="111" HorizontalAlignment="Center" Content="登录" Click="Login_Click" Background="Green" />
<Button Margin="165,35,10,35" Template="{StaticResource CornerButton}" Width="111" HorizontalAlignment="Center" Content="注册" /> <Button Margin="167,24,12,35" Template="{StaticResource CornerButton}" Width="111" HorizontalAlignment="Center" Content="注册" Background="Green" />
</Grid> </Grid>
</Grid> </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"/> <ListBoxItem Content="新闻" Height="30" FontSize="25"/>
<ListBoxItem Content="新闻" Height="30" FontSize="25"/> <ListBoxItem Content="新闻" Height="30" FontSize="25"/>
</ListBox> </ListBox>
</TabItem> </TabItem>
<TabItem Header="公告" Background="White" BorderThickness="0" Margin="0" Height="30" FontSize="20" /> <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"> <Grid Margin="0,20,30,20" HorizontalAlignment="Right" Width="350" Grid.ShowGridLines="True">
<Border BorderBrush="Black" BorderThickness="2" CornerRadius="5"> <Border BorderBrush="Black" BorderThickness="2" CornerRadius="5">
</Border> </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"/> <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" /> <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"/> <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"/> <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"/>
<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"/>
</Grid> </Grid>
</Grid> </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> </Grid>
</Window> </Window>

View File

@ -1,140 +1,180 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using System.Windows.Data; using System.Windows.Data;
using System.Windows.Documents; using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
using System.Windows.Navigation; using System.Windows.Navigation;
using System.Windows.Shapes; using System.Windows.Shapes;
using KMCCC.Authentication; using KMCCC.Authentication;
using KMCCC.Launcher; using KMCCC.Launcher;
using KMCCC.Tools; using KMCCC.Tools;
using KMCCC.Modules; using KMCCC.Modules;
using KMCCC.Modules.JVersion; using KMCCC.Modules.JVersion;
using CityCraft; using CityCraft;
using System.IO; using System.IO;
using System.Windows.Threading;
namespace CTZLauncher
{ namespace CTZLauncher
/// <summary> {
/// MainWindow.xaml 的交互逻辑 /// <summary>
/// </summary> /// MainWindow.xaml 的交互逻辑
public partial class MainWindow : Window /// </summary>
{ public partial class MainWindow : Window
LauncherCore launcher = null; {
public MainWindow() LauncherCore launcher = null;
{ public MainWindow()
InitializeComponent(); {
} InitializeComponent();
}
private void Window_Initialized(object sender, EventArgs e)
{ private void Window_Initialized(object sender, EventArgs e)
if (Directory.Exists(".minecraft")) {
{ if (Directory.Exists(".minecraft"))
launcher = LauncherCore.Create(".minecraft"); {
launcher.GameLog += launcher_GameLog; launcher = LauncherCore.Create(".minecraft");
} launcher.GameLog += launcher_GameLog;
else }
{ else
MessageBox.Show("请将启动器放置于.minecraft同级目录..."); {
this.Close(); Directory.CreateDirectory(".minecraft");
} }
} }
private void Window_Loaded(object sender, RoutedEventArgs e) private void Window_Loaded(object sender, RoutedEventArgs e)
{ {
foreach (var item in SystemTools.FindJava()) foreach (var item in SystemTools.FindJava())
{ {
javacombo.Items.Add(item); javacombo.Items.Add(item);
} }
if (!javacombo.Items.IsEmpty) if (!javacombo.Items.IsEmpty)
javacombo.SelectedIndex = 0; javacombo.SelectedIndex = 0;
foreach (var item in launcher.GetVersions()) foreach (var item in launcher.GetVersions())
{ {
gamecombo.Items.Add(item.Id); gamecombo.Items.Add(item.Id);
} }
if (!gamecombo.Items.IsEmpty) if (!gamecombo.Items.IsEmpty)
gamecombo.SelectedIndex = 0; gamecombo.SelectedIndex = 0;
} maxmem.Text = "2048";
}
private void Window_MouseMove(object sender, MouseEventArgs e)
{ private void Window_MouseMove(object sender, MouseEventArgs e)
{
}
}
private void barclick_MouseDown(object sender, MouseButtonEventArgs e)
{ private void barclick_MouseDown(object sender, MouseButtonEventArgs e)
Label bar = (Label)sender; {
MessageBox.Show(bar.Name); Label bar = (Label)sender;
switch (bar.Name.Substring(4)) MessageBox.Show(bar.Name);
{ switch (bar.Name.Substring(4))
case "l1": {
break; case "l1":
case "l2": break;
break; case "l2":
case "l3": break;
break; case "l3":
case "l4": break;
break; case "l4":
case "r1": break;
break; case "r1":
case "r2": break;
break; case "r2":
case "r3": break;
break; case "r3":
case "r4": break;
break; case "r4":
} break;
} }
}
private void Button_Click(object sender, RoutedEventArgs e)
{ private void Button_Click(object sender, RoutedEventArgs e)
IAuthenticator auth = new YggdrasilLogin("jtb1@163.com", "jtb325325", false); {
AuthenticationInfo result = auth.Do(); IAuthenticator auth = new YggdrasilLogin("jtb1@163.com", "jtb325325", false);
MessageBox.Show(result.UUID.ToString()); AuthenticationInfo result = auth.Do();
} MessageBox.Show(result.UUID.ToString());
}
private void Login_Click(object sender, RoutedEventArgs e)
{ 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); HttpHelper http = new HttpHelper();
Console.WriteLine("服务器返回结果" + result); http.Send(HttpMethod.GET,"http://127.0.0.1:2000/isregistered?username=" + username.Text);
} while(http.readyState!=HttpReadyState.){
DoEvent();
private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) }
{ String result = http.responseBody;
if (e.LeftButton == MouseButtonState.Pressed) Console.WriteLine("服务器返回结果" + result);
this.DragMove(); }
}
private void StartGame_Click(object sender, RoutedEventArgs e) /// <summary>
{ /// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
Console.WriteLine("StartGame"); /// </summary>
LaunchOptions option = new LaunchOptions(); public void DoEvent()
option.Mode = LaunchMode.MCLauncher; {
option.MaxMemory = 2048; DispatcherFrame frame = new DispatcherFrame();
option.Authenticator = new OfflineAuthenticator(username.Text); // offline Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
option.Version = launcher.GetVersion(gamecombo.Text); Dispatcher.PushFrame(frame);
launcher.JavaPath = javacombo.Text; }
launcher.Launch(option); public object ExitFrame(object f)
} {
((DispatcherFrame)f).Continue = false;
void launcher_GameLog(LaunchHandle arg1, string arg2) return null;
{ }
Console.WriteLine(arg2);
} private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
this.DragMove();
}
private void StartGame_Click(object sender, RoutedEventArgs e)
{
} Console.WriteLine("StartGame");
} LaunchOptions option = new LaunchOptions();
option.Mode = LaunchMode.MCLauncher;
option.MaxMemory = int.Parse(maxmem.Text);
option.Authenticator = new OfflineAuthenticator(username.Text); // offline
option.Version = launcher.GetVersion(gamecombo.Text);
launcher.JavaPath = javacombo.Text;
launcher.Launch(option);
}
void launcher_GameLog(LaunchHandle arg1, string arg2)
{
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);
}
}
}
}
}