/// 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(); } }