void SaveProfileHistory() { StreamWriter writer = null; if (File.Exists(m_sProfileHistoryFile)) { File.Delete(m_sProfileHistoryFile); } try { writer = new StreamWriter(File.Open(m_sProfileHistoryFile, FileMode.OpenOrCreate)); foreach (string pro in m_profileHistory.Values) { writer.WriteLine(pro); } writer.Close(); } catch (Exception e) { if (writer != null) { writer.Close(); } CUserInteractionUtils.ShowErrorMessageBox(e.Message); } }
/// <summary> /// Saves old profile to file and load new one. /// </summary> /// <param name="sProfileFolderPath">Relative path to the folder containing the new profile</param> public void LoadNewProfile(string sProfileFolderPath) { SaveApplicationSettings(); if (!Directory.Exists(sProfileFolderPath)) { CUserInteractionUtils.ShowErrorMessageBox("Could not find specified profile folder path, not loading profile!"); // LOCALIZE return; } m_sCurrentProfileSavePath = sProfileFolderPath; AdjustSettingsPaths(); LoadApplicationSettings(); LoadProgramDefinitions(); LoadShortcutsFromFile(); var dirInfo = new DirectoryInfo(sProfileFolderPath); if (dirInfo != null) { if (!m_profileHistory.ContainsKey(dirInfo.Name)) { m_profileHistory.Add(dirInfo.Name, sProfileFolderPath); } } }
static void OnContextDeleteClicked(object sender, EventArgs args) { var selectedItem = m_targetTreeView.SelectedItem as DirectoryTreeItem; if (selectedItem != null) { try { if (selectedItem.IsDirectory) { FileSystem.DeleteDirectory(selectedItem.FullPath, UIOption.AllDialogs, RecycleOption.DeletePermanently, UICancelOption.DoNothing); var mainWindow = Application.Current.MainWindow as Window1; if (mainWindow != null) { mainWindow.ValidateRootPath(); mainWindow.ValidateGameFolder(); } } else { FileSystem.DeleteFile(selectedItem.FullPath, UIOption.AllDialogs, RecycleOption.DeletePermanently, UICancelOption.DoNothing); } } catch (Exception e) { CUserInteractionUtils.ShowErrorMessageBox(e.Message); } } }
string GetCurrentSettingsFolder() { if (!File.Exists(m_sSettingsFilePath + m_sCurrentProfileFilePath)) { return(""); } FileStream fileStream = null; try { fileStream = File.OpenRead(m_sSettingsFilePath + m_sCurrentProfileFilePath); StreamReader strReader = new StreamReader(fileStream); string sLine = strReader.ReadLine(); strReader.Close(); return(sLine); } catch (Exception e) { if (fileStream != null) { fileStream.Close(); } CUserInteractionUtils.ShowErrorMessageBox(e.Message); return(""); } }
void OnOkClicked(object sender, RoutedEventArgs e) { if (saveFileTextBox.Text.Contains(".")) { CUserInteractionUtils.ShowErrorMessageBox(Properties.DragZoneResources.TextIsNoDirectory); } else { bool sux = true; if (m_fileInfoList != null && m_fileInfoList.Count > 0) { sux = ProcessRequest(m_fileInfoList); } if (m_dirInfoList != null && m_dirInfoList.Count > 0) { sux = ProcessRequest(m_dirInfoList, saveFileTextBox.Text); } if (sux) { Close(); } } }
private bool ProcessRequest(DirectoryInfo info, string sTargetPath) { try { CopyDirectory(info, sTargetPath); } catch (UnauthorizedAccessException e) { CUserInteractionUtils.ShowErrorMessageBox(e.Message); return(false); } return(true); }
/*public SShortcut(int nID, string sName, string sExec, string sArgs) * { * myID = nID; * Name = sName; * Exec = sExec; * Args = sArgs; * }*/ public void Start() { if (!File.Exists(Exec)) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.CommonPathDoesntExist + "(" + Exec + ")"); return; } Process p = new Process(); ProcessStartInfo info = new ProcessStartInfo(Exec); info.Arguments = Args; p.StartInfo = info; p.Start(); }
private bool ApplyCurrentSettings() { if (!ValidateDefs()) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.DCCDefChangesNotSaved); return(false); } if (GetCurrentProgram() != null) { if (File.Exists(programExeTextBox.Text)) { SDCCProgram pro = GetCurrentProgram(); pro.ExecutablePath = programExeTextBox.Text; } else { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.CommonPathDoesntExist + " (" + programExeTextBox.Text + ")"); } if (GetCurrentStartupFile() != null) { if (File.Exists(startupFileTextBox.Text)) { SStartupFile file = GetCurrentStartupFile(); file.SetFilePath(startupFileTextBox.Text); file.Copy = (bool)copyFileCheckbox.IsChecked; file.LaunchWithProgram = (bool)launchWithProgCheckbox.IsChecked; } else { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.CommonPathDoesntExist + " (" + startupFileTextBox.Text + ")"); } } UpdateListViews(); } ApplyAllChanges(); return(true); }
public void SaveShortcutsToFile() { XmlTextWriter writer = null; try { writer = new XmlTextWriter(File.Open(m_sShortcutsSavePath, FileMode.Create), System.Text.Encoding.UTF8); writer.Formatting = Formatting.Indented; if (writer != null) { writer.WriteStartDocument(); writer.WriteStartElement("Shortcuts"); foreach (SShortcut sc in Shortcuts) { writer.WriteStartElement("Shortcut"); writer.WriteAttributeString("id", sc.myID.ToString()); writer.WriteAttributeString("name", sc.Name); writer.WriteAttributeString("exec", sc.Exec); writer.WriteAttributeString("args", sc.Args); writer.WriteEndElement(); } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); } } catch (Exception e) { if (writer != null) { writer.Close(); } CUserInteractionUtils.ShowErrorMessageBox(e.Message); } }
void OnLoadProfileClicked(object sender, RoutedEventArgs e) { bool bOK = false; System.Windows.Forms.OpenFileDialog dialog = new System.Windows.Forms.OpenFileDialog(); dialog.CheckFileExists = true; dialog.CheckPathExists = true; dialog.InitialDirectory = new DirectoryInfo(CApplicationSettings.Instance.SettingsFilePath).FullName; FileInfo fileInf = null; while (bOK != true) { System.Windows.Forms.DialogResult res = dialog.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { fileInf = new FileInfo(dialog.FileName); if (fileInf.Directory.Parent.Name != "Profiles") { CUserInteractionUtils.ShowErrorMessageBox("Please specify a folder inside the " + // LOCALIZE CApplicationSettings.Instance.SettingsFilePath + "subdirectory of CEWSP!"); } else { bOK = true; } } else { return; } } string sRelPath = CApplicationSettings.Instance.SettingsFilePath + "\\" + fileInf.Directory.Name; CApplicationSettings.Instance.LoadNewProfile(sRelPath); PostLoadProfile(); }
private bool ValidateDefs() { foreach (CDCCDefinition def in m_dccDefCopy.Values) { foreach (SDCCProgram prog in def.Programs.Values) { foreach (SStartupFile file in prog.StartupFiles.Values) { if (!File.Exists(file.FullName)) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.CommonPathDoesntExist + " :" + file.FullName + " (" + file.Name + ")"); return(false); } } if (!File.Exists(prog.ExecutablePath)) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.CommonPathDoesntExist + " :" + prog.ExecutablePath + " (" + prog.Name + ")"); return(false); } } if (def.Programs.Count <= 0) { MessageBoxResult res = MessageBox.Show(Properties.Resources.DCCDefEmptyDef, Properties.Resources.CommonError, MessageBoxButton.OKCancel, MessageBoxImage.Error); if (res == MessageBoxResult.Cancel) { return(false); } } } return(true); }
int AddFileEntryCallback(TextBox box, System.Windows.Forms.DialogResult res) { if (GetCurrentProgram() != null) { SDCCProgram prog = GetCurrentProgram(); if (prog.StartupFiles.ContainsKey(box.Text)) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.DCCDefDuplicateEntry + " " + box.Text); return(0); } SStartupFile newFile = new SStartupFile(box.Text, ""); prog.StartupFiles.Add(newFile.Name, newFile); RefreshFilesListView(); } return(0); }
public void DeleteProfile(string sKey, bool bHistoryOnly) { if (!bHistoryOnly) { if (m_profileHistory[sKey] == m_sCurrentProfileSavePath) { CUserInteractionUtils.ShowErrorMessageBox("Trying to delete currently active profile, please switch to another one first!"); // LOCALIZE return; } try { Directory.Delete(m_profileHistory[sKey], true); } catch (DirectoryNotFoundException) { } } m_profileHistory.Remove(sKey); }
private void TryAlterSystemCFG(string sNewGameFolderPath) { MessageBoxResult res = MessageBox.Show(Properties.Resources.AskGameFolderUpdateCFG, Properties.Resources.CommonNotice, MessageBoxButton.YesNo, MessageBoxImage.Question); if (res == MessageBoxResult.Yes) { if (CApplicationSettings.Instance.IsRootValid(CApplicationSettings.Instance.GetValue(ESettingsStrings.RootPath).GetValueString())) { SetGameFolderInSysCFG(CApplicationSettings.Instance.GetValue(ESettingsStrings.GameFolderPath).GetValueString()); } else { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.RootNotValidNoSaveChanges); } } }
private void StartProcess(string path, string args = "") { if (!File.Exists(path)) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.QuickAccesPathNonexistent); return; } Process programProcess = new Process(); programProcess.Exited += OnProcessTerminated; programProcess.ErrorDataReceived += OnProcessTerminated; programProcess.EnableRaisingEvents = true; ProcessStartInfo startInfo = new ProcessStartInfo(path, args); programProcess.StartInfo = startInfo; programProcess.Start(); }
//######################################################################################### // Callbacks //######################################################################################### int ProgramDefAddCallback(TextBox box, System.Windows.Forms.DialogResult res) { if (res != System.Windows.Forms.DialogResult.Cancel) { if (m_dccDefCopy.ContainsKey(box.Text)) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.DCCDefDuplicateEntry + " " + box.Text); return(0); } CDCCDefinition newDef = new CDCCDefinition(); newDef.Name = box.Text; m_dccDefCopy.Add(newDef.Name, newDef); RefreshDCCDefDropdown(); TrySelectDCCDef(newDef.Name); } return(0); }
static void OnContextRunGFXClicked(object sender, RoutedEventArgs args) { DirectoryTreeItem selectedItem = m_targetTreeView.SelectedItem as DirectoryTreeItem; if (selectedItem.IsDirectory) { CUserInteractionUtils.ShowErrorMessageBox("You can only run the gfxexporter on files (directory was selected)"); // LOCALIZE return; } else { FileInfo fileInf = new FileInfo(selectedItem.FullPath); if (fileInf.Extension != ".swf") { CUserInteractionUtils.ShowErrorMessageBox("You can only run the gfxexporter on .swf files"); // LOCALIZE return; } CProcessUtils.RunGFXExporter(fileInf); } }
static void OnContextRecycleClicked(object sender, EventArgs args) { DirectoryTreeItem selectedItem = m_targetTreeView.SelectedItem as DirectoryTreeItem; DirectoryTreeItem parent = selectedItem.GetParentSave() as DirectoryTreeItem; try { if (selectedItem.IsDirectory) { //Directory.Delete(selectedItem.FullPath, true); FileSystem.DeleteDirectory(selectedItem.FullPath, UIOption.AllDialogs, RecycleOption.SendToRecycleBin, UICancelOption.DoNothing); var mainWindow = Application.Current.MainWindow as Window1; if (mainWindow != null) { mainWindow.ValidateRootPath(); mainWindow.ValidateGameFolder(); } } else { //File.Delete(selectedItem.FullPath); FileSystem.DeleteFile(selectedItem.FullPath, UIOption.AllDialogs, RecycleOption.SendToRecycleBin, UICancelOption.DoNothing); } } catch (Exception e) { if (e is ArgumentException || e is UnauthorizedAccessException || e is IOException) { CUserInteractionUtils.ShowErrorMessageBox(e.Message); } else { throw; } } }
bool AddProgramEntryCallback(TextBox box, System.Windows.Forms.DialogResult res) { if (GetCurrentDefinition() != null) { CDCCDefinition def = GetCurrentDefinition(); if (def.Programs.ContainsKey(box.Text)) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.DCCDefDuplicateEntry + " " + box.Text); return(false); } SDCCProgram prog = new SDCCProgram(); prog.Name = box.Text; def.Programs.Add(prog.Name, prog); UpdateListViews(); } return(true); }
void LoadProfileHistory() { if (!File.Exists(m_sProfileHistoryFile)) { return; } m_profileHistory.Clear(); StreamReader reader = null; try { reader = new StreamReader(File.Open(m_sProfileHistoryFile, FileMode.Open)); while (!reader.EndOfStream) { string sEntry = reader.ReadLine(); var dirInf = new DirectoryInfo(sEntry); m_profileHistory.Add(dirInf.Name, sEntry); } reader.Close(); } catch (Exception e) { if (reader != null) { reader.Close(); } CUserInteractionUtils.ShowErrorMessageBox(e.Message); } }
void OnAddNewProgramClicked(object sender, RoutedEventArgs args) { //CUserInteractionUtils.AskUserToEnterString(Properties.Resources.DCCDefEnterProgName, AddProgramEntryCallback); var grid = new Grid(); for (int i = 0; i < 5; i++) { var rowDef = new RowDefinition(); rowDef.Height = new GridLength(12, GridUnitType.Star); grid.RowDefinitions.Add(rowDef); } // Label var label = new Label(); label.Content = "Either enter name or choose existing"; // LOCALIZE label.SetValue(Grid.RowProperty, 0); grid.Children.Add(label); // Combobox var comboBox = new ComboBox(); comboBox.SetValue(Grid.RowProperty, 1); // items in combobox var progs = CApplicationSettings.Instance.GetAllDCCProgramsDefined(); foreach (var prog in progs.Keys) { var item = new ComboBoxItem(); item.Content = prog; comboBox.Items.Add(item); } grid.Children.Add(comboBox); // Name label label = new Label(); label.Content = "Name"; // LOCALIZE label.SetValue(Grid.RowProperty, 2); grid.Children.Add(label); // text box var textBox = new TextBox(); textBox.Text = "New Program"; textBox.SetValue(Grid.RowProperty, 3); grid.Children.Add(textBox); // Ok Cancel var okCancGrid = new Grid(); okCancGrid.SetValue(Grid.RowProperty, 4); var colDef = new ColumnDefinition(); colDef.Width = new GridLength(50, GridUnitType.Star); okCancGrid.ColumnDefinitions.Add(colDef); colDef = new ColumnDefinition(); colDef.Width = new GridLength(50, GridUnitType.Star); okCancGrid.ColumnDefinitions.Add(colDef); var okBtn = new Button(); okBtn.Content = Properties.Resources.CommonOK; okBtn.SetValue(Grid.ColumnProperty, 0); okCancGrid.Children.Add(okBtn); var cancButton = new Button(); cancButton.Content = Properties.Resources.CommonCancel; cancButton.SetValue(Grid.ColumnProperty, 1); okCancGrid.Children.Add(cancButton); grid.Children.Add(okCancGrid); var window = new Window(); window.SizeToContent = SizeToContent.WidthAndHeight; window.Content = grid; window.WindowStartupLocation = WindowStartupLocation.CenterScreen; window.Title = "Add new program"; // LOCALIZE comboBox.SelectionChanged += delegate { textBox.IsEnabled = false; }; okBtn.Click += delegate { // If there's a wrong entry, keep the window open bool bCloseWindow = false; if (comboBox.SelectedIndex != -1) { var programs = CApplicationSettings.Instance.GetAllDCCProgramsDefined(); string sSelected = (comboBox.SelectedItem as ComboBoxItem).Content as string; var curDef = GetCurrentDefinition(); if (curDef == null) { return; } if (!curDef.Programs.ContainsKey(sSelected)) { SDCCProgram prog = null; if (programs.TryGetValue(sSelected, out prog)) { curDef.Programs.Add(prog.Name, prog); UpdateDataGrid(); UpdateListViews(); bCloseWindow = true; } } else { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.DCCDefDuplicateEntry + " " + sSelected); } } else { if (textBox.Text.Length > 0) { bCloseWindow = AddProgramEntryCallback(textBox, System.Windows.Forms.DialogResult.OK); } else { CUserInteractionUtils.ShowErrorMessageBox("Please enter a name or choose an existing program from the dropdown!"); // LOCALIZE } } if (bCloseWindow) { window.Close(); } else { comboBox.SelectedIndex = -1; textBox.IsEnabled = true; } }; cancButton.Click += delegate { window.Close(); }; window.ShowDialog(); }
void OnSaveProfileClicked(object sender, RoutedEventArgs e) { CUserInteractionUtils.AskUserToEnterString("Please enter a name for the new profile", OnFinishedEnteringProfileName); // LOCALIZE }
// Button interaction void OnAddProgramDefinitionClicked(object sender, RoutedEventArgs args) { CUserInteractionUtils.AskUserToEnterString(Properties.Resources.DCCDefEnterDefName, ProgramDefAddCallback); }
static int RenameTreeEntry(TextBox box) { // DONE_TODO: Account for extension being typed already... DirectoryTreeItem selectedItem = m_targetTreeView.SelectedItem as DirectoryTreeItem; try { if (selectedItem.IsDirectory) { string newPath = selectedItem.FullPath.Substring(0, selectedItem.FullPath.LastIndexOf('\\')) + '\\' + box.Text; //Directory.Move(selectedItem.FullPath, newPath); FileSystem.RenameDirectory(selectedItem.FullPath, newPath); } else { var fileInfo = new FileInfo(selectedItem.FullPath); string sNewExtension = CPathUtils.GetExtension(box.Text); if (sNewExtension != box.Text && sNewExtension != fileInfo.Extension.TrimStart('.')) { var res = MessageBox.Show(Properties.Resources.FEConfirmChangeExtension, Properties.Resources.CommonNotice, MessageBoxButton.YesNo, MessageBoxImage.Question); if (res != MessageBoxResult.Yes) { sNewExtension = fileInfo.Extension.TrimStart('.'); } } else { if (sNewExtension == box.Text) { sNewExtension = fileInfo.Extension.TrimStart('.'); } } string filename = CPathUtils.RemoveExtension(CPathUtils.GetFilename(box.Text)); FileSystem.RenameFile(selectedItem.FullPath, filename + "." + sNewExtension); } } catch (Exception e) { if (e is ArgumentException || e is UnauthorizedAccessException || e is IOException) { CUserInteractionUtils.ShowErrorMessageBox(e.Message); } else { throw; } } var mainWindow = Application.Current.MainWindow as Window1; if (mainWindow != null) { // Not elegant but all the error checking is done in these methods // no sense in writing them again mainWindow.ValidateRootPath(); mainWindow.ValidateGameFolder(); } //selectedItem = selectedItem.GetParentSave() as DirectoryTreeItem; //selectedItem.Items.Clear(); //TraverseDirectory(new DirectoryInfo(selectedItem.FullPath), ref selectedItem); return(0); }
static void OnContextPasteClicked(object sender, EventArgs args) { // DONE_TODO: Implement directory copying if (!Clipboard.ContainsFileDropList()) { return; } DirectoryTreeItem targetItem = m_targetTreeView.SelectedItem as DirectoryTreeItem; if (!targetItem.IsDirectory) { targetItem = targetItem.GetParentSave() as DirectoryTreeItem; } //string fileSource = Clipboard.GetFileDropList()[0]; foreach (string fileSource in Clipboard.GetFileDropList()) { FileInfo fileInfo = new FileInfo(fileSource); if (fileInfo.Exists) { string fileTarget = targetItem.FullPath + "\\" + fileInfo.Name; try { //File.Copy(fileSource, fileTarget, true); if (m_bIsFileCut) { FileSystem.MoveFile(fileSource, fileTarget, UIOption.AllDialogs, UICancelOption.DoNothing); } else { CProcessUtils.CopyFile(fileSource, fileTarget, false); } } catch (Exception e) { CUserInteractionUtils.ShowErrorMessageBox(e.Message); m_bIsFileCut = false; } } else { // It's a direcory? DirectoryInfo dirInf = new DirectoryInfo(fileSource); if (dirInf.Exists) { string targetDir = targetItem.FullPath + "\\" + dirInf.Name; if (m_bIsFileCut) { CProcessUtils.MoveDirectory(dirInf.FullName, targetDir, false); } else { CProcessUtils.CopyDirectory(dirInf.FullName, targetDir, false); } } } } TraverseDirectory(new DirectoryInfo(targetItem.FullPath), ref targetItem); }
void OnAddFileClicked(object sender, RoutedEventArgs args) { CUserInteractionUtils.AskUserToEnterString(Properties.Resources.DCCDefEnterFileName, AddFileEntryCallback); }
public void LoadIgnoredFilesList(bool bCheckForSanity = true) { m_ignoredFilesWacher.EnableRaisingEvents = false; try { m_ignoredFiles.Clear(); m_ignoredNegatedRegexList.Clear(); m_ignoredRegexList.Clear(); FileStream stream = File.Open(m_sIgnoredFilesListPath, FileMode.Open); StreamReader reader = new StreamReader(stream); while (!reader.EndOfStream) { string line = reader.ReadLine(); line = line.Trim(); if (line.StartsWith("#") || String.IsNullOrWhiteSpace(line)) { continue; } if (line.IndexOf('#') != -1) { line = line.Substring(0, line.IndexOf('#')); line = line.Trim(); } m_ignoredFiles.Add(line); } reader.Close(); } catch (FileNotFoundException) { File.Create(m_sIgnoredFilesListPath); try { LoadIgnoredFilesList(); } catch (Exception) { } } m_ignoredFiles.Add(Window1.m_sGameTempDirName); foreach (string ignoredPath in m_ignoredFiles) { try { if (!ignoredPath.StartsWith("!")) { m_ignoredRegexList.Add(new Regex(ignoredPath)); } else { m_ignoredNegatedRegexList.Add(new Regex(ignoredPath.TrimStart('!'))); } } catch (ArgumentException e) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.IgnoredRegexWrong + '\n' + e.Message); continue; } } if (bCheckForSanity) { if (!CheckIgnoredFilesSanity()) { CUserInteractionUtils.ShowInfoMessageBox(Properties.Resources.IngoredRegexDoesntExist); } } else { CLogfile.Instance.LogWarning("[Source tracker] Loading ignored files file without sanity check! Performance and logic issues inbound!"); } m_ignoredFilesWacher.EnableRaisingEvents = true; }
private void LoadProgramDefinitions() { XmlTextReader reader = null; try { if (!File.Exists(m_sProgramDefSavePath)) { SaveProgramDefinitions(); } reader = new XmlTextReader(m_sProgramDefSavePath); string currentDef = ""; string currentProg = ""; while (reader.Read()) { reader.MoveToElement(); if (reader.LocalName == "ProgramDef" && reader.AttributeCount > 0) { reader.MoveToNextAttribute(); var def = new CDCCDefinition(); def.Name = reader.Value; SetDCCProgram(def); currentDef = reader.Value; } else if (reader.LocalName == "Program" && reader.AttributeCount > 0) { reader.MoveToNextAttribute(); SDCCProgram program = new SDCCProgram(); program.Name = reader.Value; reader.MoveToNextAttribute(); program.ExecutablePath = reader.Value; GetDCCProgram(currentDef).Programs.Add(program.Name, program); currentProg = program.Name; } else if (reader.LocalName == "File") { SDCCProgram prog = GetDCCProgram(currentDef).GetProgram(currentProg); SStartupFile file = new SStartupFile("", ""); reader.MoveToNextAttribute(); file.Name = reader.Value; reader.MoveToNextAttribute(); file.SetFilePath(reader.Value); reader.MoveToNextAttribute(); bool boolVal; Boolean.TryParse(reader.Value, out boolVal); file.Copy = boolVal; reader.MoveToNextAttribute(); Boolean.TryParse(reader.Value, out boolVal); file.LaunchWithProgram = boolVal; prog.StartupFiles.Add(file.Name, file); } else { } } } catch (Exception e) { if (reader != null) { reader.Close(); } CUserInteractionUtils.ShowErrorMessageBox(e.Message); // TODO: More ionfo pls } }
void OnOKClicked(object sender, RoutedEventArgs e) { string path = fileTextBox.Text; string[] paths = path.Split(';'); foreach (string filePath in paths) { if (String.IsNullOrWhiteSpace(filePath)) { continue; } string finalPath = filePath; if (!finalPath.Contains(".")) { CUserInteractionUtils.ShowErrorMessageBox(Properties.Resources.CommonNoFileNameSpecified); return; } FileInfo info = new FileInfo(finalPath); if (info.Extension != CSourceTracker.FileExtension) { finalPath = CPathUtils.ChangeExtension(finalPath, CSourceTracker.FileExtension); } if (!info.Directory.Exists) { Directory.CreateDirectory(info.DirectoryName); } EFileRoot root; bool bDoBoth = false; if (affectionComboBox.SelectedIndex == 0) { root = EFileRoot.eFR_CERoot; } else if (affectionComboBox.SelectedIndex == 1) { root = EFileRoot.eFR_GameFolder; } else { root = EFileRoot.eFR_CERoot; bDoBoth = true; } switch (m_mode) { case EMode.eMO_Import: { EFileRoot targetRoot = CSourceTracker.Instance.GetTrackingFileAffection(finalPath); if (!bDoBoth && targetRoot != root) { CUserInteractionUtils.ShowErrorMessageBox(Properties.ImportExportResources.AffectionMissmatch); return; } CSourceTracker.Instance.ImportTrackingList(finalPath, CSourceTracker.Instance.GetTrackingFileAffection(finalPath)); } break; case EMode.eMO_Export: { if (!bDoBoth) { CSourceTracker.Instance.ExportTrackingFile(finalPath, root); } else { string name = finalPath; string noExtension = CPathUtils.RemoveExtension(name); string rootFile = noExtension; string gameFile = noExtension; if (!rootFile.Contains("_Root")) { rootFile += "_Root"; } if (!gameFile.Contains("_Game")) { gameFile += "_Game"; } CSourceTracker.Instance.ExportTrackingFile(rootFile + CSourceTracker.FileExtension, EFileRoot.eFR_CERoot); CSourceTracker.Instance.ExportTrackingFile(gameFile + CSourceTracker.FileExtension, EFileRoot.eFR_GameFolder); } } break; case EMode.eMO_Move: { if (!bDoBoth) { CSourceTracker.Instance.MoveTrackedFiles(finalPath, root); } else { CSourceTracker.Instance.MoveTrackedFiles(finalPath, EFileRoot.eFR_CERoot); CSourceTracker.Instance.MoveTrackedFiles(finalPath, EFileRoot.eFR_GameFolder); } } break; default: throw new Exception("Invalid value for EMode"); } } Close(); }
private void SaveProgramDefinitions() { XmlTextWriter writer = null; try { if (File.Exists(m_sProgramDefSavePath)) { File.Delete(m_sProgramDefSavePath); } writer = new XmlTextWriter(File.Open(m_sProgramDefSavePath, FileMode.Create), System.Text.Encoding.UTF8); writer.Formatting = Formatting.Indented; writer.WriteStartDocument(); writer.WriteStartElement("ProgramDefs"); foreach (var prog in DCCPrograms.Values) { if (prog != null) { writer.WriteStartElement("ProgramDef"); writer.WriteAttributeString("name", prog.Name); //writer.WriteAttributeString("exec", prog.GetConcatenatedExecs()); //writer.WriteAttributeString("file", prog.GetConcatenatedStartups()); foreach (string progKey in prog.Programs.Keys) { SDCCProgram progele; prog.Programs.TryGetValue(progKey, out progele); writer.WriteStartElement("Program"); writer.WriteAttributeString("name", progele.Name); writer.WriteAttributeString("Exec", progele.ExecutablePath); foreach (string fileKey in progele.StartupFiles.Keys) { SStartupFile file; progele.StartupFiles.TryGetValue(fileKey, out file); writer.WriteStartElement("File"); writer.WriteAttributeString("name", file.Name); writer.WriteAttributeString("path", file.FullName); writer.WriteAttributeString("copy", file.Copy.ToString()); writer.WriteAttributeString("launch", file.LaunchWithProgram.ToString()); writer.WriteEndElement(); } writer.WriteEndElement(); } writer.WriteEndElement(); } } writer.WriteEndElement(); writer.WriteEndDocument(); writer.Close(); } catch (Exception e) { if (writer != null) { writer.Close(); } CUserInteractionUtils.ShowErrorMessageBox(e.Message); // TODO: More info pls } }