Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
DeckerCHAN committed Sep 21, 2015
2 parents 3ba5909 + 7a8c058 commit 1c224cb
Show file tree
Hide file tree
Showing 85 changed files with 2,654 additions and 473 deletions.
2 changes: 1 addition & 1 deletion Auth/AuthServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public LoginResultType Auth(String username)
this.CurrentPlayer = new PlayerEntity()
{
PlayerName = username,
PlayerId = Md5Utils.CalculateStringMd5(username),
PlayerId = EncodeUtils.CalculateStringMd5(username),
AccessToken = Guid.NewGuid().ToString("N"),
ClientToken = Guid.NewGuid().ToString("N"),
LoginType = LoginType.OfflineMode,
Expand Down
15 changes: 12 additions & 3 deletions Configs/Config.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;

namespace TerminologyLauncher.Configs
Expand All @@ -26,11 +27,19 @@ public String GetConfig(String key)
}
this.ReadConfigsFromFile();
var value = this.ConfigJObject.SelectToken(key).ToString();
if (String.IsNullOrEmpty(value))
return String.IsNullOrEmpty(value) ? null : value;
}

public List<String> GetConfigs(String key)
{
if (String.IsNullOrEmpty(key))
{
return null;
throw new ArgumentException("Empty key is not allowed!");
}
return value;
this.ReadConfigsFromFile();
var value = this.ConfigJObject.SelectToken(key).ToObject<List<String>>();

return value.Count == 0 ? new List<string>() : value;
}


Expand Down
5 changes: 2 additions & 3 deletions Configs/Configs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<UseVSHostingProcess>false</UseVSHostingProcess>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
Expand All @@ -47,7 +47,6 @@
<Compile Include="Config.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Configs/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" />
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
</packages>
13 changes: 11 additions & 2 deletions Core/Configs/CoreConfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"authConfig": "Configs/AuthConfig.json",
"authConfig": "Configs/AuthConfig.json",
"instanceManagerConfig": "Configs/InstanceManagerConfig.json",
"fileRepositoryConfig": "Configs/FileRepositoryConfig.json",
"updateManagerConfig": "Configs/UpdaterConifg.json"
"updateManagerConfig": "Configs/UpdaterConifg.json",
"javaSearchPaths": [
"C:\\Program Files\\Java\\",
"C:\\Program Files (x86)\\Java\\",
"D:\\Program Files\\Java\\",
"D:\\Program Files (x86)\\Java\\",
"Java\\"

],
"loginPerserveFilePath": "Login.bin"
}
14 changes: 9 additions & 5 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="log4net, Version=1.2.13.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL" />
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
Expand All @@ -53,15 +53,16 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Engine.cs" />
<Compile Include="Handlers\CloseHandler.cs" />
<Compile Include="Handlers\SystemHandlers\CloseHandler.cs" />
<Compile Include="Handlers\HandlerBase.cs" />
<Compile Include="Handlers\LoginHandlers\LoginHandler.cs" />
<Compile Include="Handlers\LoginHandlers\LoginWindowVisibilityChangedHandler.cs" />
<Compile Include="Handlers\MainHandlers\AddInstanceHandler.cs" />
<Compile Include="Handlers\MainHandlers\LaunchInstanceHandler.cs" />
<Compile Include="Handlers\MainHandlers\MainWindowVisibilityChangedHandler.cs" />
<Compile Include="Handlers\MainHandlers\RemoveInstanceHandler.cs" />
<Compile Include="Handlers\MainHandlers\UpdateApplicationHandler.cs" />
<Compile Include="Handlers\SystemHandlers\ConfigHandler.cs" />
<Compile Include="Handlers\SystemHandlers\UpdateApplicationHandler.cs" />
<Compile Include="Handlers\MainHandlers\UpdateInstanceHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down Expand Up @@ -108,6 +109,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</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.
Expand Down
9 changes: 6 additions & 3 deletions Core/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using TerminologyLauncher.Core.Handlers;
using TerminologyLauncher.Core.Handlers.LoginHandlers;
using TerminologyLauncher.Core.Handlers.MainHandlers;
using TerminologyLauncher.Core.Handlers.SystemHandlers;
using TerminologyLauncher.Entities.Account;
using TerminologyLauncher.Entities.FileRepository;
using TerminologyLauncher.FileRepositorySystem;
Expand All @@ -32,7 +33,7 @@ public static Engine GetEngine()

public String CoreVersion
{
get { return "A1"; }
get { return "A2"; }
}

