Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeromusXYZ committed Apr 6, 2019
2 parents 43d5ae8 + 3565fbc commit f686af7
Show file tree
Hide file tree
Showing 12 changed files with 399 additions and 162 deletions.
1 change: 1 addition & 0 deletions AAEmu.Launcher/DebugHelperForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

116 changes: 112 additions & 4 deletions AAEmu.Launcher/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Text;
using System.Threading;
using System.Security.Cryptography;
using System.Diagnostics;
using Microsoft.Win32;

namespace AAEmu.Launcher
{
Expand Down Expand Up @@ -218,7 +220,7 @@ public void Init(string ArcheAgeExeLocation)
remotePatchSystemVersion = "0";
localVersion = "";
remoteVersion = "";
localGameFolder = Path.GetDirectoryName(Path.GetDirectoryName(ArcheAgeExeLocation)) + Path.DirectorySeparatorChar ;
localGameFolder = Path.GetDirectoryName(Path.GetDirectoryName(ArcheAgeExeLocation)) + Path.DirectorySeparatorChar;
localGame_Pak = localGameFolder + "game_pak";
localPatchDirectory = localGameFolder + ".patch" + Path.DirectorySeparatorChar;
localPakFileList = new List<PakFileInfo>();
Expand All @@ -234,7 +236,7 @@ public void Init(string ArcheAgeExeLocation)
public void RecalculateTotalDownloadSize()
{
Int64 c = 0;
for (int i = 0; i < remotePakFileList.Count;i++)
for (int i = 0; i < remotePakFileList.Count; i++)
{
c += remotePakFileList[i].fileSize;
}
Expand Down Expand Up @@ -277,7 +279,7 @@ public bool SetLocalVersionByString(string verStr)

public int GetDownloadProgressPercent()
{
long p = FileDownloadSizeDownloaded * 100 / FileDownloadSizeTotal ;
long p = FileDownloadSizeDownloaded * 100 / FileDownloadSizeTotal;
return (int)p;
}

Expand All @@ -297,7 +299,7 @@ public static string DateTimeToPAtchDateTimeStr(DateTime aTime)

public static long PatchDateTimeStrToFILETIME(string encodedString)
{
long res = 0 ;
long res = 0;

int yyyy = 0;
int mm = 0;
Expand Down Expand Up @@ -326,4 +328,110 @@ public static long PatchDateTimeStrToFILETIME(string encodedString)

}

public class FileAssociation
{
public string Extension { get; set; }
public string ProgId { get; set; }
public string FileTypeDescription { get; set; }
public string ExecutableFilePath { get; set; }
}


// source: https://stackoverflow.com/questions/2681878/associate-file-extension-with-application
public class FileAssociations
{
// needed so that Explorer windows get refreshed after the registry is updated
[System.Runtime.InteropServices.DllImport("Shell32.dll")]
private static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);

private const int SHCNE_ASSOCCHANGED = 0x8000000;
private const int SHCNF_FLUSH = 0x1000;

public static void EnsureAssociationsSet()
{
var filePath = Process.GetCurrentProcess().MainModule.FileName;
EnsureAssociationsSet(
new FileAssociation
{
Extension = ".aelcf",
ProgId = "AAEmu_Launcher_Config",
FileTypeDescription = "ArcheAge Emu Launcher Configuration File",
ExecutableFilePath = filePath
});
}

public static void EnsureURIAssociationsSet()
{
var filePath = Process.GetCurrentProcess().MainModule.FileName;
SetURIAssociation("aelcf", "AAEmu Launcher Protocol", filePath);
}

public static void EnsureAssociationsSet(params FileAssociation[] associations)
{
bool madeChanges = false;
foreach (var association in associations)
{
madeChanges |= SetAssociation(
association.Extension,
association.ProgId,
association.FileTypeDescription,
association.ExecutableFilePath);
}

if (madeChanges)
{
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_FLUSH, IntPtr.Zero, IntPtr.Zero);
}
}

public static bool SetAssociation(string extension, string progId, string fileTypeDescription, string applicationFilePath)
{
bool madeChanges = false;
madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + extension, progId);
madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + progId, fileTypeDescription);
madeChanges |= SetKeyDefaultValue($@"Software\Classes\{progId}\shell\open\command", "\"" + applicationFilePath + "\" \"%1\"");
return madeChanges;
}

private static bool SetKeyDefaultValue(string keyPath, string value)
{
using (var key = Registry.CurrentUser.CreateSubKey(keyPath))
{
if (key.GetValue(null) as string != value)
{
key.SetValue(null, value);
return true;
}
}

return false;
}

private static bool SetKeyValue(string keyPath, string keyName, string value)
{
using (var key = Registry.CurrentUser.CreateSubKey(keyPath))
{
if (key.GetValue(keyName) as string != value)
{
key.SetValue(keyName, value);
return true;
}
}

return false;
}

