Exemplo n.º 1
0
        /// <summary>
        /// Renames the project (and its directory if renameDirectory is true).
        /// </summary>
        public void Rename(string newName, bool renameDirectory)
        {
            if (renameDirectory)
            {
                // Rename the project directory
                string newProjectPath = Path.Combine(Path.GetDirectoryName(ProjectPath), newName);

                if (Directory.Exists(ProjectPath + "_TEMP"))                 // The "_TEMP" suffix exists only when the directory name just changed letter cases
                {
                    Directory.Move(ProjectPath + "_TEMP", newProjectPath);
                }
                else
                {
                    Directory.Move(ProjectPath, newProjectPath);
                }

                EnginePath = Path.Combine(newProjectPath, EnginePath.Remove(0, ProjectPath.Length + 1));

                // Change ScriptPath / LevelsPath values of the project if they were inside the ProjectPath folder
                if (ScriptPath.StartsWith(ProjectPath))
                {
                    ScriptPath = Path.Combine(newProjectPath, ScriptPath.Remove(0, ProjectPath.Length + 1));
                }

                if (LevelsPath.StartsWith(ProjectPath))
                {
                    LevelsPath = Path.Combine(newProjectPath, LevelsPath.Remove(0, ProjectPath.Length + 1));
                }

                List <ProjectLevel> cachedLevelList = new List <ProjectLevel>();
                cachedLevelList.AddRange(Levels);

                // Remove all internal levels from the project's list to update all .prj2 files with new paths
                Levels.Clear();

                // Restore external levels, because we don't update them
                foreach (ProjectLevel projectLevel in cachedLevelList)
                {
                    if (Path.GetDirectoryName(projectLevel.FolderPath).ToLower() != LevelsPath.ToLower())
                    {
                        Levels.Add(projectLevel);
                    }
                }

                ProjectPath = newProjectPath;
            }

            Name = newName;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Replaces "$(ProjectDirectory)" with the project's .trproj folder path.
        /// <para>This is used to make projects inside TombIDE easier to read for the software.</para>
        /// </summary>
        public void DecodeProjectPaths(string trprojFilePath)
        {
            ProjectPath = Path.GetDirectoryName(trprojFilePath);

            if (!string.IsNullOrEmpty(LaunchFilePath))
            {
                LaunchFilePath = Path.Combine(ProjectPath, LaunchFilePath.Replace(@"$(ProjectDirectory)\", string.Empty));
            }

            string engineDirectory = Path.Combine(ProjectPath, "Engine");

            if (Directory.Exists(engineDirectory))
            {
                foreach (string file in Directory.GetFiles(engineDirectory, "*.exe", SearchOption.TopDirectoryOnly))
                {
                    if (((GameVersion == TRVersion.Game.TR4 || GameVersion == TRVersion.Game.TRNG) && Path.GetFileName(file).ToLower() == "tomb4.exe") ||
                        (GameVersion == TRVersion.Game.TR5Main && Path.GetFileName(file).ToLower() == "pctomb5.exe"))
                    {
                        EnginePath = engineDirectory;
                        break;
                    }
                }
            }

            // If the /Engine/ directory doesn't exist or no valid .exe file was found in that directory
            if (string.IsNullOrEmpty(EnginePath))
            {
                EnginePath = ProjectPath;
            }

            if (ScriptPath.StartsWith("$(ProjectDirectory)"))
            {
                ScriptPath = ScriptPath.Replace("$(ProjectDirectory)", ProjectPath);
            }

            if (LevelsPath.StartsWith("$(ProjectDirectory)"))
            {
                LevelsPath = LevelsPath.Replace("$(ProjectDirectory)", ProjectPath);
            }

            foreach (ProjectLevel level in Levels)
            {
                if (level.FolderPath.StartsWith("$(ProjectDirectory)"))
                {
                    level.FolderPath = level.FolderPath.Replace("$(ProjectDirectory)", ProjectPath);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Replaces the project's .trproj folder path with "$(ProjectDirectory)".
        /// <para>This is used before saving .trproj files to avoid having "hardcoded" paths.</para>
        /// </summary>
        public void EncodeProjectPaths()
        {
            LaunchFilePath = Path.Combine("$(ProjectDirectory)", Path.GetFileName(LaunchFilePath));

            if (ScriptPath.StartsWith(ProjectPath))
            {
                ScriptPath = ScriptPath.Replace(ProjectPath, "$(ProjectDirectory)");
            }

            if (LevelsPath.StartsWith(ProjectPath))
            {
                LevelsPath = LevelsPath.Replace(ProjectPath, "$(ProjectDirectory)");
            }

            foreach (ProjectLevel level in Levels)
            {
                if (level.FolderPath.StartsWith(ProjectPath))
                {
                    level.FolderPath = level.FolderPath.Replace(ProjectPath, "$(ProjectDirectory)");
                }
            }
        }