public Config CoreConfig { get; set; }
Expand All @@ -45,7 +46,7 @@ public String CoreVersion
public Process GameProcess { get; set; }
public Engine()
{
Logger.GetLogger().Info("Engine Initializing...");
Logger.GetLogger().InfoFormat("Engine {0} Initializing...", this.CoreVersion);
this.CoreConfig = new Config(new FileInfo("Configs/CoreConfig.json"));
this.UiControl = new UiControl();
this.AuthServer = new AuthServer(this.CoreConfig.GetConfig("authConfig"));
Expand All @@ -66,6 +67,8 @@ public void Run()
public void Exit()
{
Logger.GetLogger().Info("Engine shutting down...");
Engine.GetEngine().UiControl.Shutdown();
Logger.GetLogger().Info("UiControl shutdown.");
}

public void RegisterHandlers()
Expand All @@ -81,7 +84,7 @@ public void RegisterHandlers()
this.Handlers.Add("LAUNCH_AN_INSTANCE", new LaunchInstanceHandler(this));
this.Handlers.Add("UPDATE_AN_INSTANCE", new UpdateInstanceHandler(this));
this.Handlers.Add("UPDATE_APPLICATION", new UpdateApplicationHandler(this));

this.Handlers.Add("CONFIG", new ConfigHandler(this));
}

public void PostInitializeComponents()
Expand Down
33 changes: 5 additions & 28 deletions Core/Handlers/LoginHandlers/LoginHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
using System.Threading.Tasks;
using TerminologyLauncher.Entities.Account;
using TerminologyLauncher.GUI;
using TerminologyLauncher.GUI.SingleLineInput;
using TerminologyLauncher.GUI.ToolkitWindows;
using TerminologyLauncher.GUI.ToolkitWindows.SingleLineInput;
using TerminologyLauncher.Logging;

namespace TerminologyLauncher.Core.Handlers.LoginHandlers
Expand All @@ -14,7 +15,7 @@ public class LoginHandlerBase : HandlerBase
public LoginHandlerBase(Engine engine)
: base(engine)
{
this.Engine.UiControl.LoginWindow.LoginButton.Click += this.HandleEvent;
this.Engine.UiControl.LoginWindow.Logining += this.HandleEvent;
}
public override void HandleEvent(Object sender, EventArgs e)
{
Expand Down Expand Up @@ -85,38 +86,14 @@ private void LoginSuccess()
this.Engine.UiControl.LoginWindow.LoginResult(LoginResultType.Success);
this.Engine.PostInitializeComponents();
this.Engine.UiControl.MajorWindow.Player = this.Engine.AuthServer.CurrentPlayer;
while (String.IsNullOrEmpty(this.Engine.InstanceManager.Config.GetConfig("javaPath")))
{
Logger.GetLogger().Warn("Java path is empty. Try to receive from user..");

var result = this.Engine.UiControl.StartSingleLineInput("Request Java path", "Java Path");
if (result.Type == SingleLineInputResultType.CommonFinished)
{
if (String.IsNullOrEmpty(result.InputLine) || !new FileInfo(result.InputLine).Exists || (new FileInfo(result.InputLine).Name.ToLower() != "java.exe"))
{
//try again.
}
else
{
this.Engine.InstanceManager.Config.SetConfig("javaPath", result.InputLine);
Logger.GetLogger().Info("Received java path from user. Pass.");
}
}
else if (result.Type == SingleLineInputResultType.Canceled)
{
Logger.GetLogger().Info("Handling close event.");
Engine.GetEngine().UiControl.Shutdown();
Logger.GetLogger().Info("UiControl shutdown.");
Engine.GetEngine().Exit();
return;
}
}
this.Engine.UiControl.ShowMainWindow();
}

private void LoginFault(LoginResultType reason)
{
this.Engine.UiControl.LoginWindow.LoginResult(reason);
}


}
}
53 changes: 46 additions & 7 deletions Core/Handlers/LoginHandlers/LoginWindowVisibilityChangedHandler.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,66 @@
using System;
using System.IO;
using System.Text;
using System.Windows;
using TerminologyLauncher.Entities.Account;
using TerminologyLauncher.Entities.SerializeUtils;
using TerminologyLauncher.GUI;
using TerminologyLauncher.Logging;
using TerminologyLauncher.Utils;

