private void OpenSelectedProject() { if (_selectedProject == null) // If no project is selected { return; } string errorMessage; if (!ProjectChecker.IsValidProject(_selectedProject, out errorMessage)) { DarkMessageBox.Show(this, "Failed to load project. " + errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (!IsValidGameLauncher()) { return; } // Set RememberedProject if checkBox_Remember is checked if (checkBox_Remember.Checked) { _ide.IDEConfiguration.RememberedProject = _selectedProject.Name; } // Save settings and hide the current window SaveSettings(); Hide(); // Show the main form of TombIDE using (FormMain form = new FormMain(_ide, _selectedProject)) { DialogResult result = form.ShowDialog(this); if (result == DialogResult.OK) // OK means the user wants to switch projects { // Reset the RememberedProject setting _ide.IDEConfiguration.RememberedProject = string.Empty; _ide.IDEConfiguration.Save(); // Restart the application (without any arguments) Application.Exit(); Process.Start(Assembly.GetExecutingAssembly().Location); } else if (result == DialogResult.Cancel) // Cancel means the user closed the program { Application.Exit(); } } }
private void OpenTrproj() { using (OpenFileDialog dialog = new OpenFileDialog()) { dialog.Title = "Select the .trproj file you want to open"; dialog.Filter = "TombIDE Project Files|*.trproj"; if (dialog.ShowDialog(this) == DialogResult.OK) { try { Project openedProject = Project.FromFile(dialog.FileName); string errorMessage; if (!ProjectChecker.IsValidProject(openedProject, out errorMessage)) { throw new ArgumentException(errorMessage); } // Check if a project with the same name but different paths already exists on the list foreach (DarkTreeNode node in treeView.Nodes) { Project nodeProject = (Project)node.Tag; if (nodeProject.Name.ToLower() == openedProject.Name.ToLower() && nodeProject.ProjectPath.ToLower() != openedProject.ProjectPath.ToLower()) { if (AskForProjectNodeReplacement(openedProject, node)) { break; // The user confirmed replacing the node } else { return; // The user declined replacing the node } } } if (!IsProjectOnList(openedProject)) { AddProjectToList(openedProject, true); } SelectProjectOnList(openedProject.Name); } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void FillProjectList() { treeView.Nodes.Clear(); // Add nodes into the treeView for each project foreach (Project project in _ide.AvailableProjects) { if (ProjectChecker.IsValidProject(project)) { AddProjectToList(project, false); } } // Update TombIDEProjects.xml with only valid projects RefreshAndReserializeProjects(); }
public void OpenTrprojWithTombIDE(string trprojFilePath) { try { Project openedProject = Project.FromFile(trprojFilePath); string errorMessage; if (!ProjectChecker.IsValidProject(openedProject, out errorMessage)) { throw new ArgumentException(errorMessage); } // Check if a project with the same name but different paths already exists on the list foreach (DarkTreeNode node in treeView.Nodes) { Project nodeProject = (Project)node.Tag; if (nodeProject.Name.ToLower() == openedProject.Name.ToLower() && nodeProject.ProjectPath.ToLower() != openedProject.ProjectPath.ToLower()) { if (AskForProjectNodeReplacement(openedProject, node)) { break; // The user confirmed replacing the node } else { return; // The user declined replacing the node } } } if (!IsProjectOnList(openedProject)) { AddProjectToList(openedProject, true); } _ide.IDEConfiguration.RememberedProject = openedProject.Name; // Continue code in Program.cs } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button_Import_Click(object sender, EventArgs e) { button_Import.Enabled = false; try { if (!File.Exists(textBox_ExePath.Text)) { throw new FileNotFoundException("The game's .exe file doesn't exist anymore."); } if (!File.Exists(textBox_LauncherPath.Text)) { throw new FileNotFoundException("The project's launcher file doesn't exist anymore."); } string projectName = PathHelper.RemoveIllegalPathSymbols(textBox_ProjectName.Text.Trim()); if (string.IsNullOrWhiteSpace(projectName)) { throw new ArgumentException("You must enter a valid name for the project."); } if (projectName.ToLower() == "engine") // Safety { throw new ArgumentException("Illegal project name."); } if (string.IsNullOrWhiteSpace(textBox_ScriptPath.Text)) { throw new ArgumentException("You must specify the /Script/ folder path of the project."); } if (string.IsNullOrWhiteSpace(textBox_LevelsPath.Text)) { throw new ArgumentException("You must specify the /Levels/ folder path for the project."); } if (ProjectChecker.IsProjectNameDuplicate(projectName)) { throw new ArgumentException("A project with the same name already exists on the list."); } TRVersion.Game gameVersion = GetGameVersion(textBox_ExePath.Text); string launcherFilePath = textBox_LauncherPath.Text; string projectPath = GetProjectDirectory(textBox_ExePath.Text); string enginePath = Path.GetDirectoryName(textBox_ExePath.Text); string scriptPath = textBox_ScriptPath.Text.Trim(); string levelsPath = textBox_LevelsPath.Text.Trim(); // Check if a script.txt file exists in the specified /Script/ folder if (!File.Exists(Path.Combine(scriptPath, "script.txt"))) { throw new FileNotFoundException("Selected /Script/ folder does not contain a Script.txt file."); } // Check if the levelsPath directory exists, if so, check if it contains any valid .prj2 files if (Directory.Exists(levelsPath)) { // Check if the directory contains non-backup .prj2 files List <string> prj2Files = LevelHandling.GetValidPrj2FilesFromDirectory(levelsPath); if (prj2Files.Count > 0) { DialogResult result = DarkMessageBox.Show(this, "TombIDE will change the \"Game\" settings of all the .prj2 files\n" + "in the specified /Levels/ folder to match the imported project settings.\n" + "Would you like to to create a backup of the folder first?", "Create backup?", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { CreateLevelsBackup(levelsPath); } } } else { Directory.CreateDirectory(levelsPath); } Project importedProject = new Project { Name = projectName, GameVersion = gameVersion, DefaultLanguage = GameLanguage.English, LaunchFilePath = launcherFilePath, ProjectPath = projectPath, EnginePath = enginePath, ScriptPath = scriptPath, LevelsPath = levelsPath }; // Create the .trproj file importedProject.Save(); // .trproj = .xml but .trproj can be opened with TombIDE // // // // // // // // ImportedProject = importedProject; // // // // // // // // } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); button_Import.Enabled = true; DialogResult = DialogResult.None; } }
private void button_Create_Click(object sender, EventArgs e) { button_Create.Text = "Installing..."; button_Create.Enabled = false; try { string projectName = PathHelper.RemoveIllegalPathSymbols(textBox_ProjectName.Text.Trim()); if (string.IsNullOrWhiteSpace(projectName)) { throw new ArgumentException("You must enter a valid name for your project."); } if (projectName.ToLower() == "engine") // Safety { throw new ArgumentException("Illegal project name."); } if (string.IsNullOrWhiteSpace(textBox_ProjectPath.Text)) { throw new ArgumentException("You must select a folder where you want to install your project."); } if (radio_Script_02.Checked && string.IsNullOrWhiteSpace(textBox_ScriptPath.Text)) { throw new ArgumentException("You must specify the custom /Script/ folder path."); } if (radio_Levels_02.Checked && string.IsNullOrWhiteSpace(textBox_LevelsPath.Text)) { throw new ArgumentException("You must specify the custom /Levels/ folder path."); } if (ProjectChecker.IsProjectNameDuplicate(projectName)) { throw new ArgumentException("A project with the same name already exists on the list."); } if (comboBox_EngineType.SelectedIndex == 0) { throw new ArgumentException("You must specify the engine type of the project."); } string projectPath = textBox_ProjectPath.Text.Trim(); string enginePath = Path.Combine(projectPath, "Engine"); string scriptPath = radio_Script_01.Checked ? Path.Combine(projectPath, "Script") : textBox_ScriptPath.Text.Trim(); string levelsPath = radio_Levels_01.Checked ? Path.Combine(projectPath, "Levels") : textBox_LevelsPath.Text.Trim(); if (!Directory.Exists(projectPath)) { Directory.CreateDirectory(projectPath); } if (Directory.EnumerateFileSystemEntries(projectPath).ToArray().Length > 0) { throw new ArgumentException("Selected project folder is not empty."); } if (!Directory.Exists(scriptPath)) { Directory.CreateDirectory(scriptPath); } if (Directory.EnumerateFileSystemEntries(scriptPath).ToArray().Length > 0) { throw new ArgumentException("Selected /Script/ folder is not empty."); } if (!Directory.Exists(levelsPath)) { Directory.CreateDirectory(levelsPath); } if (Directory.EnumerateFileSystemEntries(levelsPath).ToArray().Length > 0) { throw new ArgumentException("Selected /Levels/ folder is not empty."); } // Create the Project instance Project createdProject = CreateNewProject(projectName, projectPath, enginePath, scriptPath, levelsPath); // Install the game files into the specified projectPath folder InstallEngine(createdProject); DarkMessageBox.Show(this, "Project installation finished successfully.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); // // // // // // // // CreatedProject = createdProject; // // // // // // // // } catch (Exception ex) { DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); button_Create.Text = "Create Project"; button_Create.Enabled = true; DialogResult = DialogResult.None; } }