private void FillFormFromRegistry() { if (!stateLoaded) { if (AppCuKey != null) { // get the MRU list of .... whatever _completions = new System.Windows.Forms.AutoCompleteStringCollection(); string c = (string)AppCuKey.GetValue(_rvn_Completions, ""); if (!String.IsNullOrEmpty(c)) { string[] items = c.Split('¡'); if (items != null && items.Length > 0) { //_completions.AddRange(items); foreach (string item in items) { _completions.Add(item.XmlUnescapeIexcl()); } } } // Can also store/retrieve items in the registry for // - textbox contents // - checkbox state // - splitter state // - and so on // stateLoaded = true; } } }
private void SaveUserPrefs() { double leftColWidth = this.innerGrid.ColumnDefinitions[0].ActualWidth; AppCuKey.SetValue(_rvn_Geometry, String.Format("{0},{1},{2},{3},{4},{5}", this.Left, this.Top, this.Width, this.Height, leftColWidth, (int)this.WindowState)); int x = (Int32)AppCuKey.GetValue(_rvn_Runs, 0); x++; AppCuKey.SetValue(_rvn_Runs, x); var bt = this.listView1.SelectedItem as BrowserTab; if (bt != null) { AppCuKey.SetValue(_rvn_LastUrl, bt.LocationUrl); } StoreUrlHistory(); }
private void LoadUserPrefs() { string s = (string)AppCuKey.GetValue(_rvn_Geometry); if (!String.IsNullOrEmpty(s)) { double[] p = Array.ConvertAll <string, double>(s.Split(','), new Converter <string, double>((t) => { return(Double.Parse(t)); })); if (p != null && p.Length == 5) { Left = p[0]; Top = p[1]; Width = p[2]; Height = p[3]; WindowState = (System.Windows.WindowState)((int)p[4]); } else if (p != null && p.Length == 6) { Left = p[0]; Top = p[1]; Width = p[2]; Height = p[3]; var lcWidth = p[4]; WindowState = (System.Windows.WindowState)((int)p[5]); this.innerGrid.ColumnDefinitions[0].Width = new System.Windows.GridLength(lcWidth); } } LastUrlViewed = (string)AppCuKey.GetValue(_rvn_LastUrl); int x = (Int32)AppCuKey.GetValue(_rvn_ReloadIntervalInMs, 0); if ((x != 0) && (x > 1000) && (x < 180 * 1000)) { ReasonableInterval = new TimeSpan(x * 10000); } else { ReasonableInterval = new TimeSpan(2800 * 10000); // 3.2s AppCuKey.SetValue(_rvn_ReloadIntervalInMs, 2800); } }
private void SaveFormToRegistry() { if (AppCuKey == null) { return; } StoreFileHistory(); if (!String.IsNullOrEmpty(this.tbXpath.Text)) { AppCuKey.SetValue(_rvn_XPathExpression, this.tbXpath.Text); } if (!String.IsNullOrEmpty(this.tbPrefix.Text)) { AppCuKey.SetValue(_rvn_Prefix, this.tbPrefix.Text); } if (!String.IsNullOrEmpty(this.tbXmlns.Text)) { AppCuKey.SetValue(_rvn_Xmlns, this.tbXmlns.Text); } AppCuKey.SetValue(_rvn_LastRun, System.DateTime.Now.ToString("yyyy MMM dd HH:mm:ss")); int x = (Int32)AppCuKey.GetValue(_rvn_Runs, 0); x++; AppCuKey.SetValue(_rvn_Runs, x); // store the size of the form int w = 0, h = 0, left = 0, top = 0; if (this.Bounds.Width < this.MinimumSize.Width || this.Bounds.Height < this.MinimumSize.Height) { // RestoreBounds is the size of the window prior to last minimize action. // But the form may have been resized since then! w = this.RestoreBounds.Width; h = this.RestoreBounds.Height; left = this.RestoreBounds.Location.X; top = this.RestoreBounds.Location.Y; } else { w = this.Bounds.Width; h = this.Bounds.Height; left = this.Location.X; top = this.Location.Y; } AppCuKey.SetValue(_rvn_Geometry, String.Format("{0},{1},{2},{3},{4}", left, top, w, h, (int)this.WindowState)); // workitem 3392 // store the position of splitter // AppCuKey.SetValue(_rvn_Splitter, this.splitContainer3.SplitterDistance.ToString()); // the Xpath expression MRU list var converted = _xpathExpressionMruList.ToList().ConvertAll(z => z.XmlEscapeIexcl()); string history = String.Join("¡", converted.ToArray()); AppCuKey.SetValue(_rvn_History, history); }
private void FillFormFromRegistry() { if (!stateLoaded) { if (AppCuKey != null) { // fill the various textboxes SlurpFileHistory(); var s = (string)AppCuKey.GetValue(_rvn_XPathExpression); if (s != null) { this.tbXpath.Text = s; } s = (string)AppCuKey.GetValue(_rvn_Prefix); if (s != null) { this.tbPrefix.Text = s; } s = (string)AppCuKey.GetValue(_rvn_Xmlns); if (s != null) { this.tbXmlns.Text = s; } // get the MRU list of XPath expressions _xpathExpressionMruList = new System.Windows.Forms.AutoCompleteStringCollection(); string historyString = (string)AppCuKey.GetValue(_rvn_History, ""); if (!String.IsNullOrEmpty(historyString)) { string[] items = historyString.Split('¡'); if (items != null && items.Length > 0) { //_xpathExpressionMruList.AddRange(items); foreach (string item in items) { _xpathExpressionMruList.Add(item.XmlUnescapeIexcl()); } // insert the most recent expression into the box? this.tbXpath.Text = _xpathExpressionMruList[_xpathExpressionMruList.Count - 1]; } } // set the geometry of the form s = (string)AppCuKey.GetValue(_rvn_Geometry); if (!String.IsNullOrEmpty(s)) { int[] p = Array.ConvertAll <string, int>(s.Split(','), new Converter <string, int>((t) => { return(Int32.Parse(t)); })); if (p != null && p.Length == 5) { this.Bounds = ConstrainToScreen(new System.Drawing.Rectangle(p[0], p[1], p[2], p[3])); } } // workitem 3392 - don't need this // set the splitter // s = (string)AppCuKey.GetValue(_rvn_Splitter); // if (!String.IsNullOrEmpty(s)) // { // try // { // int x = Int32.Parse(s); // this.splitContainer3.SplitterDistance = x; // } // catch { } // } stateLoaded = true; } } }
private void LoadUrlHistory() { watchedUrlHistory = new MruDictionary <String, BrowserTab>(HISTORY_ENTRIES); var mruPath = _AppRegyPath + "\\URLs"; var dirPath = _AppRegyPath + "\\Dirs"; var mruKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(mruPath, true); var dirKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(dirPath, true); if (mruKey == null || dirKey == null) { return; } try { // Get the list of items for which we want reload. This // is a string of characters ABCD.... The presence of a // char indicates that we want reload for that // particular item in the URLs list. string reloads = (string)AppCuKey.GetValue(_rvn_WantReloads); // Restore the history, in reverse order, so the last one stored, // is treated as the most recent item. for (int i = HISTORY_ENTRIES; i >= 0; i--) { string c = new String((char)(i + 65), 1); // ascii char A,B,C (etc) string url = (string)mruKey.GetValue(c); // Is there a URL associated with that letter? if (!String.IsNullOrEmpty(url)) { string j = (string)dirKey.GetValue(c); // Is there a set of directories to watch associated // with that letter? if (!String.IsNullOrEmpty(j)) { var split = j.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); var slist = new System.Collections.Generic.List <String>(); slist.AddRange(split); var bt = new BrowserTab { PathsToMonitor = slist }; if (reloads != null && reloads.IndexOf(c) >= 0) { bt.WantReload = true; } watchedUrlHistory.Store(url, bt); } else { // There are no directories to watch. Therefore // remove the entries for this URL, because they // don't store any useful information. This happens // only during development of this code. mruKey.DeleteValue(c); dirKey.DeleteValue(c, false); } } else { // There's no URL for this letter. Clean out the dir // entry, just in case, for good registry hygiene. // This happens only during development of this code. dirKey.DeleteValue(c, false); } } } finally { dirKey.Close(); mruKey.Close(); } }
/// This app uses the windows registry to store config data for itself. /// - creates a key for this DotNetZip Winforms app, if one does not exist /// - stores and retrieves the most recent settings. /// - this is done on a per user basis. (HKEY_CURRENT_USER) private void FillFormFromRegistry() { if (!stateLoaded) { if (AppCuKey != null) { var s = (string)AppCuKey.GetValue(_rvn_DirectoryToZip); if (s != null) { this.tbDirectoryToZip.Text = s; this.tbDirectoryInArchive.Text = System.IO.Path.GetFileName(this.tbDirectoryToZip.Text); } s = (string)AppCuKey.GetValue(_rvn_SelectionToZip); if (s != null) { this.tbSelectionToZip.Text = s; } s = (string)AppCuKey.GetValue(_rvn_SelectionToExtract); if (s != null) { this.tbSelectionToExtract.Text = s; } s = (string)AppCuKey.GetValue(_rvn_ZipTarget); if (s != null) { this.tbZipToCreate.Text = s; } s = (string)AppCuKey.GetValue(_rvn_ZipToOpen); if (s != null) { this.tbZipToOpen.Text = s; } s = (string)AppCuKey.GetValue(_rvn_ExtractLoc); if (s != null) { this.tbExtractDir.Text = s; } else { this.tbExtractDir.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); } s = (string)AppCuKey.GetValue(_rvn_Encoding); if (s != null) { SelectNamedEncoding(s); } s = (string)AppCuKey.GetValue(_rvn_Compression); if (s != null) { SelectNamedCompressionLevel(s); } else { SelectNamedCompressionLevel("Default"); } s = (string)AppCuKey.GetValue(_rvn_Encryption); if (s != null) { SelectNamedEncryption(s); this.tbPassword.Text = ""; } int x = (Int32)AppCuKey.GetValue(_rvn_ZipFlavor, 0); if (x >= 0 && x <= 2) { this.comboFlavor.SelectedIndex = x; } x = (Int32)AppCuKey.GetValue(_rvn_Zip64Option, 0); if (x >= 0 && x <= 2) { this.comboZip64.SelectedIndex = x; } x = (Int32)AppCuKey.GetValue(_rvn_ExtractExistingFileAction, 0); if (x >= 0 && x <= comboExistingFileAction.Items.Count) { this.comboExistingFileAction.SelectedIndex = x; } x = (Int32)AppCuKey.GetValue(_rvn_FormTab, 1); if (x == 0 || x == 1) { this.tabControl1.SelectedIndex = x; } x = (Int32)AppCuKey.GetValue(_rvn_HidePassword, 1); this.chkHidePassword.Checked = (x != 0); x = (Int32)AppCuKey.GetValue(_rvn_OpenExplorer, 1); this.chkOpenExplorer.Checked = (x != 0); x = (Int32)AppCuKey.GetValue(_rvn_TraverseJunctions, 1); this.chkTraverseJunctions.Checked = (x != 0); x = (Int32)AppCuKey.GetValue(_rvn_RecurseDirs, 1); this.chkRecurse.Checked = (x != 0); x = (Int32)AppCuKey.GetValue(_rvn_RemoveFiles, 1); this.chkRemoveFiles.Checked = (x != 0); // get the MRU list of selection expressions _selectionCompletions = new System.Windows.Forms.AutoCompleteStringCollection(); string history = (string)AppCuKey.GetValue(_rvn_SelectionCompletions, ""); if (!String.IsNullOrEmpty(history)) { string[] items = history.Split('¡'); if (items != null && items.Length > 0) { foreach (string item in items) { _selectionCompletions.Add(item.XmlUnescapeIexcl()); } } } // set the geometry of the form s = (string)AppCuKey.GetValue(_rvn_Geometry); if (!String.IsNullOrEmpty(s)) { int[] p = Array.ConvertAll <string, int>(s.Split(','), new Converter <string, int>((t) => { return(Int32.Parse(t)); })); if (p != null && p.Length == 5) { this.Bounds = ConstrainToScreen(new System.Drawing.Rectangle(p[0], p[1], p[2], p[3])); // Starting a window minimized is confusing... //this.WindowState = (FormWindowState)p[4]; } } AppCuKey.Close(); AppCuKey = null; tbPassword_TextChanged(null, null); stateLoaded = true; } } }
private void SaveFormToRegistry() { if (this.tbExtractDir.InvokeRequired) { return; // skip it } if (AppCuKey != null) { AppCuKey.SetValue(_rvn_DirectoryToZip, this.tbDirectoryToZip.Text); AppCuKey.SetValue(_rvn_SelectionToZip, this.tbSelectionToZip.Text); AppCuKey.SetValue(_rvn_SelectionToExtract, this.tbSelectionToExtract.Text); AppCuKey.SetValue(_rvn_ZipTarget, this.tbZipToCreate.Text); AppCuKey.SetValue(_rvn_ZipToOpen, this.tbZipToOpen.Text); AppCuKey.SetValue(_rvn_Encoding, this.comboEncoding.SelectedItem.ToString()); AppCuKey.SetValue(_rvn_Compression, this.comboCompression.SelectedItem.ToString()); if (this.tbPassword.Text == "") { if (!String.IsNullOrEmpty(_mostRecentEncryption)) { AppCuKey.SetValue(_rvn_Encryption, _mostRecentEncryption); } } else { AppCuKey.SetValue(_rvn_Encryption, this.comboEncryption.SelectedItem.ToString()); } AppCuKey.SetValue(_rvn_ExtractLoc, this.tbExtractDir.Text); int x = this.comboFlavor.SelectedIndex; AppCuKey.SetValue(_rvn_ZipFlavor, x); x = this.comboZip64.SelectedIndex; AppCuKey.SetValue(_rvn_Zip64Option, x); x = this.comboExistingFileAction.SelectedIndex; AppCuKey.SetValue(_rvn_ExtractExistingFileAction, x); AppCuKey.SetValue(_rvn_FormTab, this.tabControl1.SelectedIndex); AppCuKey.SetValue(_rvn_LastRun, System.DateTime.Now.ToString("yyyy MMM dd HH:mm:ss")); x = (Int32)AppCuKey.GetValue(_rvn_Runs, 0); x++; AppCuKey.SetValue(_rvn_Runs, x); AppCuKey.SetValue(_rvn_HidePassword, this.chkHidePassword.Checked ? 1 : 0); AppCuKey.SetValue(_rvn_OpenExplorer, this.chkOpenExplorer.Checked ? 1 : 0); AppCuKey.SetValue(_rvn_TraverseJunctions, this.chkTraverseJunctions.Checked ? 1 : 0); AppCuKey.SetValue(_rvn_RecurseDirs, this.chkRecurse.Checked ? 1 : 0); AppCuKey.SetValue(_rvn_RemoveFiles, this.chkRemoveFiles.Checked ? 1 : 0); // the selection completion list var converted = _selectionCompletions.ToList().ConvertAll(z => z.XmlEscapeIexcl()); string history = String.Join("¡", converted.ToArray()); AppCuKey.SetValue(_rvn_SelectionCompletions, history); // store the size of the form int w = 0, h = 0, left = 0, top = 0; if (this.Bounds.Width < this.MinimumSize.Width || this.Bounds.Height < this.MinimumSize.Height) { // RestoreBounds is the size of the window prior to last minimize action. // But the form may have been resized since then! w = this.RestoreBounds.Width; h = this.RestoreBounds.Height; left = this.RestoreBounds.Location.X; top = this.RestoreBounds.Location.Y; } else { w = this.Bounds.Width; h = this.Bounds.Height; left = this.Location.X; top = this.Location.Y; } AppCuKey.SetValue(_rvn_Geometry, String.Format("{0},{1},{2},{3},{4}", left, top, w, h, (int)this.WindowState)); AppCuKey.Close(); } }