namespace TerminologyLauncher.Core.Handlers.LoginHandlers
{
public class LoginWindowVisibilityChangedHandler : HandlerBase
{

public LoginWindowVisibilityChangedHandler(Engine engine)
: base(engine)
{
this.Engine.UiControl.LoginWindow.IsVisibleChanged += this.HandleEvent;
}
public void HandleEvent(Object sender, DependencyPropertyChangedEventArgs e)
{
var window = sender as Window;
var window = sender as LoginWindow;
Logger.GetLogger().InfoFormat("Login window is going to {0}!", window.Visibility);
switch (window.Visibility)
{
case Visibility.Hidden:
{
if (window.IsPerservePassword)
{

var bin =
Encoding.ASCII.GetBytes(
EncodeUtils.Base64Encode(JsonConverter.ConvertToJson(window.GetLogin())));
File.WriteAllBytes(this.Engine.CoreConfig.GetConfig("loginPerserveFilePath"), bin);

}
else
{
if (File.Exists(this.Engine.CoreConfig.GetConfig("loginPerserveFilePath")))
{
File.Delete(this.Engine.CoreConfig.GetConfig("loginPerserveFilePath"));
}
}
break;
}
case Visibility.Visible:
{
if (File.Exists(this.Engine.CoreConfig.GetConfig("loginPerserveFilePath")))
{

var bin = File.ReadAllBytes(this.Engine.CoreConfig.GetConfig("loginPerserveFilePath"));
var login = JsonConverter.Parse<LoginEntity>(EncodeUtils.Base64Decode(Encoding.ASCII.GetString(bin)));
window.SetLogin(login);
}
break;
}
}
}

public override void HandleEvent(object sender, EventArgs e)
{
throw new NotSupportedException();
}

public LoginWindowVisibilityChangedHandler(Engine engine)
: base(engine)
{
this.Engine.UiControl.LoginWindow.IsVisibleChanged += this.HandleEvent;
}
}
}
35 changes: 14 additions & 21 deletions Core/Handlers/MainHandlers/AddInstanceHandler.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using TerminologyLauncher.Entities.InstanceManagement;
using TerminologyLauncher.Entities.SerializeUtils;
using TerminologyLauncher.GUI;
using TerminologyLauncher.GUI.SingleLineInput;
using TerminologyLauncher.GUI.ToolkitWindows;
using TerminologyLauncher.GUI.ToolkitWindows.SingleLineInput;
using TerminologyLauncher.Logging;

namespace TerminologyLauncher.Core.Handlers.MainHandlers
{
Expand All @@ -23,54 +20,50 @@ public AddInstanceHandler(Engine engine)

public override void HandleEvent(object sender, EventArgs e)
{
Logger.GetLogger().Info("Handling add instance event!");


var result = new SingleLineInputWindow("Input instance url", "URL:").ReceiveUserinput();
if (result.Type == SingleLineInputResultType.Canceled)
var result = new SingleLineInputWindow("Input instance url", "URL:").ReceiveUserInput();
if (result.Type == WindowResultType.Canceled)
{
Logging.Logger.GetLogger().Info("Empty input or user canceled. Ignore!");
Logger.GetLogger().Info("Empty input or user canceled. Ignore!");
return;
}
try
{
var message = this.Engine.InstanceManager.AddInstance(result.InputLine);
var message = this.Engine.InstanceManager.AddInstance(result.Result.ToString());
this.Engine.UiControl.MajorWindow.InstanceList =
new ObservableCollection<InstanceEntity>(this.Engine.InstanceManager.InstancesWithLocalImageSource);
this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Successful", message);
}
catch (WebException ex)
{
Logging.Logger.GetLogger()
Logger.GetLogger()
.ErrorFormat("Network is not accessable! Detail: {0}", ex.Message);
this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Error", String.Format("Network is not accessable! Detail: {0}", ex.Message));
}
catch (JsonReaderException ex)
{
Logging.Logger.GetLogger()
Logger.GetLogger()
.ErrorFormat("Wrong instance json format! {0}", ex.Message);
this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Error", String.Format("Wrong instance json format! {0}", ex.Message));
}
catch (MissingFieldException)
{
new PopupWindow(this.Engine.UiControl.MajorWindow, "Error",
"Some critical field is missing. Unable to add this instance.!").ShowDialog();


}

catch (Exception ex)
{
Logging.Logger.GetLogger()
.ErrorFormat("Can not add this instance because {0}", ex.Message);
Logger.GetLogger()
.ErrorFormat("Can not add this instance because {0}", ex);
this.Engine.UiControl.StartPopupWindow(this.Engine.UiControl.MajorWindow, "Can not launch", String.Format(
"Caused by an internal error, we can not launch this instance right now. Detail: {0}", ex.Message));
"Caused by an error, we can not add this instance right now. Detail: {0}", ex.Message));

}
finally
{
this.Engine.UiControl.MajorWindow.InstanceList =
new ObservableCollection<InstanceEntity>(this.Engine.InstanceManager.InstancesWithLocalImageSource);


}


Expand Down
Loading

0 comments on commit 1c224cb

Please sign in to comment.