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; } }