合并库文件到EXE...
parent
22dabdb0bd
commit
06cbb9c434
|
@ -1,10 +1,8 @@
|
||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2013
|
# Visual Studio 14
|
||||||
VisualStudioVersion = 12.0.21005.1
|
VisualStudioVersion = 14.0.23107.0
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KMCCC", "KMCCC.Shared\KMCCC.csproj", "{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}"
|
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CTZLauncher", "CTZLauncher\CTZLauncher.csproj", "{EC25362D-5BA7-4CB3-BDA2-C575B9318086}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CTZLauncher", "CTZLauncher\CTZLauncher.csproj", "{EC25362D-5BA7-4CB3-BDA2-C575B9318086}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
|
@ -13,10 +11,6 @@ Global
|
||||||
Release|Any CPU = Release|Any CPU
|
Release|Any CPU = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{52E292BB-FC7A-46E6-A8E8-B71E46FAF54E}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
{EC25362D-5BA7-4CB3-BDA2-C575B9318086}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
{EC25362D-5BA7-4CB3-BDA2-C575B9318086}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
{EC25362D-5BA7-4CB3-BDA2-C575B9318086}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{EC25362D-5BA7-4CB3-BDA2-C575B9318086}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{EC25362D-5BA7-4CB3-BDA2-C575B9318086}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{EC25362D-5BA7-4CB3-BDA2-C575B9318086}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
|
|
@ -1,70 +1,70 @@
|
||||||
namespace KMCCC.Authentication
|
namespace KMCCC.Authentication
|
||||||
{
|
{
|
||||||
#region
|
#region
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 离线验证器
|
/// 离线验证器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class OfflineAuthenticator : IAuthenticator
|
public class OfflineAuthenticator : IAuthenticator
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 玩家的名字
|
/// 玩家的名字
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public readonly string DisplayName;
|
public readonly string DisplayName;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 构造离线验证器
|
/// 构造离线验证器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="displayName">玩家的名字</param>
|
/// <param name="displayName">玩家的名字</param>
|
||||||
public OfflineAuthenticator(string displayName)
|
public OfflineAuthenticator(string displayName)
|
||||||
{
|
{
|
||||||
DisplayName = displayName;
|
DisplayName = displayName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 标注离线验证器
|
/// 标注离线验证器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Type
|
public string Type
|
||||||
{
|
{
|
||||||
get { return "KMCCC.Offline"; }
|
get { return "KMCCC.Offline"; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthenticationInfo Do()
|
public AuthenticationInfo Do()
|
||||||
{
|
{
|
||||||
if (String.IsNullOrWhiteSpace(DisplayName))
|
if (String.IsNullOrWhiteSpace(DisplayName))
|
||||||
{
|
{
|
||||||
return new AuthenticationInfo
|
return new AuthenticationInfo
|
||||||
{
|
{
|
||||||
Error = "DisplayName不符合规范"
|
Error = "DisplayName不符合规范"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
if (DisplayName.Count(char.IsWhiteSpace) > 0)
|
if (DisplayName.Count(char.IsWhiteSpace) > 0)
|
||||||
{
|
{
|
||||||
return new AuthenticationInfo
|
return new AuthenticationInfo
|
||||||
{
|
{
|
||||||
Error = "DisplayName不符合规范"
|
Error = "DisplayName不符合规范"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
return new AuthenticationInfo
|
return new AuthenticationInfo
|
||||||
{
|
{
|
||||||
AccessToken = null,
|
AccessToken = null,
|
||||||
DisplayName = DisplayName,
|
DisplayName = DisplayName,
|
||||||
UUID = null,
|
UUID = null,
|
||||||
Properties = "{}",
|
Properties = "{}",
|
||||||
UserType = "Mojang"
|
UserType = "Mojang"
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<AuthenticationInfo> DoAsync(CancellationToken token)
|
public Task<AuthenticationInfo> DoAsync(CancellationToken token)
|
||||||
{
|
{
|
||||||
return Task.Factory.StartNew((Func<AuthenticationInfo>)Do, token);
|
return Task.Factory.StartNew((Func<AuthenticationInfo>)Do, token);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -41,6 +41,7 @@
|
||||||
<StartupObject />
|
<StartupObject />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.VisualBasic" />
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Xaml" />
|
<Reference Include="System.Xaml" />
|
||||||
|
@ -57,6 +58,9 @@
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
|
<Compile Include="Tools\SystemTools.cs" />
|
||||||
|
<Compile Include="Tools\UsefulTools.cs" />
|
||||||
|
<Compile Include="Tools\ZipTools.cs" />
|
||||||
<Page Include="MainWindow.xaml">
|
<Page Include="MainWindow.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
@ -65,15 +69,40 @@
|
||||||
<DependentUpon>App.xaml</DependentUpon>
|
<DependentUpon>App.xaml</DependentUpon>
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Authentication\AuthenticationInfo.cs" />
|
||||||
|
<Compile Include="Authentication\IAuthenticator.cs" />
|
||||||
|
<Compile Include="Authentication\OfflineAuthenticator.cs" />
|
||||||
|
<Compile Include="Authentication\WarpedAuhenticator.cs" />
|
||||||
|
<Compile Include="Authentication\Yggdrasil.cs" />
|
||||||
<Compile Include="CTZAuth\CTZAuth.cs" />
|
<Compile Include="CTZAuth\CTZAuth.cs" />
|
||||||
<Compile Include="CTZAuth\ICTZAuth.cs" />
|
<Compile Include="CTZAuth\ICTZAuth.cs" />
|
||||||
<Compile Include="HttpHelper.cs" />
|
<Compile Include="HttpHelper.cs" />
|
||||||
|
<Compile Include="Launcher\LaunchArguments.cs" />
|
||||||
|
<Compile Include="Launcher\LauncherCore.cs" />
|
||||||
|
<Compile Include="Launcher\LauncherCoreInternal.cs" />
|
||||||
|
<Compile Include="Launcher\LaunchHandle.cs" />
|
||||||
|
<Compile Include="Launcher\LaunchHandleExtensions.cs" />
|
||||||
|
<Compile Include="Launcher\LaunchMode.cs" />
|
||||||
|
<Compile Include="Launcher\Version.cs" />
|
||||||
|
<Compile Include="LitJson\IJsonWrapper.cs" />
|
||||||
|
<Compile Include="LitJson\JsonData.cs" />
|
||||||
|
<Compile Include="LitJson\JsonException.cs" />
|
||||||
|
<Compile Include="LitJson\JsonMapper.cs" />
|
||||||
|
<Compile Include="LitJson\JsonMockWrapper.cs" />
|
||||||
|
<Compile Include="LitJson\JsonPropertyName.cs" />
|
||||||
|
<Compile Include="LitJson\JsonReader.cs" />
|
||||||
|
<Compile Include="LitJson\JsonWriter.cs" />
|
||||||
|
<Compile Include="LitJson\Lexer.cs" />
|
||||||
|
<Compile Include="LitJson\ParserToken.cs" />
|
||||||
<Compile Include="MainWindow.xaml.cs">
|
<Compile Include="MainWindow.xaml.cs">
|
||||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="Modules\JVersion\JVersion.cs" />
|
||||||
|
<Compile Include="Modules\JVersion\JVersionLocator.cs" />
|
||||||
|
<Compile Include="Modules\Yggdrasil\YggdrasilClient.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs">
|
<Compile Include="Properties\AssemblyInfo.cs">
|
||||||
<SubType>Code</SubType>
|
<SubType>Code</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
@ -101,12 +130,6 @@
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Resource Include="ico.ico" />
|
<Resource Include="ico.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\KMCCC.Shared\KMCCC.csproj">
|
|
||||||
<Project>{52e292bb-fc7a-46e6-a8e8-b71e46faf54e}</Project>
|
|
||||||
<Name>KMCCC</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Resource Include="IZ.ico" />
|
<Resource Include="IZ.ico" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
|
@ -1,217 +1,217 @@
|
||||||
namespace KMCCC.Launcher
|
namespace KMCCC.Launcher
|
||||||
{
|
{
|
||||||
#region
|
#region
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Tools;
|
using Tools;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
partial class LauncherCore
|
partial class LauncherCore
|
||||||
{
|
{
|
||||||
internal object Locker = new object();
|
internal object Locker = new object();
|
||||||
|
|
||||||
private LaunchResult GenerateArguments(LaunchOptions options, ref MinecraftLaunchArguments args)
|
private LaunchResult GenerateArguments(LaunchOptions options, ref MinecraftLaunchArguments args)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var authentication = options.Authenticator.Do();
|
var authentication = options.Authenticator.Do();
|
||||||
if (!string.IsNullOrWhiteSpace(authentication.Error))
|
if (!string.IsNullOrWhiteSpace(authentication.Error))
|
||||||
return new LaunchResult
|
return new LaunchResult
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
ErrorType = ErrorType.AuthenticationFailed,
|
ErrorType = ErrorType.AuthenticationFailed,
|
||||||
ErrorMessage = "验证错误: " + authentication.Error
|
ErrorMessage = "验证错误: " + authentication.Error
|
||||||
};
|
};
|
||||||
args.CGCEnabled = true;
|
args.CGCEnabled = true;
|
||||||
args.MainClass = options.Version.MainClass;
|
args.MainClass = options.Version.MainClass;
|
||||||
args.MaxMemory = options.MaxMemory;
|
args.MaxMemory = options.MaxMemory;
|
||||||
args.MinMemory = options.MinMemory;
|
args.MinMemory = options.MinMemory;
|
||||||
args.NativePath = GameRootPath + options.Version.Id + @"\\" + options.Version.Id + @"-natives";
|
args.NativePath = GameRootPath + options.Version.Id + @"\\" + options.Version.Id + @"-natives";
|
||||||
foreach (var native in options.Version.Natives)
|
foreach (var native in options.Version.Natives)
|
||||||
{
|
{
|
||||||
var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options);
|
var exp = ZipTools.UnzipFile(this.GetNativePath(native), args.NativePath, native.Options);
|
||||||
if (exp == null)
|
if (exp == null)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return new LaunchResult
|
return new LaunchResult
|
||||||
{
|
{
|
||||||
Success = false,
|
Success = false,
|
||||||
ErrorType = ErrorType.UncompressingFailed,
|
ErrorType = ErrorType.UncompressingFailed,
|
||||||
ErrorMessage = string.Format("解压错误: {0}:{1}:{2}", native.NS, native.Name, native.Version),
|
ErrorMessage = string.Format("解压错误: {0}:{1}:{2}", native.NS, native.Name, native.Version),
|
||||||
Exception = exp
|
Exception = exp
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
args.Server = options.Server;
|
args.Server = options.Server;
|
||||||
args.Size = options.Size;
|
args.Size = options.Size;
|
||||||
args.Libraries = options.Version.Libraries.Select(this.GetLibPath).ToList();
|
args.Libraries = options.Version.Libraries.Select(this.GetLibPath).ToList();
|
||||||
args.Libraries.Add(this.GetVersionJarPath(options.Version.JarId));
|
args.Libraries.Add(this.GetVersionJarPath(options.Version.JarId));
|
||||||
args.MinecraftArguments = options.Version.MinecraftArguments;
|
args.MinecraftArguments = options.Version.MinecraftArguments;
|
||||||
|
|
||||||
args.Tokens.Add("auth_access_token", authentication.AccessToken.GoString());
|
args.Tokens.Add("auth_access_token", authentication.AccessToken.GoString());
|
||||||
args.Tokens.Add("auth_session", authentication.AccessToken.GoString());
|
args.Tokens.Add("auth_session", authentication.AccessToken.GoString());
|
||||||
args.Tokens.Add("auth_player_name", authentication.DisplayName);
|
args.Tokens.Add("auth_player_name", authentication.DisplayName);
|
||||||
args.Tokens.Add("version_name", options.Version.Id);
|
args.Tokens.Add("version_name", options.Version.Id);
|
||||||
args.Tokens.Add("game_directory", ".");
|
args.Tokens.Add("game_directory", ".");
|
||||||
args.Tokens.Add("game_assets", "assets");
|
args.Tokens.Add("game_assets", "assets");
|
||||||
args.Tokens.Add("assets_root", "assets");
|
args.Tokens.Add("assets_root", "assets");
|
||||||
args.Tokens.Add("assets_index_name", options.Version.Assets);
|
args.Tokens.Add("assets_index_name", options.Version.Assets);
|
||||||
args.Tokens.Add("auth_uuid", authentication.UUID.GoString());
|
args.Tokens.Add("auth_uuid", authentication.UUID.GoString());
|
||||||
args.Tokens.Add("user_properties", authentication.Properties);
|
args.Tokens.Add("user_properties", authentication.Properties);
|
||||||
args.Tokens.Add("user_type", authentication.UserType);
|
args.Tokens.Add("user_type", authentication.UserType);
|
||||||
|
|
||||||
args.AdvencedArguments = new List<string> { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" };
|
args.AdvencedArguments = new List<string> { "-Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true" };
|
||||||
|
|
||||||
args.Authentication = authentication;
|
args.Authentication = authentication;
|
||||||
args.Version = options.Version;
|
args.Version = options.Version;
|
||||||
if (options.Mode != null)
|
if (options.Mode != null)
|
||||||
{
|
{
|
||||||
options.Mode.Operate(this, args);
|
options.Mode.Operate(this, args);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
catch (Exception exp)
|
catch (Exception exp)
|
||||||
{
|
{
|
||||||
Console.WriteLine(exp.Message);
|
Console.WriteLine(exp.Message);
|
||||||
Console.WriteLine(exp.Source);
|
Console.WriteLine(exp.Source);
|
||||||
Console.WriteLine(exp.StackTrace);
|
Console.WriteLine(exp.StackTrace);
|
||||||
return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "在生成参数时发生了意外的错误", Exception = exp };
|
return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "在生成参数时发生了意外的错误", Exception = exp };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal LaunchResult LaunchInternal(LaunchOptions options, params Action<MinecraftLaunchArguments>[] argumentsOperators)
|
internal LaunchResult LaunchInternal(LaunchOptions options, params Action<MinecraftLaunchArguments>[] argumentsOperators)
|
||||||
{
|
{
|
||||||
lock (Locker)
|
lock (Locker)
|
||||||
{
|
{
|
||||||
if (!File.Exists(JavaPath))
|
if (!File.Exists(JavaPath))
|
||||||
{
|
{
|
||||||
return new LaunchResult { Success = false, ErrorType = ErrorType.NoJAVA, ErrorMessage = "指定的JAVA位置不存在" };
|
return new LaunchResult { Success = false, ErrorType = ErrorType.NoJAVA, ErrorMessage = "指定的JAVA位置不存在" };
|
||||||
}
|
}
|
||||||
CurrentCode = Random.Next();
|
CurrentCode = Random.Next();
|
||||||
var args = new MinecraftLaunchArguments();
|
var args = new MinecraftLaunchArguments();
|
||||||
var result = GenerateArguments(options, ref args);
|
var result = GenerateArguments(options, ref args);
|
||||||
if (result != null)
|
if (result != null)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
if (argumentsOperators == null) return LaunchGame(args);
|
if (argumentsOperators == null) return LaunchGame(args);
|
||||||
foreach (var opt in argumentsOperators)
|
foreach (var opt in argumentsOperators)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (opt != null)
|
if (opt != null)
|
||||||
{
|
{
|
||||||
opt(args);
|
opt(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception exp)
|
catch (Exception exp)
|
||||||
{
|
{
|
||||||
return new LaunchResult { Success = false, ErrorType = ErrorType.OperatorException, ErrorMessage = "指定的操作器引发了异常", Exception = exp };
|
return new LaunchResult { Success = false, ErrorType = ErrorType.OperatorException, ErrorMessage = "指定的操作器引发了异常", Exception = exp };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return LaunchGame(args);
|
return LaunchGame(args);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private LaunchResult LaunchGame(MinecraftLaunchArguments args)
|
private LaunchResult LaunchGame(MinecraftLaunchArguments args)
|
||||||
{
|
{
|
||||||
Console.WriteLine(args.ToArguments());
|
Console.WriteLine(args.ToArguments());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var handle = new LaunchHandle(args.Authentication)
|
var handle = new LaunchHandle(args.Authentication)
|
||||||
{
|
{
|
||||||
Code = CurrentCode,
|
Code = CurrentCode,
|
||||||
Core = this,
|
Core = this,
|
||||||
Arguments = args,
|
Arguments = args,
|
||||||
Process = Process.Start(new ProcessStartInfo(JavaPath)
|
Process = Process.Start(new ProcessStartInfo(JavaPath)
|
||||||
{
|
{
|
||||||
Arguments = args.ToArguments(),
|
Arguments = args.ToArguments(),
|
||||||
UseShellExecute = false,
|
UseShellExecute = false,
|
||||||
WorkingDirectory = GameRootPath,
|
WorkingDirectory = GameRootPath,
|
||||||
RedirectStandardError = true,
|
RedirectStandardError = true,
|
||||||
RedirectStandardOutput = true
|
RedirectStandardOutput = true
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
handle.Work();
|
handle.Work();
|
||||||
Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
|
Task.Factory.StartNew(handle.Process.WaitForExit).ContinueWith(t => Exit(handle, handle.Process.ExitCode));
|
||||||
return new LaunchResult { Success = true, Handle = handle };
|
return new LaunchResult { Success = true, Handle = handle };
|
||||||
}
|
}
|
||||||
catch (Exception exp)
|
catch (Exception exp)
|
||||||
{
|
{
|
||||||
return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "启动时出现了异常", Exception = exp };
|
return new LaunchResult { Success = false, ErrorType = ErrorType.Unknown, ErrorMessage = "启动时出现了异常", Exception = exp };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region 复制文件夹
|
#region 复制文件夹
|
||||||
|
|
||||||
public void CopyVersionDirectory(string directoryName, string versionId)
|
public void CopyVersionDirectory(string directoryName, string versionId)
|
||||||
{
|
{
|
||||||
CopyDirectory(string.Format(@"{0}\versions\{2}\{1}", GameRootPath, directoryName, versionId),
|
CopyDirectory(string.Format(@"{0}\versions\{2}\{1}", GameRootPath, directoryName, versionId),
|
||||||
string.Format(@"{0}\{1}", GameRootPath, directoryName));
|
string.Format(@"{0}\{1}", GameRootPath, directoryName));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyDirectory(string source, string target)
|
public void CopyDirectory(string source, string target)
|
||||||
{
|
{
|
||||||
var code = CurrentCode;
|
var code = CurrentCode;
|
||||||
if (!Directory.Exists(source)) return;
|
if (!Directory.Exists(source)) return;
|
||||||
if (Directory.Exists(target))
|
if (Directory.Exists(target))
|
||||||
{
|
{
|
||||||
Directory.Delete(target, true);
|
Directory.Delete(target, true);
|
||||||
}
|
}
|
||||||
UsefulTools.Dircopy(source, target);
|
UsefulTools.Dircopy(source, target);
|
||||||
Action<LaunchHandle, int> handler = null;
|
Action<LaunchHandle, int> handler = null;
|
||||||
handler = (handle, c) =>
|
handler = (handle, c) =>
|
||||||
{
|
{
|
||||||
if (handle.Code == code)
|
if (handle.Code == code)
|
||||||
{
|
{
|
||||||
Directory.Delete(source, true);
|
Directory.Delete(source, true);
|
||||||
UsefulTools.Dircopy(target, source);
|
UsefulTools.Dircopy(target, source);
|
||||||
Directory.Delete(target, true);
|
Directory.Delete(target, true);
|
||||||
}
|
}
|
||||||
GameExit -= handler;
|
GameExit -= handler;
|
||||||
};
|
};
|
||||||
GameExit += handler;
|
GameExit += handler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CopyVersionDirectories(string ver)
|
public void CopyVersionDirectories(string ver)
|
||||||
{
|
{
|
||||||
var root = string.Format(@"{0}\versions\{1}\moddir", GameRootPath, ver);
|
var root = string.Format(@"{0}\versions\{1}\moddir", GameRootPath, ver);
|
||||||
if (!Directory.Exists(root))
|
if (!Directory.Exists(root))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
foreach (var dir in new DirectoryInfo(root).EnumerateDirectories())
|
foreach (var dir in new DirectoryInfo(root).EnumerateDirectories())
|
||||||
{
|
{
|
||||||
CopyDirectory(dir.FullName, string.Format(@"{0}\{1}", GameRootPath, dir.Name));
|
CopyDirectory(dir.FullName, string.Format(@"{0}\{1}", GameRootPath, dir.Name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 事件
|
#region 事件
|
||||||
|
|
||||||
internal void Log(LaunchHandle handle, string line)
|
internal void Log(LaunchHandle handle, string line)
|
||||||
{
|
{
|
||||||
if (GameLog != null)
|
if (GameLog != null)
|
||||||
{
|
{
|
||||||
GameLog(handle, line);
|
GameLog(handle, line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void Exit(LaunchHandle handle, int code)
|
internal void Exit(LaunchHandle handle, int code)
|
||||||
{
|
{
|
||||||
if (GameExit != null)
|
if (GameExit != null)
|
||||||
{
|
{
|
||||||
GameExit(handle, code);
|
GameExit(handle, code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,190 +1,190 @@
|
||||||
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;
|
using System.Windows.Threading;
|
||||||
|
|
||||||
namespace CTZLauncher
|
namespace CTZLauncher
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// MainWindow.xaml 的交互逻辑
|
/// MainWindow.xaml 的交互逻辑
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
LauncherCore launcher = null;
|
LauncherCore launcher = null;
|
||||||
public MainWindow()
|
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 = LauncherCore.Create(".minecraft");
|
||||||
launcher.GameLog += launcher_GameLog;
|
launcher.GameLog += launcher_GameLog;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(".minecraft");
|
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";
|
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;
|
Label bar = (Label)sender;
|
||||||
MessageBox.Show(bar.Name);
|
MessageBox.Show(bar.Name);
|
||||||
switch (bar.Name.Substring(4))
|
switch (bar.Name.Substring(4))
|
||||||
{
|
{
|
||||||
case "l1":
|
case "l1":
|
||||||
break;
|
break;
|
||||||
case "l2":
|
case "l2":
|
||||||
break;
|
break;
|
||||||
case "l3":
|
case "l3":
|
||||||
break;
|
break;
|
||||||
case "l4":
|
case "l4":
|
||||||
break;
|
break;
|
||||||
case "r1":
|
case "r1":
|
||||||
break;
|
break;
|
||||||
case "r2":
|
case "r2":
|
||||||
break;
|
break;
|
||||||
case "r3":
|
case "r3":
|
||||||
break;
|
break;
|
||||||
case "r4":
|
case "r4":
|
||||||
break;
|
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);
|
IAuthenticator auth = new YggdrasilLogin("jtb1@163.com", "jtb325325", false);
|
||||||
AuthenticationInfo result = auth.Do();
|
AuthenticationInfo result = auth.Do();
|
||||||
MessageBox.Show(result.UUID.ToString());
|
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();
|
HttpHelper http = new HttpHelper();
|
||||||
http.Send(HttpMethod.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.完成)
|
while (http.readyState != HttpReadyState.完成)
|
||||||
{
|
{
|
||||||
DoEvent();
|
DoEvent();
|
||||||
}
|
}
|
||||||
String result = http.responseBody;
|
String result = http.responseBody;
|
||||||
Console.WriteLine("服务器返回结果" + result);
|
Console.WriteLine("服务器返回结果" + result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
|
/// 模仿C#的Application.Doevent函数。可以适当添加try catch 模块
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void DoEvent()
|
public void DoEvent()
|
||||||
{
|
{
|
||||||
DispatcherFrame frame = new DispatcherFrame();
|
DispatcherFrame frame = new DispatcherFrame();
|
||||||
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
|
Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Background, new DispatcherOperationCallback(ExitFrame), frame);
|
||||||
Dispatcher.PushFrame(frame);
|
Dispatcher.PushFrame(frame);
|
||||||
}
|
}
|
||||||
public object ExitFrame(object f)
|
public object ExitFrame(object f)
|
||||||
{
|
{
|
||||||
((DispatcherFrame)f).Continue = false;
|
((DispatcherFrame)f).Continue = false;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
private void outline_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||||
{
|
{
|
||||||
if (e.LeftButton == MouseButtonState.Pressed)
|
if (e.LeftButton == MouseButtonState.Pressed)
|
||||||
this.DragMove();
|
this.DragMove();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void StartGame_Click(object sender, RoutedEventArgs e)
|
private void StartGame_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Console.WriteLine("StartGame");
|
Console.WriteLine("StartGame");
|
||||||
LaunchOptions option = new LaunchOptions();
|
LaunchOptions option = new LaunchOptions();
|
||||||
option.Mode = LaunchMode.MCLauncher;
|
option.Mode = LaunchMode.MCLauncher;
|
||||||
option.MaxMemory = int.Parse(maxmem.Text);
|
option.MaxMemory = int.Parse(maxmem.Text);
|
||||||
option.Authenticator = new OfflineAuthenticator(username.Text); // offline
|
option.Authenticator = new OfflineAuthenticator(username.Text); // offline
|
||||||
option.Version = launcher.GetVersion(gamecombo.Text);
|
option.Version = launcher.GetVersion(gamecombo.Text);
|
||||||
launcher.JavaPath = javacombo.Text;
|
launcher.JavaPath = javacombo.Text;
|
||||||
launcher.Launch(option);
|
launcher.Launch(option);
|
||||||
}
|
}
|
||||||
|
|
||||||
void launcher_GameLog(LaunchHandle arg1, string arg2)
|
void launcher_GameLog(LaunchHandle arg1, string arg2)
|
||||||
{
|
{
|
||||||
Console.WriteLine(arg2);
|
Console.WriteLine(arg2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void close_Click(object sender, RoutedEventArgs e)
|
private void close_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maxmem_TextChanged(object sender, TextChangedEventArgs e)
|
private void maxmem_TextChanged(object sender, TextChangedEventArgs e)
|
||||||
{
|
{
|
||||||
//屏蔽中文输入和非法字符粘贴输入
|
//屏蔽中文输入和非法字符粘贴输入
|
||||||
TextBox textBox = sender as TextBox;
|
TextBox textBox = sender as TextBox;
|
||||||
TextChange[] change = new TextChange[e.Changes.Count];
|
TextChange[] change = new TextChange[e.Changes.Count];
|
||||||
e.Changes.CopyTo(change, 0);
|
e.Changes.CopyTo(change, 0);
|
||||||
|
|
||||||
int offset = change[0].Offset;
|
int offset = change[0].Offset;
|
||||||
if (change[0].AddedLength > 0)
|
if (change[0].AddedLength > 0)
|
||||||
{
|
{
|
||||||
double num = 0;
|
double num = 0;
|
||||||
if (!Double.TryParse(textBox.Text, out num))
|
if (!Double.TryParse(textBox.Text, out num))
|
||||||
{
|
{
|
||||||
textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength);
|
textBox.Text = textBox.Text.Remove(offset, change[0].AddedLength);
|
||||||
textBox.Select(offset, 0);
|
textBox.Select(offset, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void register_Click(object sender, RoutedEventArgs e)
|
private void register_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
if (username.Text.Length == 0 || password.Text.Length == 0)
|
if (username.Text.Length == 0 || password.Text.Length == 0)
|
||||||
{
|
{
|
||||||
MessageBox.Show("请输入账号密码!");
|
MessageBox.Show("请输入账号密码!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue