Пример #1
0
 private void UpdateAllPrj2GameSettings(DirectoryInfo directory, ProjectLevel detectedLevel)
 {
     foreach (FileInfo file in directory.GetFiles("*.prj2", SearchOption.TopDirectoryOnly))
     {
         if (!ProjectLevel.IsBackupFile(file.Name))
         {
             LevelHandling.UpdatePrj2GameSettings(file.FullName, detectedLevel, _ide.Project);
         }
     }
 }
        private void EnableAndFillPrj2FileList()
        {
            treeView_AllPrjFiles.Enabled  = true;
            checkBox_ShowAllFiles.Enabled = true;

            // When the user switched the _ide.SelectedLevel and the current _ide.SelectedLevel 's SpecificFile is a backup file,
            // then check this checkbox, otherwise it will reset the SpecificFile to a non-backup file and we don't want that
            checkBox_ShowAllFiles.Checked = ProjectLevel.IsBackupFile(_ide.SelectedLevel.SpecificFile);

            UpdatePrj2FileList();
        }
Пример #3
0
        private bool FolderOnlyContainsBackupFiles(DirectoryInfo directory)
        {
            foreach (FileInfo file in directory.GetFiles("*.prj2", SearchOption.TopDirectoryOnly))
            {
                if (!ProjectLevel.IsBackupFile(file.Name))
                {
                    return(false);                    // We got a non-backup file
                }
            }

            return(true);
        }
Пример #4
0
        public static List <string> GetValidPrj2FilesFromDirectory(string directoryPath)
        {
            List <string> validPrj2Files = new List <string>();

            foreach (string file in Directory.GetFiles(directoryPath, "*.prj2", SearchOption.AllDirectories))
            {
                if (!ProjectLevel.IsBackupFile(Path.GetFileName(file)))
                {
                    validPrj2Files.Add(file);
                }
            }

            return(validPrj2Files);
        }
        private void checkBox_ShowAllFiles_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton_LatestFile.Checked)
            {
                return;
            }

            UpdatePrj2FileList();

            // If the user unchecked the checkBox and the SpecificFile was a backup file
            if (!checkBox_ShowAllFiles.Checked && ProjectLevel.IsBackupFile(_ide.SelectedLevel.SpecificFile))
            {
                treeView_AllPrjFiles.SelectNode(treeView_AllPrjFiles.Nodes[0]);                 // Select something else since the item is no longer on the list
            }
        }
Пример #6
0
        private void UpdateAllPrj2FilesInLevelDirectory(ProjectLevel importedLevel)
        {
            string[] files = Directory.GetFiles(importedLevel.FolderPath, "*.prj2", SearchOption.TopDirectoryOnly);

            progressBar.Visible = true;
            progressBar.BringToFront();
            progressBar.Maximum = files.Length;

            foreach (string file in files)
            {
                if (!ProjectLevel.IsBackupFile(Path.GetFileName(file)))
                {
                    LevelHandling.UpdatePrj2GameSettings(file, importedLevel, _targetProject);
                }

                progressBar.Increment(1);
            }
        }
        private void UpdatePrj2FileList()
        {
            treeView_AllPrjFiles.Nodes.Clear();

            foreach (string file in Directory.GetFiles(_ide.SelectedLevel.FolderPath, "*.prj2", SearchOption.TopDirectoryOnly))
            {
                // Don't show backup files if checkBox_ShowAllFiles is unchecked
                if (!checkBox_ShowAllFiles.Checked && ProjectLevel.IsBackupFile(Path.GetFileName(file)))
                {
                    continue;
                }

                // Create the .prj2 file node
                DarkTreeNode node = new DarkTreeNode
                {
                    Text = Path.GetFileName(file),
                    Tag  = file
                };

                // Add the node to the .prj2 file list
                treeView_AllPrjFiles.Nodes.Add(node);
            }

            // Select the SpecificFile node (if the file exists on the list)
            bool nodeFound = false;

            foreach (DarkTreeNode node in treeView_AllPrjFiles.Nodes)
            {
                if (node.Text.ToLower() == _ide.SelectedLevel.SpecificFile.ToLower())
                {
                    treeView_AllPrjFiles.SelectNode(node);
                    nodeFound = true;

                    break;
                }
            }

            if (!nodeFound)
            {
                treeView_AllPrjFiles.SelectNode(treeView_AllPrjFiles.Nodes[0]);                 // Select the first node if no file was found
            }
            treeView_AllPrjFiles.Invalidate();
        }
