FRBDK/NewProjectCreator/NewProjectCreator/ProjectCreationHelper.cs
/// <summary>
/// Renames all contained files to match the project name.  For example if the project
/// is called RaceCar, then this makes RaceCar.sln, RaceCar.csproj, and so on.
/// </summary>
/// <param name="unpackDirectory">The directory containing all of the files to rename.</param>
/// <param name="stringToReplace">What to replace - usually this is the platform name.</param>
/// <param name="stringToReplaceWith">What to replace with - this is the project name.</param>
Renames all contained files to match the project name.  For example if the project
is called RaceCar, then this makes RaceCar.sln, RaceCar.csproj, and so on.
Renames all contained files to match the project name . For example if the project is called RaceCar then this makes RaceCar . sln RaceCar . csproj and so on .
private static void RenameFiles(string unpackDirectory, string stringToReplace, string stringToReplaceWith)
        {
            List<string> filesToReplace = FileManager.GetAllFilesInDirectory(
                unpackDirectory, "csproj");
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "sln"));
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "suo"));
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "html"));
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "aspx"));
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "user"));
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "apk"));
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "java"));
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "contentproj"));
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "glux"));
            filesToReplace.AddRange(FileManager.GetAllFilesInDirectory(
                unpackDirectory, "pfx"));
            foreach (string fileName in filesToReplace)
            {
                if (fileName.Contains(stringToReplace))
                {
                    string directory = FileManager.GetDirectory(fileName);
                    string fileWithoutPath = FileManager.RemovePath(fileName);
                    fileWithoutPath = fileWithoutPath.Replace(stringToReplace, stringToReplaceWith);
                    TryMultipleTimes(() => File.Move(fileName, directory + fileWithoutPath), 5);
                }
            }
            bool shouldRepeat = true;
            List<string> directoriesAlreadyRenamed = new List<string>();
            while (shouldRepeat)
            {
                string[] directories = Directory.GetDirectories(unpackDirectory, stringToReplace + "*", SearchOption.AllDirectories);
                int i = 0;
                for (i = 0; i < directories.Length; i++)
                {
                    string fileName = directories[i];
                    if (!directoriesAlreadyRenamed.Contains(fileName) && fileName.Contains(stringToReplace))
                    {
                        int lastIndexOfWhatToReplace = fileName.LastIndexOf(stringToReplace);
                        string beforeLastIndex = fileName.Substring(0, lastIndexOfWhatToReplace);
                        string after = fileName.Substring(lastIndexOfWhatToReplace, fileName.Length - lastIndexOfWhatToReplace);
                        after = after.Replace(stringToReplace, stringToReplaceWith);
                        string targetDirectory = beforeLastIndex + after;
                        TryMultipleTimes( () => Directory.Move(fileName, targetDirectory), 5);
                        shouldRepeat = true;
                        directoriesAlreadyRenamed.Add(targetDirectory);
                        break;
                    }
                }
                if (i >= directories.Length)
                {
                    shouldRepeat = false;
                }
            }
        }
private static void RenameFiles ( string unpackDirectory , string stringToReplace , string stringToReplaceWith ) { List < string > filesToReplace = FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; filesToReplace . AddRange ( FileManager . GetAllFilesInDirectory ( unpackDirectory , " " ) ) ; foreach ( string fileName in filesToReplace ) { if ( fileName . Contains ( stringToReplace ) ) { string directory = FileManager . GetDirectory ( fileName ) ; string fileWithoutPath = FileManager . RemovePath ( fileName ) ; fileWithoutPath = fileWithoutPath . Replace ( stringToReplace , stringToReplaceWith ) ; TryMultipleTimes ( ( ) => File . Move ( fileName , directory + fileWithoutPath ) , 5 ) ; } } bool shouldRepeat = true ; List < string > directoriesAlreadyRenamed = new List < string > ( ) ; while ( shouldRepeat ) { string [ ] directories = Directory . GetDirectories ( unpackDirectory , stringToReplace + " " , SearchOption . AllDirectories ) ; int i = 0 ; for ( i = 0 ; i < directories . Length ; i ++ ) { string fileName = directories [ i ] ; if ( ! directoriesAlreadyRenamed . Contains ( fileName ) && fileName . Contains ( stringToReplace ) ) { int lastIndexOfWhatToReplace = fileName . LastIndexOf ( stringToReplace ) ; string beforeLastIndex = fileName . Substring ( 0 , lastIndexOfWhatToReplace ) ; string after = fileName . Substring ( lastIndexOfWhatToReplace , fileName . Length - lastIndexOfWhatToReplace ) ; after = after . Replace ( stringToReplace , stringToReplaceWith ) ; string targetDirectory = beforeLastIndex + after ; TryMultipleTimes ( ( ) => Directory . Move ( fileName , targetDirectory ) , 5 ) ; shouldRepeat = true ; directoriesAlreadyRenamed . Add ( targetDirectory ) ; break ; } } if ( i >= directories . Length ) { shouldRepeat = false ; } } }
Renames all contained files to match the project name.
Renames all contained files to match the project name .
unpackDirectory
string
The directory containing all of the files to rename.
The directory containing all of the files to rename .
stringToReplace
string
None
stringToReplaceWith
string
None