@@ -520,12 +520,14 @@ public static void InstallPatches(string patch, string name)
520520 // Append the location to the active path
521521 string _RenameLocation = GetDataLocation ( Literal . CoreReplace ( _Rename [ 0 ] ) ) ,
522522
523- // Define the final path name
524- newName = Paths . ReplaceFilename ( Literal . CoreReplace ( _Rename [ 0 ] ) , Path . GetFileName ( _Rename [ 1 ] ) ) ;
523+ // Define the final path names
524+ newName = Paths . ReplaceFilename ( _RenameLocation , Path . GetFileName ( _Rename [ 1 ] ) ) ,
525+ rBackup = $ "{ _RenameLocation } _back";
525526
526527 BackupFile ( _RenameLocation ) ; // Backup the pre-renamed file no matter what
527528
528529 if ( ! File . Exists ( newName ) ) File . Move ( _RenameLocation , newName ) ;
530+ else if ( newName == rBackup && File . Exists ( rBackup ) ) File . Delete ( _RenameLocation ) ;
529531 break ;
530532
531533 // Renames all files with the specified extension to the new extension.
@@ -538,8 +540,13 @@ public static void InstallPatches(string patch, string name)
538540
539541 // Iterate through all files by extension
540542 foreach ( string file in Directory . GetFiles ( _RenameExtensionLocation , _RenameByExtension [ 1 ] , SearchOption . TopDirectoryOnly ) ) {
541- string newExtension = Path . ChangeExtension ( file , _RenameByExtension [ 2 ] ) ;
543+ // Get new file name
544+ string newExtension = Path . ChangeExtension ( file , _RenameByExtension [ 2 ] ) ,
545+ rbeBackup = $ "{ file } _back";
546+
542547 if ( ! File . Exists ( newExtension ) ) File . Move ( file , newExtension ) ;
548+ else if ( newExtension == rbeBackup && File . Exists ( rbeBackup ) )
549+ File . Delete ( file ) ;
543550 }
544551 break ;
545552
@@ -598,6 +605,8 @@ public static void InstallPatches(string patch, string name)
598605 case string x when x . StartsWith ( "ParameterAdd(" ) :
599606 // Deserialise 'ParameterAdd' parameter
600607 string [ ] _ParameterAdd = Lua . DeserialiseParameterList ( "ParameterAdd" , line , false ) ;
608+
609+ // Append the location to the active path
601610 string _ParameterAddLocation = GetDataLocation ( Literal . CoreReplace ( _ParameterAdd [ 0 ] ) ) ;
602611
603612 // Add parameters in a single file.
@@ -617,6 +626,8 @@ public static void InstallPatches(string patch, string name)
617626 case string x when x . StartsWith ( "ParameterEdit(" ) :
618627 // Deserialise 'ParameterEdit' parameter
619628 string [ ] _ParameterEdit = Lua . DeserialiseParameterList ( "ParameterEdit" , line , false ) ;
629+
630+ // Append the location to the active path
620631 string _ParameterEditLocation = GetDataLocation ( Literal . CoreReplace ( _ParameterEdit [ 0 ] ) ) ;
621632
622633 // Edit parameters in a single file.
@@ -637,6 +648,8 @@ public static void InstallPatches(string patch, string name)
637648 case string x when x . StartsWith ( "ParameterErase(" ) :
638649 // Deserialise 'ParameterErase' parameter
639650 string [ ] _ParameterErase = Lua . DeserialiseParameterList ( "ParameterErase" , line , false ) ;
651+
652+ // Append the location to the active path
640653 string _ParameterEraseLocation = GetDataLocation ( Literal . CoreReplace ( _ParameterErase [ 0 ] ) ) ;
641654
642655 // Edit parameters in a single file.
@@ -656,6 +669,8 @@ public static void InstallPatches(string patch, string name)
656669 case string x when x . StartsWith ( "ParameterRename(" ) :
657670 // Deserialise 'ParameterRename' parameter
658671 string [ ] _ParameterRename = Lua . DeserialiseParameterList ( "ParameterRename" , line , false ) ;
672+
673+ // Append the location to the active path
659674 string _ParameterRenameLocation = GetDataLocation ( Literal . CoreReplace ( _ParameterRename [ 0 ] ) ) ;
660675
661676 // Edit parameters in a single file.
@@ -675,6 +690,8 @@ public static void InstallPatches(string patch, string name)
675690 case string x when x . StartsWith ( "TextAdd(" ) :
676691 // Deserialise 'TextAdd' parameter
677692 string [ ] _TextAdd = Lua . DeserialiseParameterList ( "TextAdd" , line , false ) ;
693+
694+ // Append the location to the active path
678695 string _TextAddLocation = GetDataLocation ( Literal . CoreReplace ( _TextAdd [ 0 ] ) ) ;
679696
680697 // Edit text in a single file.
@@ -694,6 +711,8 @@ public static void InstallPatches(string patch, string name)
694711 case string x when x . StartsWith ( "TextEdit(" ) :
695712 // Deserialise 'TextEdit' parameter
696713 string [ ] _TextEdit = Lua . DeserialiseParameterList ( "TextEdit" , line , false ) ;
714+
715+ // Append the location to the active path
697716 string _TextEditLocation = GetDataLocation ( Literal . CoreReplace ( _TextEdit [ 0 ] ) ) ;
698717
699718 // Edit text in a single file.
@@ -713,6 +732,8 @@ public static void InstallPatches(string patch, string name)
713732 case string x when x . StartsWith ( "StringReplace(" ) :
714733 // Deserialise 'StringReplace' parameter
715734 string [ ] _StringReplace = Lua . DeserialiseParameterList ( "StringReplace" , line , false ) ;
735+
736+ // Append the location to the active path
716737 string _StringReplaceLocation = GetDataLocation ( Literal . CoreReplace ( _StringReplace [ 0 ] ) ) ;
717738
718739 // Edit text in a single file.
@@ -732,6 +753,8 @@ public static void InstallPatches(string patch, string name)
732753 case string x when x . StartsWith ( "PackageAdd(" ) :
733754 // Deserialise 'PackageAdd' parameter
734755 string [ ] _PackageAdd = Lua . DeserialiseParameterList ( "PackageAdd" , line , false ) ;
756+
757+ // Append the location to the active path
735758 string _PackageAddLocation = GetDataLocation ( Literal . CoreReplace ( _PackageAdd [ 0 ] ) ) ;
736759
737760 // Edit text in a single file.
@@ -751,6 +774,8 @@ public static void InstallPatches(string patch, string name)
751774 case string x when x . StartsWith ( "PackageEdit(" ) :
752775 // Deserialise 'PackageEdit' parameter
753776 string [ ] _PackageEdit = Lua . DeserialiseParameterList ( "PackageEdit" , line , false ) ;
777+
778+ // Append the location to the active path
754779 string _PackageEditLocation = GetDataLocation ( Literal . CoreReplace ( _PackageEdit [ 0 ] ) ) ;
755780
756781 // Edit text in a single file.
@@ -770,6 +795,8 @@ public static void InstallPatches(string patch, string name)
770795 case string x when x . StartsWith ( "PackageErase(" ) :
771796 // Deserialise 'PackageErase' parameter
772797 string [ ] _PackageErase = Lua . DeserialiseParameterList ( "PackageErase" , line , false ) ;
798+
799+ // Append the location to the active path
773800 string _PackageEraseLocation = GetDataLocation ( Literal . CoreReplace ( _PackageErase [ 0 ] ) ) ;
774801
775802 // Edit text in a single file.
@@ -1010,18 +1037,11 @@ private static void TextEdit(string location, string name, string placeholder, s
10101037 private static void StringReplace ( string location , string _string , string _new )
10111038 {
10121039 DecompileLua ( location ) ;
1013- string [ ] script = File . ReadAllLines ( location ) ;
1014- int lineCount = 0 ;
10151040
1016- foreach ( string line in script ) {
1017- if ( line . Contains ( _string ) ) {
1018- script [ lineCount ] = line . Replace ( _string , _new ) ;
1019- break ;
1020- }
1021- lineCount ++ ;
1022- }
1041+ _string = _string . Replace ( "\\ n" , Environment . NewLine ) ;
1042+ _new = _new . Replace ( "\\ n" , Environment . NewLine ) ;
10231043
1024- File . WriteAllLines ( location , script ) ;
1044+ File . WriteAllText ( location , File . ReadAllText ( location ) . Replace ( _string , _new ) ) ;
10251045 }
10261046
10271047 /// <summary>
0 commit comments