Clean helper methods + move wine property to OS.

pull/32/head
Miepee 4 years ago
parent c3e60ee18c
commit f1cf1ce14f

@ -43,7 +43,7 @@ internal static class MainClass
#endif #endif
//Log Wine //Log Wine
if (Core.IsThisRunningFromWine) log.Info("Currently running from WINE!"); if (OS.IsThisRunningFromWine) log.Info("Currently running from WINE!");
// Try catch in case it ever crashes before actually getting to the Eto application // Try catch in case it ever crashes before actually getting to the Eto application
try try

@ -80,7 +80,7 @@ namespace AM2RLauncher
private static readonly bool isInternetThere = AM2RLauncherLib.Core.IsInternetThere; private static readonly bool isInternetThere = AM2RLauncherLib.Core.IsInternetThere;
private static readonly bool isThisRunningFromWine = AM2RLauncherLib.Core.IsThisRunningFromWine; private static readonly bool isThisRunningFromWine = AM2RLauncherLib.OS.IsThisRunningFromWine;
private static bool singleInstance; private static bool singleInstance;

@ -42,25 +42,6 @@ public static class Core
/// </summary> /// </summary>
public static readonly string ModsPath = CrossPlatformOperations.CurrentPath + "/Mods"; public static readonly string ModsPath = CrossPlatformOperations.CurrentPath + "/Mods";
/// <summary>
/// Checks if this is run via WINE.
/// </summary>
public static readonly bool IsThisRunningFromWine = CheckIfRunFromWINE();
/// <summary>
/// Checks if the Launcher is ran from WINE.
/// </summary>
/// <returns><see langword="true"/> if run from WINE, <see langword="false"/> if not.</returns>
private static bool CheckIfRunFromWINE()
{
// We check for wine by seeing if a reg entry exists.
// Not the best way, and could be removed from the future, but good enough for our purposes.
if (OS.IsWindows && (Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Wine") != null))
return true;
return false;
}
/// <summary> /// <summary>
/// This is used on Windows only. This sets a window to be in foreground, is used i.e. to fix am2r just being hidden. /// This is used on Windows only. This sets a window to be in foreground, is used i.e. to fix am2r just being hidden.
/// </summary> /// </summary>

@ -33,9 +33,7 @@ public static class HelperMethods
if (!dir.Exists) if (!dir.Exists)
{ {
throw new DirectoryNotFoundException( throw new DirectoryNotFoundException($"Source directory does not exist or could not be found: {sourceDirName}");
"Source directory does not exist or could not be found: "
+ sourceDirName);
} }
DirectoryInfo[] dirs = dir.GetDirectories(); DirectoryInfo[] dirs = dir.GetDirectories();
@ -96,6 +94,8 @@ public static class HelperMethods
/// </summary> /// </summary>
/// <param name="filename">Full Path to the file whose MD5 hash is supposed to be calculated.</param> /// <param name="filename">Full Path to the file whose MD5 hash is supposed to be calculated.</param>
/// <returns>The MD5 hash as a <see cref="string"/>, empty string if file does not exist.</returns> /// <returns>The MD5 hash as a <see cref="string"/>, empty string if file does not exist.</returns>
/*TODO: in the future we should use sha256, as both md5 and sha1 are unsafe.
This however needs to wait, until we somehow can find a way to publish the windows launcher as .net core...*/
public static string CalculateMD5(string filename) public static string CalculateMD5(string filename)
{ {
// Check if File exists first // Check if File exists first
@ -150,7 +150,7 @@ public static class HelperMethods
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://github.com"); HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://github.com");
try try
{ {
HttpWebResponse _ = (HttpWebResponse)request.GetResponse(); request.GetResponse();
} }
catch (WebException) catch (WebException)
{ {

@ -43,7 +43,26 @@ public static class OS
return "Linux"; return "Linux";
if (IsMac) if (IsMac)
return "Mac"; return "Mac";
return "Unknown OS"; return "Unknown OS";
} }
/// <summary>
/// Checks if this is run via WINE.
/// </summary>
public static readonly bool IsThisRunningFromWine = CheckIfRunFromWINE();
/// <summary>
/// Checks if the Launcher is ran from WINE.
/// </summary>
/// <returns><see langword="true"/> if run from WINE, <see langword="false"/> if not.</returns>
private static bool CheckIfRunFromWINE()
{
// We check for wine by seeing if a reg entry exists.
// Not the best way, and could be removed from the future, but good enough for our purposes.
if (IsWindows && (Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\Wine") != null))
return true;
return false;
}
} }

@ -666,7 +666,7 @@ public static class Profile
stream.WriteLine($"AM2RLauncher {Core.Version} log generated at {date}"); stream.WriteLine($"AM2RLauncher {Core.Version} log generated at {date}");
if (Core.IsThisRunningFromWine) if (OS.IsThisRunningFromWine)
stream.WriteLine("Using WINE!"); stream.WriteLine("Using WINE!");
stream.Flush(); stream.Flush();

Loading…
Cancel
Save