private bool CanSaveFile(string file, bool addExtensionIfRequired) { bool canSave = false; OPMSaveFileDialog dlg = this as OPMSaveFileDialog; if (dlg != null) { string ext = PathUtils.GetExtension(file); if (string.IsNullOrEmpty(ext) && dlg.AddExtension) { file = $"{file}.{dlg.DefaultExt}"; } bool exists = File.Exists(file); if (exists) { canSave = (!dlg.OverwritePrompt || ConfirmOverwrite(file)); } else { canSave = (!dlg.CreatePrompt || ConfirmCreate(file)); } } return(canSave); }
private void OnBrowseCatalog(object sender, EventArgs e) { OPMSaveFileDialog dlg = new OPMSaveFileDialog(); dlg.Title = Translator.Translate("TXT_SELECTCATALOG"); dlg.Filter = Translator.Translate("TXT_CATALOG_FILTER"); dlg.DefaultExt = "ctx"; dlg.InitialDirectory = BuiltinAddonConfig.MCLastOpenedFolder; dlg.FillFavoriteFoldersEvt += () => { return ProTONEConfig.GetFavoriteFolders("FavoriteFolders"); }; dlg.AddToFavoriteFolders += (s) => { return ProTONEConfig.AddToFavoriteFolders(s); }; dlg.ShowAddToFavorites = true; if (dlg.ShowDialog() == DialogResult.OK) { BuiltinAddonConfig.MCLastOpenedFolder = Path.GetDirectoryName(dlg.FileName); (BkgTask as Task).CatalogPath = dlg.FileName; lblCatalogPath.Text = Translator.Translate("TXT_CATALOGPATH", dlg.FileName); ThreadPool.QueueUserWorkItem(new WaitCallback(DisplayCatalogContents)); } }
private bool SaveThemeFileWithDialog() { if (_themeFile != null) { OPMSaveFileDialog dlg = new OPMSaveFileDialog(); dlg.Title = Translator.Translate("TXT_SAVETHEMEFILE"); dlg.Filter = Translator.Translate("TXT_THEMEFILE_FILTER"); dlg.DefaultExt = "thm"; dlg.InitialDirectory = SkinBuilderConfiguration.LastOpenedFolder; if (dlg.ShowDialog() == DialogResult.OK) { SkinBuilderConfiguration.LastOpenedFolder = Path.GetDirectoryName(dlg.FileName); string ext = PathUtils.GetExtension(dlg.FileName); SaveThemeFile(dlg.FileName); DisplayThemeFile(); return true; } } return false; }
private void SaveCatalogWithDialog() { OPMSaveFileDialog dlg = new OPMSaveFileDialog(); dlg.Title = Translator.Translate("TXT_SAVECATALOG"); dlg.Filter = Translator.Translate("TXT_CATALOG_FILTER"); dlg.DefaultExt = "ctx"; dlg.InitialDirectory = BuiltinAddonConfig.MCLastOpenedFolder; dlg.FillFavoriteFoldersEvt += () => { return ProTONEConfig.GetFavoriteFolders("FavoriteFolders"); }; dlg.AddToFavoriteFolders += (s) => { return ProTONEConfig.AddToFavoriteFolders(s); }; dlg.ShowAddToFavorites = true; if (dlg.ShowDialog() == DialogResult.OK) { BuiltinAddonConfig.MCLastOpenedFolder = Path.GetDirectoryName(dlg.FileName); _bwSave.RunWorkerAsync(dlg.FileName); ShowWaitDialog("TXT_WAIT_SAVING_CATALOG"); } }
private void OnSaveLogFile(object sender, EventArgs e) { OPMSaveFileDialog dlg = new OPMSaveFileDialog(); dlg.Title = Translator.Translate("TXT_SAVELOGFILE"); dlg.Filter = Translator.Translate("TXT_LOGFILE_FILTER"); dlg.DefaultExt = "log"; if (dlg.ShowDialog(this) == DialogResult.OK) { Logger.CopyCurrentLogFile(dlg.FileName); } }
private void OnSaveWindow(object sender, EventArgs e) { OPMSaveFileDialog dlg = new OPMSaveFileDialog(); dlg.Title = Translator.Translate("TXT_SAVELOGFILE_PART"); dlg.Filter = Translator.Translate("TXT_LOGFILE_FILTER"); dlg.DefaultExt = "log"; if (dlg.ShowDialog(this) == DialogResult.OK) { StringBuilder sb = new StringBuilder(); foreach (ListViewItem item in lvLogLines.Items) { string line = item.Tag as string; if (!string.IsNullOrEmpty(line)) { sb.AppendLine(line); } } using (StreamWriter sw = new StreamWriter(dlg.FileName)) { sw.Write(sb.ToString()); } } }
private void btnSave_Click(object sender, EventArgs e) { if (lvPictures.SelectedItems.Count > 0) { PictureInfo pi = lvPictures.SelectedItems[0].Tag as PictureInfo; if (pi != null) { OPMSaveFileDialog dlg = new OPMSaveFileDialog(); dlg.Filter = "All image files|*.bmp;*.jpg;*.jpeg;*.jpe;*.jfif;*.gif;*.tif;*.tiff;*.png;*.ico;||"; if (dlg.ShowDialog() == DialogResult.OK) { ImageFormat imgFormat = ImageFormat.Bmp; switch(PathUtils.GetExtension(dlg.FileName).ToLowerInvariant()) { case "jpg": case "jpeg": case "jpe": imgFormat = ImageFormat.Jpeg; break; case "gif": imgFormat = ImageFormat.Gif; break; case "tif": case "tiff": imgFormat = ImageFormat.Tiff; break; case "png": imgFormat = ImageFormat.Png; break; case "ico": imgFormat = ImageFormat.Icon; break; case "bmp": default: imgFormat = ImageFormat.Bmp; break; } pi.Picture.Save(dlg.FileName, imgFormat); } } } }
internal void SavePlaylist() { string filter = string.Empty; filter += MediaRenderer.DefaultInstance.PlaylistsFilter; filter += Translator.Translate("TXT_ALL_FILES_FILTER"); filter = filter.Replace("TXT_PLAYLISTS", Translator.Translate("TXT_PLAYLISTS")); OPMSaveFileDialog dlg = new OPMSaveFileDialog(); dlg.Title = Translator.Translate("TXT_SAVEPLAYLIST"); dlg.Filter = filter; dlg.DefaultExt = "m3u"; dlg.FilterIndex = ProTONEConfig.PL_LastFilterIndex; dlg.InitialDirectory = ProTONEConfig.PL_LastOpenedFolder; dlg.InheritAppIcon = false; dlg.Icon = Resources.btnSavePlaylist.ToIcon((uint)Color.White.ToArgb()); dlg.FillFavoriteFoldersEvt += () => { return ProTONEConfig.GetFavoriteFolders("FavoriteFolders"); }; dlg.AddToFavoriteFolders += (s) => { return ProTONEConfig.AddToFavoriteFolders(s); }; dlg.ShowAddToFavorites = true; dlg.ShowNewFolder = true; if (dlg.ShowDialog() == DialogResult.OK) { ProTONEConfig.PL_LastFilterIndex = dlg.FilterIndex; playlist.SavePlaylist(dlg.FileName); try { FileInfo fi = new FileInfo(dlg.FileName); ProTONEConfig.PL_LastOpenedFolder = fi.DirectoryName; } catch { ProTONEConfig.PL_LastOpenedFolder = dlg.InitialDirectory; } } }
private void tsmiExportFull_Click(object sender, EventArgs e) { OPMSaveFileDialog dlg = new OPMSaveFileDialog(); dlg.Filter = Translator.Translate("TXT_CONFIG_FILES_FILTER"); dlg.DefaultExt = "config"; dlg.Title = Translator.Translate("TXT_EXPORT_FULL"); if (dlg.ShowDialog() == DialogResult.OK) { _config.WriteXml(dlg.FileName); } }
private void tsmiExportPartial_Click(object sender, EventArgs e) { try { string selRemoteName = string.Empty; TreeNode node = tvRemotes.SelectedNode; if (node != null) { if (node.Tag is RCCServiceConfig.RemoteControlRow) { selRemoteName = (node.Tag as RCCServiceConfig.RemoteControlRow).RemoteName; } else if (node.Tag is RCCServiceConfig.RemoteButtonsRow) { selRemoteName = (node.Tag as RCCServiceConfig.RemoteButtonsRow).RemoteName; } } RCCServiceConfig partialConfig = new RCCServiceConfig(); var remote = (from rc in _config.RemoteControl where rc.RemoteName == selRemoteName select rc).FirstOrDefault(); if (remote != null) { partialConfig.RemoteControl.AddRemoteControlRow(selRemoteName, remote.InputPinName, remote.InputPinCfgData, remote.OutputPinName, remote.OutputPinCfgData, remote.Enabled); var buttons = (from rb in _config.RemoteButtons where rb.RemoteName == selRemoteName select rb); if (buttons != null) { foreach(var button in buttons) { partialConfig.RemoteButtons.AddRemoteButtonsRow(selRemoteName, button.InputData, button.OutputData, button.ButtonName, button.TargetWndName, button.Enabled, button.TimedRepeatRate); } partialConfig.RemoteButtons.AcceptChanges(); } partialConfig.RemoteControl.AcceptChanges(); OPMSaveFileDialog dlg = new OPMSaveFileDialog(); dlg.Filter = Translator.Translate("TXT_CONFIG_FILES_FILTER"); dlg.DefaultExt = "config"; dlg.Title = Translator.Translate("TXT_EXPORT_PARTIAL"); if (dlg.ShowDialog() == DialogResult.OK) { partialConfig.WriteXml(dlg.FileName); } } } catch (Exception ex) { ErrorDispatcher.DispatchError(ex); } }