private static void ParseCommandLine() { ArgumentParser argumentParser = new ArgumentParser(); argumentParser.AddSwitch("?", requiresValue: false); argumentParser.AddSwitch("h", requiresValue: false); argumentParser.AddSwitch("reset", requiresValue: false); argumentParser.AddSwitch("noopen", requiresValue: false); argumentParser.AddSwitch("noconnect", requiresValue: false); argumentParser.AddSwitch("reconnect", requiresValue: false); argumentParser.AddSwitch("c", requiresValue: true); try { argumentParser.Parse(); } catch (ArgumentException ex) { FormTools.ErrorDialog(ex.Message); Environment.Exit(1); } if (argumentParser.HasSwitch("?") || argumentParser.HasSwitch("h")) { Usage(); Environment.Exit(0); } if (argumentParser.HasSwitch("reset")) { ResetPreferences = true; } if (argumentParser.HasSwitch("noopen")) { _openFiles = false; } if (argumentParser.HasSwitch("noconnect")) { _reconnectServersAtStart = ReconnectServerOptions.None; } if (argumentParser.HasSwitch("reconnect")) { _reconnectServersAtStart = ReconnectServerOptions.All; } if (argumentParser.HasSwitch("c")) { _serversToConnect = argumentParser.SwitchValues["c"].Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries); } _filesToOpen.AddRange(argumentParser.PlainArgs); }
internal static void Main(params string[] args) { //防止工作目录不是文件所在目录 Environment.CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory; Application.EnableVisualStyles(); Policies.Read(); using (Helpers.Timer("解析命令行")) { ParseCommandLine(); } try { Current.Read(); } catch (Exception ex) { FormTools.ErrorDialog("读取RDCMan配置文件时出错:{0}程序可能不稳定或功能不完全。".InvariantFormat(ex.Message)); } using (CompositionContainer compositionContainer = new CompositionContainer(new AssemblyCatalog(Assembly.GetCallingAssembly()))) { _builtInVirtualGroups.AddRange(compositionContainer.GetExportedValues <IBuiltInVirtualGroup>()); _builtInVirtualGroups.Sort((IBuiltInVirtualGroup a, IBuiltInVirtualGroup b) => a.Text.CompareTo(b.Text)); } using (Helpers.Timer("读取个性设置")) { Preferences = Preferences.Load(); if (Preferences == null) { Environment.Exit(1); } } Thread thread2; using (Helpers.Timer("启动消息循环线程")) { InitializedEvent = new ManualResetEvent(initialState: false); Thread thread = new Thread(StartMessageLoop); thread.IsBackground = true; thread2 = thread; thread2.SetApartmentState(ApartmentState.STA); thread2.Start(); InitializedEvent.WaitOne(); } if (TheForm == null) { Environment.Exit(1); } TheForm.Invoke(new MethodInvoker(CompleteInitialization)); thread2.Join(); Log.Write("正在退出"); }
private unsafe static string EncryptStringUsingLocalUser(string plaintext) { Crypto.DataBlob optionalEntropy = default(Crypto.DataBlob); Crypto.CryptProtectPromptStruct promptStruct = default(Crypto.CryptProtectPromptStruct); if (string.IsNullOrEmpty(plaintext)) { return(null); } optionalEntropy.Size = 0; promptStruct.Size = 0; char[] array = plaintext.ToCharArray(); Crypto.DataBlob dataIn = default(Crypto.DataBlob); dataIn.Size = array.Length * 2; Crypto.DataBlob dataOut; fixed(char *value = array) { dataIn.Data = (IntPtr)(void *)value; if (!Crypto.CryptProtectData(ref dataIn, null, ref optionalEntropy, (IntPtr)null, ref promptStruct, 0, out dataOut)) { FormTools.ErrorDialog("无法加密密码"); return(null); } } byte *ptr = (byte *)(void *)dataOut.Data; byte[] array2 = new byte[dataOut.Size]; for (int i = 0; i < array2.Length; i++) { array2[i] = ptr[i]; } string result = Convert.ToBase64String(array2); Crypto.LocalFree(dataOut.Data); return(result); }
public static FileGroup OpenFile(string filename) { using (Helpers.Timer("reading {0}", filename)) { XmlDocument xmlDocument = new XmlDocument(); XmlTextReader xmlTextReader = null; XmlNode topNode; try { xmlTextReader = new XmlTextReader(filename); xmlTextReader.WhitespaceHandling = WhitespaceHandling.None; xmlTextReader.MoveToContent(); topNode = xmlDocument.ReadNode(xmlTextReader); } catch (Exception ex) { FormTools.ErrorDialog(ex.Message); return(null); } finally { xmlTextReader?.Close(); } if (topNode == null) { throw new FileLoadException(filename + ": File format error"); } FileGroup fileGroup = new FileGroup(filename); FileGroup fileGroup2 = (from f in ServerTree.Instance.Nodes.OfType <FileGroup>() where f.Pathname.Equals(fileGroup.Pathname, StringComparison.OrdinalIgnoreCase) select f).FirstOrDefault(); if (fileGroup2 == null) { try { List <string> errors = new List <string>(); ServerTree.Instance.Operation((OperationBehavior)31, delegate { ServerTree.Instance.AddNode(fileGroup, ServerTree.Instance.RootNode); if (!ReadXml(topNode, fileGroup, errors)) { throw new Exception(string.Empty); } }); if (errors.Count > 0) { StringBuilder stringBuilder = new StringBuilder("The following errors were encountered:").AppendLine().AppendLine(); foreach (string item in errors) { stringBuilder.AppendLine(item); } stringBuilder.AppendLine().Append("The file was not loaded completely. If it is saved it almost certainly means losing information. Continue?"); DialogResult dialogResult = FormTools.ExclamationDialog(stringBuilder.ToString(), MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) { throw new Exception(string.Empty); } } using (Helpers.Timer("sorting root, builtin groups and file")) { ServerTree.Instance.SortRoot(); foreach (GroupBase builtInVirtualGroup in Program.BuiltInVirtualGroups) { ServerTree.Instance.SortGroup(builtInVirtualGroup); ServerTree.Instance.OnGroupChanged(builtInVirtualGroup, ChangeType.TreeChanged); } ServerTree.Instance.SortGroup(fileGroup, recurse: true); ServerTree.Instance.OnGroupChanged(fileGroup, ChangeType.TreeChanged); } SmartGroup.RefreshAll(fileGroup); fileGroup.VisitNodes(delegate(RdcTreeNode node) { GroupBase groupBase = node as GroupBase; if (groupBase != null && groupBase.Properties.Expanded.Value) { groupBase.Expand(); } }); Encryption.DecryptPasswords(); fileGroup.CheckCredentials(); fileGroup.VisitNodes(delegate(RdcTreeNode n) { n.ResetInheritance(); }); fileGroup.HasChangedSinceWrite = false; Program.Preferences.NeedToSave = true; return(fileGroup); } catch (Exception ex2) { if (!string.IsNullOrEmpty(ex2.Message)) { FormTools.ErrorDialog(ex2.Message); } ServerTree.Instance.RemoveNode(fileGroup); return(null); } } FormTools.InformationDialog("{0} is already open as '{1}'".CultureFormat(fileGroup.Pathname, fileGroup2.Text)); return(fileGroup2); } }