public static bool SetURIAssociation(string protocolID, string protocolName, string applicationFilePath)
{
bool madeChanges = false;
madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + protocolID, "URL:"+protocolName);
madeChanges |= SetKeyValue(@"Software\Classes\" + protocolID, "URL PRotocol", "");
madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + protocolID + @"\DefaultIcon", "\"" + applicationFilePath+",1\"");
madeChanges |= SetKeyDefaultValue(@"Software\Classes\" + protocolID + @"\shell\open\command", "\"" + applicationFilePath + "\" \"%1\"");
return madeChanges;
}


}

}
77 changes: 48 additions & 29 deletions AAEmu.Launcher/LauncherClass/BaseLauncher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,43 @@
using System.Security.Cryptography;
using System.Diagnostics;

namespace AAEmu.Launcher.LauncherBase
namespace AAEmu.Launcher.Basic
{
public partial class AAEmuLauncherBase
{
public string userName { get; set; }
public string gameExeFilePath { get; set; }
public string loginServerAdress { get; set; }
public UInt16 loginServerPort { get; set; }
public string locale { get; set; }
public string hShieldArgs { get; set; }
public string extraArguments { get; set; }
public string UserName { get; set; }
public string GameExeFilePath { get; set; }
public string LoginServerAdress { get; set; }
public UInt16 LoginServerPort { get; set; }
public string Locale { get; set; }
public string HShieldArgs { get; set; }
public string ExtraArguments { get; set; }
/// <summary>
/// launchArguments should be generated by InitializeForLaunch()
/// </summary>
public string launchArguments { get; set; }
public Process runningProcess { get; protected set; }
public string LaunchArguments { get; set; }
public Process RunningProcess { get; protected set; }
protected string _passwordHash { get; set; }
protected string launchVerb { get; set; }
protected string LaunchVerb { get; set; }

public AAEmuLauncherBase()
{
userName = "";
UserName = "";
_passwordHash = "";
gameExeFilePath = "C:\\ArcheAge\\Working\\Bin32\\ArcheAge.exe";
launchArguments = "";
extraArguments = "";
hShieldArgs = "";
launchVerb = "runas";
loginServerAdress = "127.0.0.1";
loginServerPort = 1237;
locale = "";
runningProcess = null;
GameExeFilePath = "C:\\ArcheAge\\Working\\Bin32\\ArcheAge.exe";
LaunchArguments = "";
ExtraArguments = "";
HShieldArgs = "";
LaunchVerb = "runas";
LoginServerAdress = "127.0.0.1";
LoginServerPort = 1237;
Locale = "";
RunningProcess = null;
}

/// <summary>
/// Cleanup code
/// </summary>
public virtual void Dispose()
{
// Dispose
Expand All @@ -66,38 +69,54 @@ public virtual bool SetPassword(string userPassword)
return true;
}

/// <summary>
/// Call this after you have set at minimum UserName, SetPassword, LoginServerAdress, GameExeFilePath and before calling Launch()
/// </summary>
/// <returns>Returns false if failed</returns>
public virtual bool InitializeForLaunch()
{
return true;
}


/// <summary>
/// Launches the game client using settings provided, most have called InitializeForLaunch() first
/// </summary>
/// <returns>Returns false it the game client process failed to be created</returns>
public virtual bool Launch()
{
System.Threading.Thread.Sleep(100);
ProcessStartInfo GameClientProcessInfo;
var fullArgs = launchArguments;
if (extraArguments != "")
fullArgs += " " + extraArguments;
if (hShieldArgs != "")
fullArgs += " " + hShieldArgs;
GameClientProcessInfo = new ProcessStartInfo(gameExeFilePath, fullArgs);
var fullArgs = LaunchArguments;
if (ExtraArguments != "")
fullArgs += " " + ExtraArguments;
if (HShieldArgs != "")
fullArgs += " " + HShieldArgs;
GameClientProcessInfo = new ProcessStartInfo(GameExeFilePath, fullArgs);
GameClientProcessInfo.UseShellExecute = true;
GameClientProcessInfo.Verb = launchVerb;
GameClientProcessInfo.Verb = LaunchVerb;
bool startOK = false;
try
{
runningProcess = Process.Start(GameClientProcessInfo);
RunningProcess = Process.Start(GameClientProcessInfo);
startOK = true;
}
catch
{
RunningProcess = null;
startOK = false;
}

return startOK;
}

/// <summary>
/// Call this after you started the game client with Launch()
/// </summary>
/// <returns></returns>
public virtual bool FinalizeLaunch()
{
RunningProcess = null;
return true;
}

Expand Down
4 changes: 2 additions & 2 deletions AAEmu.Launcher/LauncherClass/MailRu10Launcher.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using AAEmu.Launcher.LauncherBase;
using AAEmu.Launcher.Basic;

namespace AAEmu.Launcher.MailRu10
{
public class MailRu_1_0_Launcher: AAEmuLauncherBase
{
public override bool InitializeForLaunch()
{
launchArguments = "-r +auth_ip " + loginServerAdress + ":" + loginServerPort.ToString() + " -uid " + userName + " -token " + _passwordHash;
LaunchArguments = "-r +auth_ip " + LoginServerAdress + ":" + LoginServerPort.ToString() + " -uid " + UserName + " -token " + _passwordHash;
return true;
}
}
Expand Down
Loading

0 comments on commit f686af7

Please sign in to comment.