private static List <UpdateComponentInfo> LoadInfoFilePriv(byte[] pbData, IOConnectionInfo iocSource) { if ((pbData == null) || (pbData.Length == 0)) { return(null); } int iOffset = 0; StrEncodingInfo sei = StrUtil.GetEncoding(StrEncodingType.Utf8); byte[] pbBom = sei.StartSignature; if ((pbData.Length >= pbBom.Length) && MemUtil.ArraysEqual(pbBom, MemUtil.Mid(pbData, 0, pbBom.Length))) { iOffset += pbBom.Length; } string strData = sei.Encoding.GetString(pbData, iOffset, pbData.Length - iOffset); strData = StrUtil.NormalizeNewLines(strData, false); string[] vLines = strData.Split('\n'); string strSigKey; g_dFileSigKeys.TryGetValue(iocSource.Path.ToLowerInvariant(), out strSigKey); string strLdSig = null; StringBuilder sbToVerify = ((strSigKey != null) ? new StringBuilder() : null); List <UpdateComponentInfo> l = new List <UpdateComponentInfo>(); bool bHeader = true, bFooterFound = false; char chSep = ':'; // Modified by header for (int i = 0; i < vLines.Length; ++i) { string str = vLines[i].Trim(); if (str.Length == 0) { continue; } if (bHeader) { chSep = str[0]; bHeader = false; string[] vHdr = str.Split(chSep); if (vHdr.Length >= 2) { strLdSig = vHdr[1]; } } else if (str[0] == chSep) { bFooterFound = true; break; } else // Component info { if (sbToVerify != null) { sbToVerify.Append(str); sbToVerify.Append('\n'); } string[] vInfo = str.Split(chSep); if (vInfo.Length >= 2) { UpdateComponentInfo c = new UpdateComponentInfo( vInfo[0].Trim(), 0, iocSource.Path, string.Empty); c.VerAvailable = StrUtil.ParseVersion(vInfo[1]); AddComponent(l, c); } } } if (!bFooterFound) { Debug.Assert(false); return(null); } if (sbToVerify != null) { if (!VerifySignature(sbToVerify.ToString(), strLdSig, strSigKey)) { return(null); } } return(l); }
private Encoding GetSelEnc() { StrEncodingInfo sei = StrUtil.GetEncoding(m_cmbEnc.Text); return((sei != null) ? sei.Encoding : null); }
private void OnFormLoad(object sender, EventArgs e) { Debug.Assert(m_pbData != null); if (m_pbData == null) { throw new InvalidOperationException(); } GlobalWindowManager.AddWindow(this); this.Icon = AppIcons.Default; this.DoubleBuffered = true; m_strInitialFormRect = UIUtil.SetWindowScreenRectEx(this, Program.Config.UI.DataEditorRect); m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData); uint uStartOffset; StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding( m_pbData, out uStartOffset); string strData; try { strData = (seiGuess.Encoding.GetString(m_pbData, (int)uStartOffset, m_pbData.Length - (int)uStartOffset) ?? string.Empty); strData = StrUtil.ReplaceNulls(strData); } catch (Exception) { Debug.Assert(false); strData = string.Empty; } ++m_uBlockEvents; UIUtil.AssignShortcut(m_menuFileSave, Keys.Control | Keys.S); UIUtil.AssignShortcut(m_menuFileExit, Keys.Escape, null, true); UIUtil.AssignShortcut(m_menuEditUndo, Keys.Control | Keys.Z, null, true); UIUtil.AssignShortcut(m_menuEditRedo, Keys.Control | Keys.Y, null, true); UIUtil.AssignShortcut(m_menuEditCut, Keys.Control | Keys.X, null, true); UIUtil.AssignShortcut(m_menuEditCopy, Keys.Control | Keys.C, null, true); UIUtil.AssignShortcut(m_menuEditPaste, Keys.Control | Keys.V, null, true); UIUtil.AssignShortcut(m_menuEditDelete, Keys.Delete, null, true); UIUtil.AssignShortcut(m_menuEditSelectAll, Keys.Control | Keys.A, null, true); UIUtil.AssignShortcut(m_menuEditFind, Keys.Control | Keys.F); UIUtil.ConfigureTbButton(m_tbFileSave, KPRes.Save, null, m_menuFileSave); UIUtil.ConfigureTbButton(m_tbEditCut, KPRes.Cut, null, m_menuEditCut); UIUtil.ConfigureTbButton(m_tbEditCopy, KPRes.Copy, null, m_menuEditCopy); UIUtil.ConfigureTbButton(m_tbEditPaste, KPRes.Paste, null, m_menuEditPaste); UIUtil.ConfigureTbButton(m_tbEditUndo, KPRes.Undo, null, m_menuEditUndo); UIUtil.ConfigureTbButton(m_tbEditRedo, KPRes.Redo, null, m_menuEditRedo); UIUtil.ConfigureTbButton(m_tbFind, null, KPRes.Find, m_menuEditFind); // Formatting keyboard shortcuts are implemented by CustomRichTextBoxEx UIUtil.ConfigureTbButton(m_tbFormatBold, KPRes.Bold, KPRes.Bold + " (" + UIUtil.GetKeysName(Keys.Control | Keys.B) + ")", null); UIUtil.ConfigureTbButton(m_tbFormatItalic, KPRes.Italic, KPRes.Italic + " (" + UIUtil.GetKeysName(Keys.Control | Keys.I) + ")", null); UIUtil.ConfigureTbButton(m_tbFormatUnderline, KPRes.Underline, KPRes.Underline + " (" + UIUtil.GetKeysName(Keys.Control | Keys.U) + ")", null); UIUtil.ConfigureTbButton(m_tbFormatStrikeout, KPRes.Strikeout, null); UIUtil.ConfigureTbButton(m_tbColorForeground, KPRes.TextColor, null); UIUtil.ConfigureTbButton(m_tbColorBackground, KPRes.BackgroundColor, null); UIUtil.ConfigureTbButton(m_tbAlignLeft, KPRes.AlignLeft, KPRes.AlignLeft + " (" + UIUtil.GetKeysName(Keys.Control | Keys.L) + ")", null); UIUtil.ConfigureTbButton(m_tbAlignCenter, KPRes.AlignCenter, KPRes.AlignCenter + " (" + UIUtil.GetKeysName(Keys.Control | Keys.E) + ")", null); UIUtil.ConfigureTbButton(m_tbAlignRight, KPRes.AlignRight, KPRes.AlignRight + " (" + UIUtil.GetKeysName(Keys.Control | Keys.R) + ")", null); string strSearchTr = ((WinUtil.IsAtLeastWindowsVista ? string.Empty : " ") + KPRes.Search); UIUtil.SetCueBanner(m_tbFind, strSearchTr); UIUtil.EnableAutoCompletion(m_tbFontCombo, true); UIUtil.EnableAutoCompletion(m_tbFontSizeCombo, true); m_rtbText.Dock = DockStyle.Fill; m_ctxText.Attach(m_rtbText, this); m_tssStatusMain.Text = KPRes.Ready; m_rtbText.WordWrap = Program.Config.UI.DataEditorWordWrap; InitFormattingToolBar(); bool bSimpleText = true, bDefaultFont = true; if (m_bdc == BinaryDataClass.RichText) { try { if (strData.Length > 0) { m_rtbText.Rtf = StrUtil.RtfFix(strData); bDefaultFont = false; } else { m_rtbText.Text = string.Empty; } bSimpleText = false; } catch (Exception) { } // Show as simple text } if (bSimpleText) { m_rtbText.Text = strData; m_rtbText.SimpleTextOnly = true; // CR is upgraded to CR+LF m_bNewLinesWin = (StrUtil.GetNewLineSeq(strData) != "\n"); } else { m_menuViewFont.Text = KPRes.FontDefault + "..."; } if (bDefaultFont && Program.Config.UI.DataEditorFont.OverrideUIDefault) { m_rtbText.SelectAll(); m_rtbText.SelectionFont = Program.Config.UI.DataEditorFont.ToFont(); } m_rtbText.Select(0, 0); --m_uBlockEvents; UpdateUIState(false, true); }
private void OnFormLoad(object sender, EventArgs e) { Debug.Assert(m_pbData != null); if (m_pbData == null) { throw new InvalidOperationException(); } m_bInitializing = true; GlobalWindowManager.AddWindow(this); this.Icon = AppIcons.Default; this.DoubleBuffered = true; string strTitle = KPRes.DataViewerKP; if (m_strDataDesc.Length > 0) { strTitle = m_strDataDesc + " - " + strTitle; } this.Text = strTitle; m_strInitialFormRect = UIUtil.SetWindowScreenRectEx(this, Program.Config.UI.DataViewerRect); m_tssStatusMain.Text = KPRes.Ready; m_ctxText.Attach(m_rtbText, this); m_tslEncoding.Text = KPRes.Encoding + ":"; foreach (StrEncodingInfo seiEnum in StrUtil.Encodings) { m_tscEncoding.Items.Add(seiEnum.Name); } StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding( m_pbData, out m_uStartOffset); int iSel = 0; if (seiGuess != null) { iSel = Math.Max(m_tscEncoding.FindStringExact(seiGuess.Name), 0); } m_tscEncoding.SelectedIndex = iSel; m_tslZoom.Text = KPRes.Zoom + ":"; // Required for mouse wheel handling Debug.Assert(m_tscZoom.DropDownStyle == ComboBoxStyle.DropDownList); m_tscZoom.Items.Add(m_strZoomAuto); int[] vZooms = new int[] { 10, 25, 50, 75, 100, 125, 150, 200, 400 }; foreach (int iZoom in vZooms) { m_tscZoom.Items.Add(iZoom.ToString() + "%"); } m_tscZoom.SelectedIndex = 0; m_tsbZoomOut.ToolTipText = KPRes.Zoom + " - (" + UIUtil.GetKeysName( Keys.Control | Keys.Subtract) + ")"; m_tsbZoomIn.ToolTipText = KPRes.Zoom + " + (" + UIUtil.GetKeysName( Keys.Control | Keys.Add) + ")"; m_tslViewer.Text = KPRes.ShowIn + ":"; m_tscViewers.Items.Add(m_strViewerHex); m_tscViewers.Items.Add(m_strViewerText); m_tscViewers.Items.Add(m_strViewerImage); m_tscViewers.Items.Add(m_strViewerWeb); m_bdc = BinaryDataClassifier.Classify(m_strDataDesc, m_pbData); if ((m_bdc == BinaryDataClass.Text) || (m_bdc == BinaryDataClass.RichText)) { m_tscViewers.SelectedIndex = 1; } else if (m_bdc == BinaryDataClass.Image) { m_tscViewers.SelectedIndex = 2; } else if (m_bdc == BinaryDataClass.WebDocument) { m_tscViewers.SelectedIndex = 3; } else { m_tscViewers.SelectedIndex = 0; } if (this.DvfInit != null) { this.DvfInit(this, new DvfContextEventArgs(this, m_pbData, m_strDataDesc, m_tscViewers)); } m_picBox.MouseWheel += this.OnPicBoxMouseWheel; m_bInitializing = false; UpdateDataView(); }
private void OnFormLoad(object sender, EventArgs e) { if ((m_pbData == null) || (m_pwDatabase == null)) { throw new InvalidOperationException(); } m_bInitializing = true; GlobalWindowManager.AddWindow(this); // Callable from KPScript without parent form Debug.Assert(this.StartPosition == FormStartPosition.CenterScreen); this.Icon = AppIcons.Default; this.Text = KPRes.GenericCsvImporter + " - " + PwDefs.ShortProductName; // FontUtil.AssignDefaultBold(m_grpSyntax); // FontUtil.AssignDefaultBold(m_grpSem); UIUtil.SetExplorerTheme(m_lvFields, false); UIUtil.SetExplorerTheme(m_lvImportPreview, false); foreach (StrEncodingInfo seiEnum in StrUtil.Encodings) { m_cmbEnc.Items.Add(seiEnum.Name); } StrEncodingInfo seiGuess = BinaryDataClassifier.GetStringEncoding( m_pbData, out m_uStartOffset); int iSel = 0; if (seiGuess != null) { iSel = Math.Max(m_cmbEnc.FindStringExact(seiGuess.Name), 0); } m_cmbEnc.SelectedIndex = iSel; string[] vChars = new string[] { ",", ";", ".", ":", "\"", @"'", StrCharTab, StrCharNewLine }; foreach (string strChar in vChars) { m_cmbFieldSep.Items.Add(strChar); m_cmbRecSep.Items.Add(strChar); m_cmbTextQual.Items.Add(strChar); } m_cmbFieldSep.SelectedIndex = 0; m_cmbRecSep.SelectedIndex = 7; m_cmbTextQual.SelectedIndex = 4; m_lvFields.Columns.Add(KPRes.Field); AddCsvField(CsvFieldType.Title, null, null); AddCsvField(CsvFieldType.UserName, null, null); AddCsvField(CsvFieldType.Password, null, null); AddCsvField(CsvFieldType.Url, null, null); AddCsvField(CsvFieldType.Notes, null, null); for (int i = (int)CsvFieldType.First; i < (int)CsvFieldType.Count; ++i) { m_cmbFieldType.Items.Add(CsvFieldToString((CsvFieldType)i)); } m_cmbFieldType.SelectedIndex = (int)CsvFieldType.Group; m_cmbFieldFormat.Text = string.Empty; m_bInitializing = false; UpdateTextPreview(); UpdateImportPreview(); GuessCsvStructure(); ProcessResize(); EnableControlsEx(); UIUtil.SetFocus(m_btnTabNext, this); }