private void btnImport_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialogEx("Import styles settings", "Text file(*.txt)|*.txt")) { if (ofd.ShowDialog() != DialogResult.OK) { return; } using (var reader = new StreamReader(ofd.FileName, Encoding.Default)) { while (!reader.EndOfStream) { var path = reader.ReadLine(); var size = reader.ReadLine(); var position = reader.ReadLine(); if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(size) || string.IsNullOrEmpty(position)) { continue; } UserConfig.ByName("Parts")[path, "Size"] = size; UserConfig.ByName("Parts")[path, "Position"] = position; } } } MessageBox.Show("Styles settings imported!", "Done"); }
private void OnClickKeyFileBrowse(object sender, EventArgs e) { OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.KeyFileUseExisting, UIUtil.CreateFileTypeFilter("key", KPRes.KeyFiles, true), 2, null, false, AppDefs.FileDialogContext.KeyFile); if (ofd.ShowDialog() == DialogResult.OK) { string strFile = ofd.FileName; // try // { // IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile); // if(ioc.IsLocalFile()) // { // FileInfo fi = new FileInfo(strFile); // if(fi.Length >= (100 * 1024 * 1024)) // { // } // } // } // catch(Exception) { Debug.Assert(false); } m_cmbKeyFile.Items.Add(strFile); m_cmbKeyFile.SelectedIndex = m_cmbKeyFile.Items.Count - 1; } EnableUserControls(); }
private void btnOpenFileDlg_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialogEx("Select template file", "Image Files|*.jpg;*.png;*.jpeg;*.bmp")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { return; } textTemplateImage.Text = ofd.FileName; using (var bmp = new Bitmap(ofd.FileName)) pictureTemplate.Image = (Bitmap)bmp.Clone(); MouthRelative = new Vector2(pictureTemplate.Image.Width * 0.5f, pictureTemplate.Image.Height / 1.5f); // примерно расставляем глаз и рот EyeRelative = new Vector2(pictureTemplate.Image.Width * 0.5f, pictureTemplate.Image.Height * 0.2f); MouthRelative = new Vector2(MouthRelative.X / (pictureTemplate.Image.Width * 1f), MouthRelative.Y / (pictureTemplate.Image.Height * 1f)); EyeRelative = new Vector2(EyeRelative.X / (pictureTemplate.Image.Width * 1f), EyeRelative.Y / (pictureTemplate.Image.Height * 1f)); btnApply.Enabled = true; RecalcRealTemplateImagePosition(); RenderTimer.Start(); } }
private void btnAddNewMaterial_Click(object sender, EventArgs e) { string accessoryPath; string sampleImagePath; using (var ofd = new OpenFileDialogEx("Select new accessory..", "OBJ files|*.obj")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { return; } accessoryPath = ofd.FileName; } using (var ofd = new OpenFileDialogEx("Select accessory image..", "Image files|*.jpg")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { return; } sampleImagePath = ofd.FileName; } var directoryPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Libraries", "Accessory"); var oldFileName = Path.GetFileNameWithoutExtension(accessoryPath); var newFileName = oldFileName; var filePath = Path.Combine(directoryPath, newFileName + ".obj"); var index = 0; while (File.Exists(filePath)) { newFileName = oldFileName + string.Format("_{0}", index); filePath = Path.Combine(directoryPath, newFileName + ".obj"); ++index; } File.Copy(accessoryPath, filePath, false); var mtl = oldFileName + ".mtl"; var newMtlName = newFileName + ".mtl"; ObjLoader.CopyMtl(mtl, newMtlName, Path.GetDirectoryName(accessoryPath), "", directoryPath, ProgramCore.Project.TextureSize); if (mtl != newMtlName) // situation, when copy attribute and can change mtl filename. so, we need to rename link to this mtl in main obj file { string lines; using (var sd = new StreamReader(filePath, Encoding.Default)) { lines = sd.ReadToEnd(); lines = lines.Replace(mtl, newMtlName); } using (var sw = new StreamWriter(filePath, false, Encoding.Default)) sw.Write(lines); } var samplePath = Path.Combine(directoryPath, newFileName + ".jpg"); File.Copy(sampleImagePath, samplePath, false); InitializeListView(); }
public void OpenFileDialog(UCCanvas canvas) { try { if (!IsNeedToSave(canvas)) { return; } List <FigureBaseModel> figures = null; FigureFilePreview figurePreview = new FigureFilePreview(); OpenFileDialogEx open = new OpenFileDialogEx(); open.Filter = "所有文件(*.*)|*.WXF;*.DXF;|WSX默认切割文件(*.WXF)|*.WXF|AutoCAD图形文件(*.DXF)|*.DXF"; open.PreviewControl = figurePreview; open.OnFileSelectChanged += (s, e) => { if (figurePreview.IsPreView) { figures = ParseFigureFile(e.Path); figurePreview.FigurePreview(figures); } else { figurePreview.FigurePreview(new List <FigureBaseModel>()); } }; if (open.ShowDialog() == DialogResult.OK) { OpenFile(open.FileName, canvas, false, figures); } } catch (Exception ex) { XtraMessageBox.Show(ex.Message, "消息", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void rbImportObj_CheckedChanged(object sender, EventArgs e) { if (rbImportObj.Checked) { btnFemale.Tag = btnChild.Tag = btnMale.Tag = "2"; btnChild.Image = Properties.Resources.btnChildGray; btnMale.Image = Properties.Resources.btnMaleGray; btnFemale.Image = Properties.Resources.btnFemaleGray; if (!ProgramCore.PluginMode) { using (var ofd = new OpenFileDialogEx("Select obj file", "OBJ Files|*.obj")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { btnNext.Enabled = false; return; } btnNext.Enabled = true; CustomModelPath = ofd.FileName; } } } }
private void btnAddNewMaterial_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialogEx("Select new material..", "Image files|*.jpg")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { return; } var directoryPath = Path.Combine(UserConfig.DocumentsDir, "Materials"); var oldFileName = Path.GetFileNameWithoutExtension(ofd.FileName); var newFileName = oldFileName; var filePath = Path.Combine(directoryPath, newFileName + ".jpg"); var index = 0; while (File.Exists(filePath)) { newFileName = oldFileName + string.Format("_{0}", index); filePath = Path.Combine(directoryPath, newFileName + ".jpg"); ++index; } File.Copy(ofd.FileName, filePath, false); InitializeListView(); } }
public DialogResult ShowOpenFileDialog(IWin32Window owner) { _OpenFile = new OpenFileDialogEx(); _OpenFile.Filter = Strings.ICON_FILTER; _OpenFile.Title = Strings.CHANGE_ICON; _OpenFile.SelectionChanged += (s, e) => OnFileNameChanged(_OpenFile.FileName); return(_OpenFile.ShowDialog(this, owner)); }
public override bool Export(PwExportInfo pwExportInfo, Stream sOutput, IStatusLogger slLogger) { string strFilter = UIUtil.CreateFileTypeFilter("xsl", KPRes.XslFileType, true); OpenFileDialogEx dlgXsl = UIUtil.CreateOpenFileDialog(KPRes.XslSelectFile, strFilter, 1, "xsl", false, AppDefs.FileDialogContext.Xsl); if (dlgXsl.ShowDialog() != DialogResult.OK) { return(false); } string strXslFile = dlgXsl.FileName; XslCompiledTransform xsl = new XslCompiledTransform(); try { xsl.Load(strXslFile); } catch (Exception exXsl) { throw new NotSupportedException(strXslFile + MessageService.NewParagraph + KPRes.NoXslFile + MessageService.NewParagraph + exXsl.Message); } MemoryStream msDataXml = new MemoryStream(); PwDatabase pd = (pwExportInfo.ContextDatabase ?? new PwDatabase()); KdbxFile kdb = new KdbxFile(pd); kdb.Save(msDataXml, pwExportInfo.DataGroup, KdbxFormat.PlainXml, slLogger); byte[] pbData = msDataXml.ToArray(); msDataXml.Close(); MemoryStream msDataRead = new MemoryStream(pbData, false); XmlReader xmlDataReader = XmlReader.Create(msDataRead); XmlWriterSettings xws = new XmlWriterSettings(); xws.CheckCharacters = false; xws.Encoding = new UTF8Encoding(false); xws.NewLineChars = MessageService.NewLine; xws.NewLineHandling = NewLineHandling.None; xws.OmitXmlDeclaration = true; xws.ConformanceLevel = ConformanceLevel.Auto; XmlWriter xmlWriter = XmlWriter.Create(sOutput, xws); xsl.Transform(xmlDataReader, xmlWriter); xmlWriter.Close(); xmlDataReader.Close(); msDataRead.Close(); Array.Clear(pbData, 0, pbData.Length); return(true); }
public static bool?Synchronize(PwDatabase pwStorage, IUIOperations uiOps, bool bOpenFromUrl, Form fParent) { if (pwStorage == null) { throw new ArgumentNullException("pwStorage"); } if (!pwStorage.IsOpen) { return(null); } if (!AppPolicy.Try(AppPolicyId.Import)) { return(null); } List <IOConnectionInfo> vConnections = new List <IOConnectionInfo>(); if (bOpenFromUrl == false) { OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.Synchronize, UIUtil.CreateFileTypeFilter(AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1, null, true, AppDefs.FileDialogContext.Sync); if (ofd.ShowDialog() != DialogResult.OK) { return(null); } foreach (string strSelFile in ofd.FileNames) { vConnections.Add(IOConnectionInfo.FromPath(strSelFile)); } } else // Open URL { IOConnectionForm iocf = new IOConnectionForm(); iocf.InitEx(false, null, true, true); if (UIUtil.ShowDialogNotValue(iocf, DialogResult.OK)) { return(null); } vConnections.Add(iocf.IOConnectionInfo); UIUtil.DestroyForm(iocf); } return(Import(pwStorage, new KeePassKdb2x(), vConnections.ToArray(), true, uiOps, false, fParent)); }
private static string UIGetXslFile() { string strFilter = UIUtil.CreateFileTypeFilter("xsl", KPRes.XslFileType, true); OpenFileDialogEx dlgXsl = UIUtil.CreateOpenFileDialog(KPRes.XslSelectFile, strFilter, 1, "xsl", false, AppDefs.FileDialogContext.Xsl); if (dlgXsl.ShowDialog() != DialogResult.OK) { return(null); } return(dlgXsl.FileName); }
private void OnClickKeyFileBrowse(object sender, EventArgs e) { OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.KeyFileUseExisting, UIUtil.CreateFileTypeFilter("key", KPRes.KeyFiles, true), 2, null, false, null); if (ofd.ShowDialog() == DialogResult.OK) { string str = ofd.FileName; } EnableUserControls(); }
public void LoadPhoto() { using (var ofd = new OpenFileDialogEx("Select template file", "Image Files|*.jpg;*.png;*.jpeg;*.bmp")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { return; } templateImage = ofd.FileName; Recognizer = new LuxandFaceRecognition(); if (!Recognizer.Recognize(ref templateImage, true)) { templateImage = string.Empty; pictureTemplate.Image = null; return; // это ОЧЕНЬ! важно. потому что мы во время распознавания можем создать обрезанную фотку и использовать ее как основную в проекте. } using (var ms = new MemoryStream(File.ReadAllBytes(templateImage))) // Don't use using!! { var img = (Bitmap)Image.FromStream(ms); pictureTemplate.Image = (Bitmap)img.Clone(); img.Dispose(); } RecalcRealTemplateImagePosition(); var eWidth = pictureTemplate.Width - 100; var TopEdgeTransformed = new RectangleF(pictureTemplate.Width / 2f - eWidth / 2f, 30, eWidth, eWidth); // затычка. нужен будет подгон верхней части бошки - сделаю var minX = Recognizer.GetMinX(); var topPoint = (TopEdgeTransformed.Y - ImageTemplateOffsetY) / ImageTemplateHeight; Recognizer.FaceRectRelative = new RectangleF(minX, topPoint, Recognizer.GetMaxX() - minX, Recognizer.BottomFace.Y - topPoint); var noseTip = Recognizer.FacialFeatures[2].Xy; var noseTop = Recognizer.FacialFeatures[22].Xy; var noseBottom = Recognizer.FacialFeatures[49].Xy; ProgramCore.MainForm.RenderControl.PhotoLoaded(Recognizer, TemplateImage); RenderTimer.Start(); if (Math.Abs(Recognizer.RotatedAngle) > 20) { MessageBox.Show("The head rotated more than 20 degrees. Please select an other photo..."); } } }
private void OnDatabaseBrowse(object sender, EventArgs e) { string strTitle = "Choose database"; string strDesc = KPRes.KdbxFiles; string strFilterExt = AppDefs.FileExtension.FileExt; string strContext = AppDefs.FileDialogContext.Database; string strFilter = UIUtil.CreateFileTypeFilter(strFilterExt, strDesc, false); OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(strTitle, strFilter, 1, null, false, strContext); if (ofd.ShowDialog() == DialogResult.OK) { databaseLocationValue.Text = ofd.FileName; } }
private void btnOpenFileDlg_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialogEx("Select template file", "Image Files|*.jpg;*.png;*.jpeg;*.bmp")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { return; } textTemplateImage.Text = ofd.FileName; using (var bmp = new Bitmap(ofd.FileName)) pictureTemplate.Image = (Bitmap)bmp.Clone(); } }
private void OnClickKeyFileBrowse(object sender, EventArgs e) { OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.KeyFileUseExisting, UIUtil.CreateFileTypeFilter("key", KPRes.KeyFiles, true), 2, null, false, AppDefs.FileDialogContext.KeyFile); if (ofd.ShowDialog() == DialogResult.OK) { string str = ofd.FileName; m_cmbKeyFile.Items.Add(str); m_cmbKeyFile.SelectedIndex = m_cmbKeyFile.Items.Count - 1; } EnableUserControls(); }
public override byte[] GetKey(KeyProviderQueryContext ctx) { if (ctx == null) { throw new ArgumentNullException(nameof(ctx)); } // The key file is expected to be next to the database by default: var keyFilePath = UrlUtil.StripExtension(ctx.DatabasePath) + DefaultKeyExtension; CertificateShortcutProviderKey cspKey; if (ctx.CreatingNewKey) { // Always return null, so that it's not possible to accidentally create a composite key with this provider. MessageBox.Show("Certificate Shortcut Provider uses the encrypted master key to access the database. There is no initialization needed other than the master key.\n\nUse 'Options > Initialize Certificate Shortcut Provider...' from the menu to create the encrypted master key.", Name, MessageBoxButtons.OK, MessageBoxIcon.Information); return(null); } else { // We need to load an existing key file... while (!File.Exists(keyFilePath)) { var ofd = new OpenFileDialogEx("Select your Certificate Shortcut Provider Key file.") { Filter = $"Certificate Shortcut Provider Key files (*{DefaultKeyExtension})|*{DefaultKeyExtension}|All files (*.*)|*.*" }; if (ofd.ShowDialog() != DialogResult.OK) { return(null); } else { keyFilePath = ofd.FileName; } } using (var fs = new FileStream(keyFilePath, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) { cspKey = XmlUtilEx.Deserialize <CertificateShortcutProviderKey>(fs); } var secretKey = CryptoHelpers.DecryptPassphrase(cspKey); return(secretKey.ReadData()); } }
public override byte[] GetKey(KeyProviderQueryContext ctx) { // The key file is expected to be next to the database by default: var keyFilePath = UrlUtil.StripExtension(ctx.DatabasePath) + DefaultKeyExtension; CertificateShortcutProviderKey cspKey; if (ctx.CreatingNewKey) { // Show the key file creation form and always return null, // so that it's not possible to accidentally create a composite key with this provider. using (var form = new KeyCreationForm(keyFilePath)) { form.ShowDialog(); return(null); } } else { // We need to load an existing key file... while (!File.Exists(keyFilePath)) { var ofd = new OpenFileDialogEx("Select your Certificate Shortcut Provider Key file."); ofd.Filter = $"Certificate Shortcut Provider Key files (*{DefaultKeyExtension})|*{DefaultKeyExtension}|All files (*.*)|*.*"; if (ofd.ShowDialog() != DialogResult.OK) { return(null); } else { keyFilePath = ofd.FileName; } } using (var fs = new FileStream(keyFilePath, FileMode.Open, FileAccess.Read, FileShare.Read | FileShare.Delete)) { cspKey = XmlUtilEx.Deserialize <CertificateShortcutProviderKey>(fs); } var secretKey = CryptoHelpers.DecryptPassphrase(cspKey); return(secretKey.ReadData()); } }
private void pictureTemplate_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(textTemplateImage.Text)) { return; } using (var ofd = new OpenFileDialogEx("Select template file", "Image Files|*.jpg;*.png;*.jpeg;*.bmp")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { btnApply.Enabled = false; return; } ApplyNewImage(ofd.FileName); } }
private void OnClickKeyFileBrowse(object sender, EventArgs e) { string strFile = null; if (m_bSecureDesktop) { FileBrowserForm dlg = new FileBrowserForm(); dlg.InitEx(false, KPRes.KeyFileSelect, KPRes.SecDeskFileDialogHint, AppDefs.FileDialogContext.KeyFile); if (dlg.ShowDialog() == DialogResult.OK) { strFile = dlg.SelectedFile; } UIUtil.DestroyForm(dlg); } else { string strFilter = UIUtil.CreateFileTypeFilter("key", KPRes.KeyFiles, true); OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.KeyFileSelect, strFilter, 2, null, false, AppDefs.FileDialogContext.KeyFile); if (ofd.ShowDialog() == DialogResult.OK) { strFile = ofd.FileName; } } if (!string.IsNullOrEmpty(strFile)) { if ((Program.Config.UI.KeyPromptFlags & (ulong)AceKeyUIFlags.UncheckKeyFile) == 0) { UIUtil.SetChecked(m_cbKeyFile, true); } AddKeyFileSuggPriv(strFile, true); } EnableUserControls(); }
private void OnClickKeyFileBrowse(object sender, EventArgs e) { string strFilter = AppDefs.GetKeyFileFilter(); OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.KeyFileUseExisting, strFilter, 1, null, false, AppDefs.FileDialogContext.KeyFile); if (ofd.ShowDialog() != DialogResult.OK) { return; } string strFile = ofd.FileName; try { // Test whether we can read the file IOConnectionInfo ioc = IOConnectionInfo.FromPath(strFile); IOConnection.OpenRead(ioc).Close(); // Check the file size? } catch (Exception ex) { MessageService.ShowWarning(ex); return; } if (!KfxFile.CanLoad(strFile)) { if (!MessageService.AskYesNo(strFile + MessageService.NewParagraph + KPRes.KeyFileNoXml + MessageService.NewParagraph + KPRes.KeyFileUseAnywayQ, null, false)) { return; } } m_cmbKeyFile.Items.Add(strFile); m_cmbKeyFile.SelectedIndex = m_cmbKeyFile.Items.Count - 1; EnableUserControls(); }
private void btnLoadProject_Click(object sender, EventArgs e) { using (var ofd = new OpenFileDialogEx("Open HeadShop/HairShop project", "HeadShop projects|*.hds|HairShop projects|*.hs")) { ofd.Multiselect = false; if (ofd.ShowDialog(false) != DialogResult.OK) { return; } textLoadProject.Text = ofd.FileName; var templateImagePath = Project.LoadTempaltePath(textLoadProject.Text); if (!string.IsNullOrEmpty(templateImagePath)) { var fi = new FileInfo(templateImagePath); if (fi.Exists) { using (var bmp = new Bitmap(fi.FullName)) pictureTemplate.Image = (Bitmap)bmp.Clone(); } } } }
private void PerformImport(string strFileExt, string strFileDesc, ImportFn f) { OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog("Import " + strFileDesc, strFileDesc + " (*." + strFileExt + ")|*." + strFileExt + "|All Files (*.*)|*.*", 1, strFileExt, false, AppDefs.FileDialogContext.Import); if (ofd.ShowDialog() != DialogResult.OK) { return; } try { f(m_trl, IOConnectionInfo.FromPath(ofd.FileName)); } catch (Exception ex) { MessageBox.Show(this, ex.Message, TrlUtilName, MessageBoxButtons.OK, MessageBoxIcon.Warning); } UpdateStringTableUI(); UpdateControlTree(); m_tvControls.SelectedNode = m_tvControls.Nodes[0]; UpdatePreviewForm(); }
private void btnAddNew_Click(object sender, EventArgs e) { string elementPath; var sampleImagePath = string.Empty; var filterIndex = -1; using (var ofd = new OpenFileDialogEx("Select new item..", "Background|*.jpg|Pose|*.obj")) { ofd.Multiselect = false; if (ofd.ShowDialog(false) != DialogResult.OK) { return; } elementPath = ofd.FileName; filterIndex = ofd.FilterIndex; if (ofd.FilterIndex != 1) // if pose - require load screenshot to it { using (var imOfd = new OpenFileDialogEx("Select item image..", "Image files|*.jpg")) { imOfd.Multiselect = false; if (imOfd.ShowDialog() != DialogResult.OK) { return; } sampleImagePath = imOfd.FileName; } } } var directoryPath = string.Empty; switch (filterIndex) { case 1: directoryPath = Path.Combine(Application.StartupPath, "Stages", "Backgrounds"); break; case 2: directoryPath = Path.Combine(Application.StartupPath, "Stages", "Poses", ProgramCore.Project.ManType.GetCaption()); break; } if (string.IsNullOrEmpty(directoryPath)) { return; } var fileExtension = Path.GetExtension(elementPath); var oldFileName = Path.GetFileNameWithoutExtension(elementPath); var newFileName = oldFileName; var filePath = Path.Combine(directoryPath, newFileName + fileExtension); var index = 0; while (File.Exists(filePath)) { newFileName = oldFileName + string.Format("_{0}", index); filePath = Path.Combine(directoryPath, newFileName + fileExtension); ++index; } File.Copy(elementPath, filePath, false); if (!string.IsNullOrEmpty(sampleImagePath)) { var samplePath = Path.Combine(directoryPath, newFileName + ".jpg"); File.Copy(sampleImagePath, samplePath, false); } switch (filterIndex) { case 1: break; case 2: ProgramCore.MainForm.ctrlRenderControl.animationController.AddPoses(filePath); break; } InitializeListView(); }
private void btnAddNewMaterial_Click(object sender, EventArgs e) { string hairPath; string sampleImagePath; using (var ofd = new OpenFileDialogEx("Select new style..", "OBJ files|*.obj")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { return; } hairPath = ofd.FileName; } using (var ofd = new OpenFileDialogEx("Select style image..", "Image files|*.jpg")) { ofd.Multiselect = false; if (ofd.ShowDialog() != DialogResult.OK) { return; } sampleImagePath = ofd.FileName; } var directoryPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "Libraries", "Style"); var oldFileName = Path.GetFileNameWithoutExtension(hairPath); var newFileName = oldFileName; var filePath = Path.Combine(directoryPath, newFileName + ".obj"); if (hairPath != filePath) { File.Copy(hairPath, filePath, true); } var mtl = oldFileName + ".mtl"; var newMtlName = newFileName + ".mtl"; if (mtl != newMtlName) { ObjLoader.CopyMtl(mtl, newMtlName, Path.GetDirectoryName(hairPath), "", directoryPath, ProgramCore.Project.TextureSize); } if (mtl != newMtlName) // situation, when copy attribute and can change mtl filename. so, we need to rename link to this mtl in main obj file { string lines; using (var sd = new StreamReader(filePath, Encoding.Default)) { lines = sd.ReadToEnd(); lines = lines.Replace(mtl, newMtlName); } using (var sw = new StreamWriter(filePath, false, Encoding.Default)) sw.Write(lines); } var samplePath = Path.Combine(directoryPath, newFileName + ".jpg"); if (sampleImagePath != samplePath) { File.Copy(sampleImagePath, samplePath, true); } UserConfig.ByName("Options")["Styles", samplePath] = "1"; InitializeListView(); }
private void OnBtnSelFile(object sender, EventArgs e) { if (m_fmtCur == null) { Debug.Assert(false); return; } if (!m_fmtCur.RequiresFile) { return; // Break on double-click } string strFormat = m_fmtCur.FormatName; if (string.IsNullOrEmpty(strFormat)) { strFormat = KPRes.Data; } string strExts = m_fmtCur.DefaultExtension; if (string.IsNullOrEmpty(strExts)) { strExts = "export"; } string strPriExt = UIUtil.GetPrimaryFileTypeExt(strExts); if (strPriExt.Length == 0) { strPriExt = "export"; // In case of "|" } string strFilter = UIUtil.CreateFileTypeFilter(strExts, strFormat, true); if (m_bExport == false) // Import { OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.Import + ": " + strFormat, strFilter, 1, strPriExt, true, AppDefs.FileDialogContext.Import); if (ofd.ShowDialog() != DialogResult.OK) { return; } StringBuilder sb = new StringBuilder(); foreach (string str in ofd.FileNames) { if (sb.Length > 0) { sb.Append(';'); } if (str.IndexOf(';') >= 0) { MessageService.ShowWarning(str, KPRes.FileNameContainsSemicolonError); } else { sb.Append(str); } } string strFiles = sb.ToString(); if (strFiles.Length < m_tbFile.MaxLength) { m_tbFile.Text = strFiles; } else { MessageService.ShowWarning(KPRes.TooManyFilesError); } } else // Export { SaveFileDialogEx sfd = UIUtil.CreateSaveFileDialog(KPRes.Export + ": " + strFormat, null, strFilter, 1, strPriExt, AppDefs.FileDialogContext.Export); string strSuggestion; if ((m_pwDatabaseInfo != null) && (m_pwDatabaseInfo.IOConnectionInfo.Path.Length > 0)) { strSuggestion = UrlUtil.StripExtension(UrlUtil.GetFileName( m_pwDatabaseInfo.IOConnectionInfo.Path)); } else { strSuggestion = KPRes.Database; } strSuggestion += "." + strPriExt; sfd.FileName = strSuggestion; if (sfd.ShowDialog() != DialogResult.OK) { return; } m_tbFile.Text = sfd.FileName; } UpdateUIState(); }
private void OnFileOpen(object sender, EventArgs e) { OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog("Open KeePass Translation", m_strFileFilter, 1, null, false, AppDefs.FileDialogContext.Attachments); if (ofd.ShowDialog() != DialogResult.OK) { return; } KPTranslation kpTrl = null; try { XmlSerializerEx xs = new XmlSerializerEx(typeof(KPTranslation)); kpTrl = KPTranslation.LoadFromFile(ofd.FileName, xs); } catch (Exception ex) { MessageBox.Show(this, ex.Message, TrlUtilName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } m_strFile = ofd.FileName; StringBuilder sbUnusedText = new StringBuilder(); if (kpTrl.UnusedText.Length > 0) { if (kpTrl.UnusedText.EndsWith("\r") || kpTrl.UnusedText.EndsWith("\n")) { sbUnusedText.Append(kpTrl.UnusedText); } else { sbUnusedText.AppendLine(kpTrl.UnusedText); } } m_trl.Properties = kpTrl.Properties; foreach (KPStringTable kpstNew in kpTrl.StringTables) { foreach (KPStringTable kpstInto in m_trl.StringTables) { if (kpstInto.Name == kpstNew.Name) { MergeInStringTable(kpstInto, kpstNew, sbUnusedText); } } } FormTrlMgr.MergeForms(m_trl.Forms, kpTrl.Forms, sbUnusedText); m_tbNameEng.Text = m_trl.Properties.NameEnglish; m_tbNameLcl.Text = m_trl.Properties.NameNative; m_tbLangID.Text = m_trl.Properties.Iso6391Code; m_tbAuthorName.Text = m_trl.Properties.AuthorName; m_tbAuthorContact.Text = m_trl.Properties.AuthorContact; m_cbRtl.Checked = m_trl.Properties.RightToLeft; m_rtbUnusedText.Text = sbUnusedText.ToString(); this.UpdateStringTableUI(); this.UpdateStatusImages(null); this.UpdatePreviewForm(); }
private void OnBtnCustomAdd(object sender, EventArgs e) { string strAllSupportedFilter = KPRes.AllSupportedFiles + @" (*.bmp; *.emf; *.gif; *.ico; *.jpg; *.jpe; *.jpeg; *.jfif; *.jfi; *.jif; *.png; *.tif; *.tiff; *.wmf)" + @"|*.bmp;*.emf;*.gif;*.ico;*.jpg;*.jpe;*.jpeg;*.jfif;*.jfi;*.jif;*.png;*.tif;*.tiff;*.wmf"; StringBuilder sbFilter = new StringBuilder(); sbFilter.Append(strAllSupportedFilter); AddFileType(sbFilter, "*.bmp", "Windows Bitmap (*.bmp)"); AddFileType(sbFilter, "*.emf", "Windows Enhanced Metafile (*.emf)"); AddFileType(sbFilter, "*.gif", "Graphics Interchange Format (*.gif)"); AddFileType(sbFilter, "*.ico", "Windows Icon (*.ico)"); AddFileType(sbFilter, "*.jpg;*.jpe;*.jpeg;*.jfif;*.jfi;*.jif", "JPEG (*.jpg; *.jpe; *.jpeg; *.jfif; *.jfi; *.jif)"); AddFileType(sbFilter, "*.png", "Portable Network Graphics (*.png)"); AddFileType(sbFilter, "*.tif;*.tiff", "Tagged Image File Format (*.tif; *.tiff)"); AddFileType(sbFilter, "*.wmf", "Windows Metafile (*.wmf)"); sbFilter.Append(@"|" + KPRes.AllFiles + @" (*.*)|*.*"); OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.ImportFileTitle, sbFilter.ToString(), 1, null, true, AppDefs.FileDialogContext.Import); if (ofd.ShowDialog() == DialogResult.OK) { bool bSelectLastIcon = false; foreach (string strFile in ofd.FileNames) { bool bUnsupportedFormat = false; try { if (!File.Exists(strFile)) { throw new FileNotFoundException(); } // Image img = Image.FromFile(strFile); // Image img = Image.FromFile(strFile, false); // Image img = Bitmap.FromFile(strFile); // Bitmap img = new Bitmap(strFile); // Image img = Image.FromFile(strFile); byte[] pb = File.ReadAllBytes(strFile); // MemoryStream msSource = new MemoryStream(pb, false); // Image img = Image.FromStream(msSource); // msSource.Close(); Image img = GfxUtil.LoadImage(pb); MemoryStream ms = new MemoryStream(); if ((img.Width == 16) && (img.Height == 16)) { img.Save(ms, ImageFormat.Png); } else { // Image imgNew = new Bitmap(img, new Size(16, 16)); Bitmap imgSc = UIUtil.CreateScaledImage(img, 16, 16); imgSc.Save(ms, ImageFormat.Png); imgSc.Dispose(); } img.Dispose(); PwCustomIcon pwci = new PwCustomIcon(new PwUuid(true), ms.ToArray()); m_pwDatabase.CustomIcons.Add(pwci); ms.Close(); m_pwDatabase.UINeedsIconUpdate = true; m_pwDatabase.Modified = true; bSelectLastIcon = true; } catch (ArgumentException) { bUnsupportedFormat = true; } catch (System.Runtime.InteropServices.ExternalException) { bUnsupportedFormat = true; } catch (Exception exImg) { MessageService.ShowWarning(strFile, exImg); } if (bUnsupportedFormat) { MessageService.ShowWarning(strFile, KPRes.ImageFormatFeatureUnsupported); } } RecreateCustomIconList(bSelectLastIcon); } EnableControlsEx(); }
private void OnBtnCustomAdd(object sender, EventArgs e) { string strAllSupportedFilter = KPRes.AllSupportedFiles + @" (*.bmp; *.emf; *.gif; *.ico; *.jpg; *.jpe; *.jpeg; *.jfif; *.jfi; *.jif; *.png; *.tif; *.tiff; *.wmf)" + @"|*.bmp;*.emf;*.gif;*.ico;*.jpg;*.jpe;*.jpeg;*.jfif;*.jfi;*.jif;*.png;*.tif;*.tiff;*.wmf"; StringBuilder sbFilter = new StringBuilder(); sbFilter.Append(strAllSupportedFilter); AddFileType(sbFilter, "*.bmp", "Windows Bitmap (*.bmp)"); AddFileType(sbFilter, "*.emf", "Windows Enhanced Metafile (*.emf)"); AddFileType(sbFilter, "*.gif", "Graphics Interchange Format (*.gif)"); AddFileType(sbFilter, "*.ico", "Windows Icon (*.ico)"); AddFileType(sbFilter, "*.jpg;*.jpe;*.jpeg;*.jfif;*.jfi;*.jif", "JPEG (*.jpg; *.jpe; *.jpeg; *.jfif; *.jfi; *.jif)"); AddFileType(sbFilter, "*.png", "Portable Network Graphics (*.png)"); AddFileType(sbFilter, "*.tif;*.tiff", "Tagged Image File Format (*.tif; *.tiff)"); AddFileType(sbFilter, "*.wmf", "Windows Metafile (*.wmf)"); sbFilter.Append(@"|" + KPRes.AllFiles + @" (*.*)|*.*"); OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(KPRes.ImportFileTitle, sbFilter.ToString(), 1, null, true, AppDefs.FileDialogContext.Import); if (ofd.ShowDialog() != DialogResult.OK) { return; } // Predicate<PwCustomIcon> fRequiresKdbx4p1 = delegate(PwCustomIcon ci) // { // return ((ci.Name.Length != 0) || ci.LastModificationTime.HasValue); // }; // bool bUseFileName = m_pd.CustomIcons.Exists(fRequiresKdbx4p1); PwUuid puSelect = PwUuid.Zero; foreach (string strFile in ofd.FileNames) { MemoryStream msPng = new MemoryStream(); string strError = null; try { byte[] pb = File.ReadAllBytes(strFile); using (Image img = GfxUtil.LoadImage(pb)) { if (img == null) { throw new FormatException(); } const int wMax = PwCustomIcon.MaxWidth; const int hMax = PwCustomIcon.MaxHeight; if ((img.Width <= wMax) && (img.Height <= hMax)) { img.Save(msPng, ImageFormat.Png); } else { using (Image imgSc = GfxUtil.ScaleImage(img, wMax, hMax)) { imgSc.Save(msPng, ImageFormat.Png); } } } PwUuid pu = new PwUuid(true); PwCustomIcon ci = new PwCustomIcon(pu, msPng.ToArray()); // if(bUseFileName) // { // string strName = UrlUtil.StripExtension( // UrlUtil.GetFileName(strFile)); // if(!string.IsNullOrEmpty(strName)) ci.Name = strName; // } m_pd.CustomIcons.Add(ci); m_pd.UINeedsIconUpdate = true; m_pd.Modified = true; if (puSelect.Equals(PwUuid.Zero)) { puSelect = pu; } } catch (ArgumentException) { strError = KPRes.ImageFormatFeatureUnsupported; } catch (System.Runtime.InteropServices.ExternalException) { strError = KPRes.ImageFormatFeatureUnsupported; } catch (Exception ex) { strError = ex.Message; } finally { msPng.Close(); } if (!string.IsNullOrEmpty(strError)) { MessageService.ShowWarning(strFile, strError); } } RecreateCustomIconList(puSelect); EnableControlsEx(); UIUtil.SetFocus(m_lvCustomIcons, this); }