public TemporaryFile(string group, string extension) { Group = group; Path = Engine.Instance.GetPathInData(RandomGenerator.GetHash() + ".tmp." + extension); TemporaryFiles.Add(this); }
public void Start() { m_command = new ElevatedProcess.Command(); if (Platform.Instance.NeedExecuteOutsideAppPath(ExePath)) { string tempPathToDelete = UtilsCore.GetTempPath() + "/openvpn-" + RandomGenerator.GetHash(); if (Platform.Instance.FileExists(tempPathToDelete)) { Platform.Instance.FileDelete(tempPathToDelete); } System.IO.File.Copy(ExePath, tempPathToDelete); ExePath = tempPathToDelete; DeleteAfterStart = true; } m_command.Parameters["command"] = "process_openvpn"; m_command.Parameters["path"] = ExePath; m_command.Parameters["airbuild"] = (AirBuild ? "y":"n"); m_command.Parameters["gui-version"] = Constants.Name + Constants.VersionDesc; m_command.Parameters["config"] = ConfigPath; m_command.ExceptionEvent += delegate(ElevatedProcess.Command cmd, string message) { StdErr.Write("Error: " + message); }; m_command.ReceiveEvent += delegate(ElevatedProcess.Command cmd, string data) { string feedbackType = data.Substring(0, 6); string feedbackData = data.Substring(7); if (feedbackType == "stdout") { StdOut.Write(feedbackData); } else if (feedbackType == "stderr") { StdErr.Write(feedbackData); } else if (feedbackType == "procid") { m_pid = Conversions.ToInt32(feedbackData); if (DeleteAfterStart) { Platform.Instance.FileDelete(ExePath); } } else if (feedbackType == "return") { } }; m_command.CompleteEvent += delegate(ElevatedProcess.Command cmd) { StdOut.Stop(); StdErr.Stop(); if (EndEvent != null) { EndEvent(); } }; m_command.DoASync(); }
// Rename AirVPN.xml (if exists) to Default.xml public static void FixOldProfilePath(string newPath) { if (Platform.Instance.FileExists(newPath)) { return; } if ((newPath.EndsWith("default.profile")) && (Platform.Instance.FileExists(newPath.Replace("default.profile", "AirVPN.xml")))) { Platform.Instance.FileMove(newPath.Replace("default.profile", "AirVPN.xml"), newPath.Replace("default.profile", "default.xml")); } if ((newPath.EndsWith("default.profile")) && (Platform.Instance.FileExists(newPath.Replace("default.profile", "default.xml")))) { byte[] content = Platform.Instance.FileContentsReadBytes(newPath.Replace("default.profile", "default.xml")); Platform.Instance.FileContentsWriteBytes(newPath, Storage.EncodeFormat("v2n", RandomGenerator.GetRandomId64(), content, Constants.PasswordIfEmpty)); Platform.Instance.FileDelete(newPath.Replace("default.profile", "default.xml")); } }