2017-03-19 19:46:03 +00:00
|
|
|
|
using PSLauncher.Properties;
|
|
|
|
|
|
using System;
|
2016-06-19 20:02:10 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-06-19 20:49:51 +00:00
|
|
|
|
using System.Collections.Specialized;
|
2016-06-19 20:02:10 +00:00
|
|
|
|
using System.ComponentModel;
|
2016-06-19 20:49:51 +00:00
|
|
|
|
using System.IO;
|
2016-06-19 20:02:10 +00:00
|
|
|
|
using System.Linq;
|
2016-06-19 20:49:51 +00:00
|
|
|
|
using System.Runtime.InteropServices;
|
2016-06-19 20:02:10 +00:00
|
|
|
|
using System.Text;
|
2016-06-20 05:45:40 +00:00
|
|
|
|
using System.Windows.Forms;
|
2023-08-01 15:08:31 +00:00
|
|
|
|
using System.Security.Cryptography;
|
2016-06-19 20:02:10 +00:00
|
|
|
|
|
|
|
|
|
|
namespace PSLauncher
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class ISynchronizeInvokeExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static void SafeInvoke<T>(this T @this, Action<T> action) where T : ISynchronizeInvoke
|
|
|
|
|
|
{
|
|
|
|
|
|
if (@this.InvokeRequired)
|
|
|
|
|
|
{
|
|
|
|
|
|
@this.Invoke(action, new object[] { @this });
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
action(@this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2016-06-19 20:49:51 +00:00
|
|
|
|
|
|
|
|
|
|
public static class QueryExtensions
|
|
|
|
|
|
{
|
|
|
|
|
|
public static string ToQueryString(this NameValueCollection nvc)
|
|
|
|
|
|
{
|
|
|
|
|
|
IEnumerable<string> segments = from key in nvc.AllKeys
|
|
|
|
|
|
from value in nvc.GetValues(key)
|
|
|
|
|
|
select string.Format("{0}={1}", key, value);
|
|
|
|
|
|
return string.Join("&", segments);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static class Win32
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
public const int WM_SETREDRAW = 0x0b;
|
|
|
|
|
|
|
|
|
|
|
|
[DllImport("user32.dll")]
|
|
|
|
|
|
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
|
|
|
|
|
|
|
|
|
|
|
|
public static void SuspendPainting(IntPtr hWnd)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendMessage(hWnd, WM_SETREDRAW, (IntPtr)0, IntPtr.Zero);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void ResumePainting(IntPtr hWnd)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendMessage(hWnd, WM_SETREDRAW, (IntPtr)1, IntPtr.Zero);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static class Util
|
|
|
|
|
|
{
|
2017-03-19 19:46:03 +00:00
|
|
|
|
public static List<ServerEntry> LoadServerList()
|
|
|
|
|
|
{
|
|
|
|
|
|
List<ServerEntry> entries = new List<ServerEntry>();
|
|
|
|
|
|
StringCollection serverList = Settings.Default.ServerList;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (String entry in serverList)
|
|
|
|
|
|
{
|
|
|
|
|
|
String[] tokens = entry.Split(',');
|
|
|
|
|
|
|
|
|
|
|
|
if (tokens.Length != 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.WriteLine("LoadServerList: Failed to load server entry " + entry);
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ServerEntry newEntry = new ServerEntry();
|
|
|
|
|
|
newEntry.name = tokens[0];
|
|
|
|
|
|
newEntry.hostname = tokens[1];
|
|
|
|
|
|
newEntry.port = int.Parse(tokens[2]);
|
|
|
|
|
|
|
|
|
|
|
|
entries.Add(newEntry);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return entries;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-19 20:49:51 +00:00
|
|
|
|
public static string getDefaultPlanetSideDirectory()
|
|
|
|
|
|
{
|
2016-06-20 05:45:40 +00:00
|
|
|
|
// paths are in order of newest (most likely to have the right planetside) to oldest
|
2016-06-19 20:49:51 +00:00
|
|
|
|
Microsoft.Win32.RegistryKey key = null;
|
|
|
|
|
|
string psFolder = "";
|
2016-06-20 05:45:40 +00:00
|
|
|
|
List<string> pathsToCheck = new List<String>();
|
2016-06-19 20:49:51 +00:00
|
|
|
|
|
|
|
|
|
|
// non-steam install
|
2016-06-20 05:45:40 +00:00
|
|
|
|
// Known to be: C:\Users\Public\Daybreak Game Company\Installed Games\PlanetSide 2 Test\LaunchPad.exe
|
2016-06-19 20:49:51 +00:00
|
|
|
|
key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\App Paths\LaunchPad.exe");
|
|
|
|
|
|
|
|
|
|
|
|
if (key != null && key.GetValue("") != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
String defaultDirectory;
|
|
|
|
|
|
defaultDirectory = key.GetValue("").ToString();
|
2016-06-20 05:45:40 +00:00
|
|
|
|
|
2017-03-19 19:46:03 +00:00
|
|
|
|
Console.WriteLine("PSDiscover: LaunchPad.exe key found {0}", defaultDirectory);
|
2016-06-20 05:45:40 +00:00
|
|
|
|
|
2016-06-19 20:49:51 +00:00
|
|
|
|
defaultDirectory = Path.GetDirectoryName(defaultDirectory);
|
|
|
|
|
|
|
|
|
|
|
|
// verify that we aren't mistakingly returning a PlanetSide 2 directory...
|
2016-06-20 05:45:40 +00:00
|
|
|
|
pathsToCheck.Add(defaultDirectory);
|
|
|
|
|
|
|
2016-06-19 20:49:51 +00:00
|
|
|
|
// try to go up a directory and find the PlanetSide folder
|
|
|
|
|
|
string upOne = Directory.GetParent(defaultDirectory).FullName;
|
|
|
|
|
|
psFolder = Path.Combine(upOne, "Planetside");
|
|
|
|
|
|
|
2016-06-20 05:45:40 +00:00
|
|
|
|
pathsToCheck.Add(psFolder);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-03-19 19:46:03 +00:00
|
|
|
|
Console.WriteLine("PSDiscover: No LaunchPad.exe key found");
|
2016-06-19 20:49:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-20 05:45:40 +00:00
|
|
|
|
// HACK: Should work on Win7 and above
|
|
|
|
|
|
psFolder = "C:\\Users\\Public\\Daybreak Game Company\\Installed Games\\Planetside";
|
|
|
|
|
|
pathsToCheck.Add(psFolder);
|
|
|
|
|
|
|
|
|
|
|
|
// HACK 2: our last attempt
|
|
|
|
|
|
psFolder = "C:\\Users\\Public\\Sony Online Entertainment\\Installed Games\\Planetside";
|
|
|
|
|
|
pathsToCheck.Add(psFolder);
|
|
|
|
|
|
|
|
|
|
|
|
// worth a shot! (for windows XP or old installs)
|
2016-06-19 20:49:51 +00:00
|
|
|
|
psFolder = Path.Combine(ProgramFilesx86(), "Sony\\PlanetSide");
|
2016-06-20 05:45:40 +00:00
|
|
|
|
pathsToCheck.Add(psFolder);
|
2016-06-19 20:49:51 +00:00
|
|
|
|
|
2016-06-20 05:45:40 +00:00
|
|
|
|
int i = 1;
|
|
|
|
|
|
foreach(var path in pathsToCheck)
|
|
|
|
|
|
{
|
2017-03-19 19:46:03 +00:00
|
|
|
|
Console.WriteLine("PSDiscover: M{0} - {1}", i, path);
|
2016-06-19 20:49:51 +00:00
|
|
|
|
|
2016-06-20 05:45:40 +00:00
|
|
|
|
if (Directory.Exists(path) && checkDirForPlanetSide(path))
|
|
|
|
|
|
{
|
2017-03-19 19:46:03 +00:00
|
|
|
|
Console.WriteLine("PSDiscover: Path found using M{0}", i);
|
2016-06-20 05:45:40 +00:00
|
|
|
|
return path;
|
|
|
|
|
|
}
|
2016-06-19 20:49:51 +00:00
|
|
|
|
|
2016-06-20 05:45:40 +00:00
|
|
|
|
i += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-03-19 19:46:03 +00:00
|
|
|
|
Console.WriteLine("PSDiscover: No default planetside.exe path found!");
|
2016-06-19 20:49:51 +00:00
|
|
|
|
|
2016-06-20 05:45:40 +00:00
|
|
|
|
// give up :'(
|
2016-06-19 20:49:51 +00:00
|
|
|
|
return "";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool checkDirForPlanetSide(string dir)
|
|
|
|
|
|
{
|
|
|
|
|
|
return File.Exists(Path.Combine(dir, SettingsForm.PS_EXE_NAME));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string ProgramFilesx86()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (8 == IntPtr.Size
|
|
|
|
|
|
|| (!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432"))))
|
|
|
|
|
|
{
|
|
|
|
|
|
return Environment.GetEnvironmentVariable("ProgramFiles(x86)");
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Environment.GetEnvironmentVariable("ProgramFiles");
|
|
|
|
|
|
}
|
2016-06-20 05:45:40 +00:00
|
|
|
|
|
2023-08-01 15:08:31 +00:00
|
|
|
|
public static string CalculateFileHash(string _filePath)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var hashingAlgorithm = HashAlgorithm.Create(Program.hashingAlgoType.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var fileHandle = File.OpenRead(_filePath))
|
|
|
|
|
|
{
|
|
|
|
|
|
return CalculateFileHash(hashingAlgorithm, fileHandle);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string CalculateFileHash(FileStream _fileHandle)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var hashingAlgorithm = HashAlgorithm.Create(Program.hashingAlgoType.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
return CalculateFileHash(hashingAlgorithm, _fileHandle);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static string CalculateFileHash(HashAlgorithm _hashingAlgorithm, FileStream _fileHandle)
|
|
|
|
|
|
{
|
|
|
|
|
|
const int bufferSize = 1 * 1000 * 1000; // 1MB
|
|
|
|
|
|
|
|
|
|
|
|
// read file in bigger buffer to improve hashing performance (slightly)
|
|
|
|
|
|
using (var stream2 = new BufferedStream(_fileHandle, bufferSize))
|
|
|
|
|
|
{
|
|
|
|
|
|
return BitConverter.ToString(_hashingAlgorithm.ComputeHash(stream2)).Replace("-", "").ToLower();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string CalculateStringHash(string _string)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var hashingAlgorithm = HashAlgorithm.Create(Program.hashingAlgoType.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
return CalculateStringHash(hashingAlgorithm, _string);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string CalculateStringHash(EHashingAlgoType _algoType, string _string)
|
|
|
|
|
|
{
|
|
|
|
|
|
using (var hashingAlgorithm = HashAlgorithm.Create(_algoType.ToString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
return CalculateStringHash(hashingAlgorithm, _string);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static string CalculateStringHash(HashAlgorithm _hashAlgorithm, string _string)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] stringBytes = System.Text.Encoding.ASCII.GetBytes(_string);
|
|
|
|
|
|
return BitConverter.ToString(_hashAlgorithm.ComputeHash(stringBytes)).Replace("-", "").ToLower();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-06-20 05:45:40 +00:00
|
|
|
|
// from https://stackoverflow.com/questions/18726852/redirecting-console-writeline-to-textbox
|
|
|
|
|
|
public class ControlWriter : TextWriter
|
|
|
|
|
|
{
|
|
|
|
|
|
private Control textbox;
|
|
|
|
|
|
public ControlWriter(Control textbox)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.textbox = textbox;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Write(char value)
|
|
|
|
|
|
{
|
|
|
|
|
|
textbox.Text += value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void Write(string value)
|
|
|
|
|
|
{
|
|
|
|
|
|
textbox.Text += value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Encoding Encoding
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Encoding.ASCII; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-08-01 15:08:31 +00:00
|
|
|
|
|
|
|
|
|
|
// https://stackoverflow.com/a/250400
|
|
|
|
|
|
public static DateTime UnixTimestampToDateTime( double unixTimestmap )
|
|
|
|
|
|
{
|
|
|
|
|
|
// Unix timestamp is seconds past epoch
|
|
|
|
|
|
DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
|
|
dateTime = dateTime.AddSeconds(unixTimestmap).ToLocalTime();
|
|
|
|
|
|
|
|
|
|
|
|
return dateTime;
|
|
|
|
|
|
}
|
2016-06-19 20:49:51 +00:00
|
|
|
|
}
|
2016-06-19 20:02:10 +00:00
|
|
|
|
}
|