public static ProxyOptions FromStream(Stream stream) { using (var reader = new BinaryReader(stream, Encoding.UTF8, true)) { if (reader.ReadByte() != 0) { throw new IOException("Unexpected data"); } var options = new Launcher.ProcessOptions(); var po = new ProxyOptions(options); options.FileName = reader.ReadString(); options.Arguments = reader.ReadString(); options.WorkingDirectory = reader.ReadString(); options.UserName = reader.ReadString(); var variables = reader.ReadByte(); while (variables > 0) { options.Variables[reader.ReadString()] = reader.ReadString(); variables--; } return(po); } }
private static FileInfo GetLink(Settings.IAccount account, Launcher.ProcessOptions options) { var path = Path.Combine(DataPath.AppDataAccountData, "pl", account.UID.ToString()); string name; if ((name = _fileDescription) == null) { try { _fileDescription = name = FileVersionInfo.GetVersionInfo(options.FileName).FileDescription; if (string.IsNullOrWhiteSpace(name)) { throw new NotSupportedException(); } return(new FileInfo(Path.Combine(path, name + ".lnk"))); } catch { _fileDescription = name = "Guild Wars 2"; } } return(new FileInfo(Path.Combine(path, name + ".lnk"))); }
public ProxyOptions(Launcher.ProcessOptions options) { this.options = options; }
public static Process Launch(Settings.IAccount account, Launcher.ProcessOptions options) { var link = GetLink(account, options); try { var di = link.Directory; if (!di.Exists) { di.Create(); } } catch (Exception e) { Util.Logging.Log(e); } if (!link.Exists) { new Windows.Shortcut(options.FileName, "") { AppUserModelID = "Gw2Launcher." + account.UID, PreventPinning = true }.Save(link.FullName); } var po = new ProxyOptions(options); po.FileName = link.FullName; int pid; using (var p = Process.GetCurrentProcess()) pid = p.Id; var capacity = 512; MemoryMappedFile mf; using (var ms = new MemoryStream(capacity)) { po.CopyTo(ms); if (ms.Length > capacity) { capacity = (int)ms.Length; } mf = MemoryMappedFile.CreateNew(Messaging.MappedMessage.BASE_ID + "PL:" + pid, capacity); using (var stream = mf.CreateViewStream()) { ms.Position = 0; ms.CopyTo(stream); } } using (mf) { var startInfo = new ProcessStartInfo(Assembly.GetExecutingAssembly().Location, "-pl " + pid); startInfo.UseShellExecute = false; if (!string.IsNullOrEmpty(options.UserName)) { startInfo.UserName = options.UserName; startInfo.Password = options.Password; startInfo.LoadUserProfile = true; } using (var p = Process.Start(startInfo)) { p.WaitForExit(); using (var reader = new BinaryReader(mf.CreateViewStream(), Encoding.UTF8)) { var result = (LaunchResult)reader.ReadByte(); if (result == LaunchResult.Success) { pid = reader.ReadInt32(); try { return(Process.GetProcessById(pid)); } catch (Exception e) { Util.Logging.Log(e); return(null); } } else if (result == LaunchResult.Failed) { var msg = reader.ReadString(); throw new Exception(msg); } else if (result == LaunchResult.None) { throw new Exception("No response from launcher"); } else { throw new NotSupportedException(); } } } } }