Пример #8
0
        private void ImportLevel()
        {
            using (OpenFileDialog dialog = new OpenFileDialog())
            {
                dialog.Title  = "Choose the .prj2 file you want to import";
                dialog.Filter = "Tomb Editor Levels|*.prj2";

                if (dialog.ShowDialog(this) == DialogResult.OK)
                {
                    try
                    {
                        if (dialog.FileName.StartsWith(_ide.Project.LevelsPath, StringComparison.OrdinalIgnoreCase))
                        {
                            throw new ArgumentException("You cannot import levels which are already inside the project's /Levels/ folder.");
                        }

                        if (ProjectLevel.IsBackupFile(Path.GetFileName(dialog.FileName)))
                        {
                            throw new ArgumentException("You cannot import backup files.");
                        }

                        using (FormImportLevel form = new FormImportLevel(_ide.Project, dialog.FileName))
                        {
                            if (form.ShowDialog(this) == DialogResult.OK)
                            {
                                OnLevelAdded(form.ImportedLevel, form.GeneratedScriptLines);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        DarkMessageBox.Show(this, ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Пример #9
0
        private void EnableAndFillTreeView()
        {
            treeView.Enabled           = true;
            button_SelectAll.Enabled   = true;
            button_DeselectAll.Enabled = true;

            treeView.Nodes.Clear();

            foreach (string file in Directory.GetFiles(textBox_Prj2Path.Text, "*.prj2", SearchOption.TopDirectoryOnly))
            {
                if (ProjectLevel.IsBackupFile(Path.GetFileName(file)))
                {
                    continue;
                }

                DarkTreeNode node = new DarkTreeNode
                {
                    Text = Path.GetFileName(file),
                    Tag  = file,
                };

                treeView.Nodes.Add(node);
            }
        }
Пример #10
0
        private void CreateLevelsBackup(string levelsPath)
        {
            try
            {
                // Check if there are any existing backup folders of the /Levels/ folder in the parent directory of the levelsPath
                string[] existingBackupFolders = Directory.GetDirectories(
                    Path.GetDirectoryName(levelsPath), Path.GetFileName(levelsPath) + "_BACKUP*", SearchOption.TopDirectoryOnly);

                string newBackupFolderPath;

                // Generate a name for the new backup folder

                if (existingBackupFolders.Length == 0)
                {
                    newBackupFolderPath = levelsPath + "_BACKUP";
                }
                else if (existingBackupFolders.Length == 1)
                {
                    newBackupFolderPath = levelsPath + "_BACKUP_2";
                }
                else
                {
                    List <int> existingNumbers = new List <int>();

                    foreach (string existingBackupFolder in existingBackupFolders)
                    {
                        int result;

                        if (int.TryParse(Path.GetFileNameWithoutExtension(existingBackupFolder).Split('_')[2], out result))
                        {
                            existingNumbers.Add(result);
                        }
                    }

                    int nextFolderNumber = existingNumbers.Max() + 1;

                    newBackupFolderPath = levelsPath + "_BACKUP_" + nextFolderNumber;
                }

                Directory.CreateDirectory(newBackupFolderPath);

                // Create all of the subdirectories
                foreach (string directory in Directory.GetDirectories(levelsPath, "*", SearchOption.AllDirectories))
                {
                    Directory.CreateDirectory(directory.Replace(levelsPath, newBackupFolderPath));
                }

                // Copy all the .prj2 files
                foreach (string file in Directory.GetFiles(levelsPath, "*.prj2", SearchOption.AllDirectories))
                {
                    if (!ProjectLevel.IsBackupFile(Path.GetFileName(file)))
                    {
                        File.Copy(file, file.Replace(levelsPath, newBackupFolderPath));
                    }
                }

                DarkMessageBox.Show(this, "Backup successfully created in:\n" + newBackupFolderPath, "Information",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                DarkMessageBox.Show(this, "Failed to create backup.\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }