//New project private void projectToolStripMenuItem_Click(object sender, EventArgs e) { // string projectName = GetUniqueStringDialog("New Project", "Name", "", projectDir.GetDirectories(), // "The project can not be created because another project of same name already exists."); DirectoryInfo[] directories = projectDir.GetDirectories(); string[] takenNames = new string[directories.Length]; for (int i = 0; i < directories.Length; i++) takenNames[i] = directories[i].Name.ToLower(); NewProjectForm dialog = new NewProjectForm(takenNames, projectDir.FullName); if (dialog.ShowDialog(this) == DialogResult.Cancel) return; string projectName = dialog.ProjectName; string folderName = dialog.Directory; CreateNewProject(projectName, folderName); //Test valid path //Now done in new project form /*{ if (projectName.Trim() == "") { MessageBox.Show(this, "Invalid project name.", "Error"); return; } DirectoryInfo t; try { t = new DirectoryInfo(Path.Combine(projectDir.FullName, projectName)); } catch (Exception) { MessageBox.Show(this, "Invalid project name.", "Error"); return; } if (t.Parent.FullName.Trim('\\', '/') != projectDir.FullName.Trim('\\', '/')) { MessageBox.Show(this, "Invalid project name.", "Error"); return; } }*/ /*if (openProjectDir != null) { bool cancel; CloseProject(out cancel); if (cancel) return; } DirectoryInfo subDir = projectDir.CreateSubdirectory(projectName); if (projectDir.FullName.Trim('\\', '/') != folderName) { StreamWriter writer = File.CreateText(Path.Combine(subDir.FullName, "Relocate.txt")); writer.WriteLine(Path.Combine(folderName, projectName)); writer.Flush(); writer.Close(); writer.Dispose(); Directory.CreateDirectory(Path.Combine(folderName, projectName)); } openProjectDir = subDir; openProjectDir.CreateSubdirectory("src"); FileInfo defultMapScript = new FileInfo("DefaultMapScript.galaxy++"); if (defultMapScript.Exists) { defultMapScript.CopyTo(openProjectSrcDir.Dir.FullName + "\\MapScript.galaxy++"); openProjectSrcDir.FixConflicts(".galaxy++", ".Dialog"); compiler.AddSourceFiles(GetSourceFiles(openProjectSrcDir)); compiler.AddDialogItems(GetDialogsFiles(openProjectSrcDir)); //AddSourceFilesToCompiler(openProjectSrcDir); } RebuildProjectView();*/ }
private void saveProjectAsToolStripMenuItem_Click(object sender, EventArgs e) { DirectoryInfo[] directories = projectDir.GetDirectories(); string[] takenNames = new string[directories.Length]; for (int i = 0; i < directories.Length; i++) takenNames[i] = directories[i].Name.ToLower(); NewProjectForm dialog = new NewProjectForm(takenNames, projectDir.FullName, true); if (dialog.ShowDialog(this) == DialogResult.Cancel) return; string projectName = dialog.ProjectName; string folderName = dialog.Directory; //Copy current project to a safe location DirectoryInfo currentProjectCopyLoc = new DirectoryInfo("temp"); int nr = 0; while (currentProjectCopyLoc.Exists) { currentProjectCopyLoc = new DirectoryInfo("temp" + ++nr); } CopyDirectories(openProjectDir, currentProjectCopyLoc); //Save current project SaveAll(); //Create relocate if neccecery DirectoryInfo subDir = new DirectoryInfo(Path.Combine(projectDir.FullName, projectName)); DirectoryInfo targetDir = new DirectoryInfo(Path.Combine(folderName, projectName)); if (projectDir.FullName.Trim('\\', '/') != folderName) { subDir.Create(); StreamWriter writer = File.CreateText(Path.Combine(subDir.FullName, "Relocate.txt")); writer.WriteLine(Path.Combine(folderName, projectName)); writer.Flush(); writer.Close(); writer.Dispose(); Directory.CreateDirectory(Path.Combine(folderName, projectName)); } //Close currnet project, and then move it DirectoryInfo oldDir = openProjectDir; bool cancel; CloseProject(out cancel); string oldDirName = oldDir.FullName; oldDir.MoveTo(targetDir.FullName); //Move the original project back currentProjectCopyLoc.MoveTo(oldDirName); //Open the other project OpenProject(subDir); }
private void openExistingProjectToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = LocRM.GetString("GEFile.Text"); dialog.CheckFileExists = true; if (dialog.ShowDialog(this) != DialogResult.OK) return; FileInfo propertiesFile = new FileInfo(dialog.FileName); DirectoryInfo newProjectDir = propertiesFile.Directory; DirectoryInfo[] directories = projectDir.GetDirectories(); DirectoryInfo subDir; for (int i = 0; i < directories.Length; i++) if (newProjectDir.Name.ToLower() == directories[i].Name.ToLower()) { bool isTargetDir = false; if (directories[i].FullName.Trim('\\', '/') == newProjectDir.FullName.Trim('\\', '/')) isTargetDir = true; else { foreach (FileInfo relocateFile in directories[i].GetFiles("Relocate.txt")) { StreamReader reader = new StreamReader(relocateFile.FullName); string relocatePath = reader.ReadToEnd().Trim('\n', '\r', '\\', '/'); if (relocatePath == newProjectDir.FullName.Trim('\\', '/')) isTargetDir = true; reader.Close(); reader.Dispose(); } } if (isTargetDir) { if (openProjectDir != null) { bool cancel; CloseProject(out cancel); if (cancel) return; } OpenProject(directories[i]); return; } MessageBox.Show(this, LocRM.GetString("Text3.Text") + newProjectDir.Name + LocRM.GetString("Text4.Text"), LocRM.GetString("Text5.Text")); string[] takenNames = new string[directories.Length]; for (int j = 0; j < directories.Length; j++) takenNames[j] = directories[j].Name.ToLower(); NewProjectForm newNameDialog = new NewProjectForm(takenNames, projectDir.FullName, false, false); if (newNameDialog.ShowDialog(this) == DialogResult.Cancel) return; //CreateNewProject(newNameDialog.ProjectName, newProjectDir.Parent.FullName, newProjectDir.FullName); if (openProjectDir != null) { bool cancel; CloseProject(out cancel); if (cancel) return; } subDir = projectDir.CreateSubdirectory(newNameDialog.ProjectName); //if (projectDir.FullName.Trim('\\', '/') != folderName) { StreamWriter writer = File.CreateText(Path.Combine(subDir.FullName, "Relocate.txt")); writer.WriteLine(newProjectDir.FullName); writer.Flush(); writer.Close(); writer.Dispose(); } OpenProject(subDir); return; } if (openProjectDir != null) { bool cancel; CloseProject(out cancel); if (cancel) return; } subDir = projectDir.CreateSubdirectory(newProjectDir.Name); //if (projectDir.FullName.Trim('\\', '/') != folderName) { StreamWriter writer = File.CreateText(Path.Combine(subDir.FullName, "Relocate.txt")); writer.WriteLine(newProjectDir.FullName); writer.Flush(); writer.Close(); writer.Dispose(); } OpenProject(subDir); }