Skip to content

Commit

Permalink
Enhance savegames moving logic
Browse files Browse the repository at this point in the history
- Add a signal flag to Flags
- Prompt error to users regarding savegames moving before pressing the 'SAVE' button
  • Loading branch information
VFansss committed Feb 24, 2019
1 parent 45eee5c commit 01a33c1
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 50 deletions.
9 changes: 9 additions & 0 deletions mgs2 v's fix/Flags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public enum FATALERRORSFOUND
ErrorWhileReadingFile
}

public enum SAVEGAMEMOVING
{
NoSuccesfulEvaluationPerformed = 0,
NoSavegame2Move,
BothFolderExist,
MovingPossible

};

public static class FlagExtension
{

Expand Down
69 changes: 22 additions & 47 deletions mgs2 v's fix/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,64 +250,39 @@ private void btn_settings_Click(object sender, EventArgs e)

}

// Check if savegame must be moved to the new location in "My Games", and warn the user if there are issues
// Check if savegame will be moved to the new location in "My Games", and warn the user if there are issues

string originalSavegameFolder = Application.StartupPath + "\\..\\savedata";
SAVEGAMEMOVING evaluationResult = Ocelot.SavegameMustBeMoved();

if (Directory.Exists(originalSavegameFolder))
{

if (Ocelot.IsThisDirectoryEmpty(originalSavegameFolder))
{
// Directory esist, but there aren't files inside the old savegame folder

Directory.Delete(originalSavegameFolder, true);
}

else
{
// There are files inside the old savegame directory. Must move things!

string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
Ocelot.PrintToDebugConsole("[!] SavegameMustBeMoved evaluation result is "+ evaluationResult);

string newSavegameFolder = Path.Combine(myDocumentsPath + "\\My Games\\METAL GEAR SOLID 2 SUBSTANCE");

// Check if the new location already have savegames...

if (Directory.Exists(newSavegameFolder))
{
if (Ocelot.IsThisDirectoryEmpty(newSavegameFolder))
{
// Directory esist, but there aren't files inside the old savegame folder

Directory.Delete(newSavegameFolder, true);
}

else
{
// There are savegames in the new directory. Need manual actions...

Ocelot.showMessage("savegameCantBeMoved");
if (evaluationResult == SAVEGAMEMOVING.NoSuccesfulEvaluationPerformed)
{
Ocelot.showMessage("UAC_error");

// Abort everything until user manually solve the situation
// Abort everything until user manually solve the situation

Program.ForceClosing();
Program.ForceClosing();

}
}

}
else if (evaluationResult == SAVEGAMEMOVING.MovingPossible)
{
Ocelot.showMessage("savegameWillBeMoved");
}

// Ready to move. Do a last check...
else if (evaluationResult == SAVEGAMEMOVING.BothFolderExist)
{
Ocelot.showMessage("savegameCantBeMoved");

if (!Directory.Exists(newSavegameFolder))
{
Ocelot.showMessage("savegameWillBeMoved");
// Abort everything until user manually solve the situation

Ocelot.MoveSavegamesToNewLocation();
}
Program.ForceClosing();
}

}

else
{
// The last remaining evaluation is SAVEGAMEMOVING.NoSavegame2Move, and doesn't require any warning
}

Ocelot.PrintToDebugConsole("[+] Settings has been displayed.");
Expand Down
99 changes: 96 additions & 3 deletions mgs2 v's fix/Ocelot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,33 @@ internal static void load_InternalConfig_SetTo_MGS()

}

// Move savegames from 'savedata' folder inside 'My Games', if needed

SAVEGAMEMOVING evaluationResult = Ocelot.SavegameMustBeMoved();

Ocelot.PrintToDebugConsole("[!] SavegameMustBeMoved evaluation result is " + evaluationResult);

if (evaluationResult == SAVEGAMEMOVING.NoSuccesfulEvaluationPerformed)
{
throw new Exception();

}

else if (evaluationResult == SAVEGAMEMOVING.MovingPossible)
{
MoveSavegamesToNewLocation();
}

else if (evaluationResult == SAVEGAMEMOVING.BothFolderExist)
{
throw new Exception();
}

else
{
// The last remaining evaluation is SAVEGAMEMOVING.NoSavegame2Move, and doesn't require any warning
}

// Extract SavegameLocationChanger.asi

if (File.Exists(Application.StartupPath + "\\scripts\\SavegameLocationChanger.asi"))
Expand Down Expand Up @@ -1349,8 +1376,9 @@ public static DialogResult showMessage(string code)
case "savegameWillBeMoved":

answer = MessageBox.Show(
"This version of the V's Fix will patch the game to search savedata inside 'My Documents\\My Games'" + "\n\n" +
"From now on, your save data will be storaged inside this folder:" + "\n\n"+
"From the next time you press 'SAVE', the V's Fix will patch the game to search savedata inside the 'My Games' folder!" + "\n\n" +
"This will also enhance game compatibility with modern systems!" + "\n\n"+
"Your save data will be stored inside this folder:" + "\n\n"+
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\My Games\\METAL GEAR SOLID 2 SUBSTANCE",
"Improvement incoming...", MessageBoxButtons.OK, MessageBoxIcon.Information);

Expand Down Expand Up @@ -1831,7 +1859,7 @@ public static void MoveSavegamesToNewLocation()
string oldSavedataPath = Directory.GetParent(Application.StartupPath).FullName + "\\savedata";
string newSavedataPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\My Games\\METAL GEAR SOLID 2 SUBSTANCE";

Ocelot.PrintToDebugConsole("[RETRIEVE LAST.LOG] old: "+ oldSavedataPath+" | new: "+ newSavedataPath);
Ocelot.PrintToDebugConsole("[MOVE SAVEGAME TO NEW LOCATION] old: " + oldSavedataPath+" | new: "+ newSavedataPath);

Directory.Move(oldSavedataPath, newSavedataPath);

Expand Down Expand Up @@ -2531,6 +2559,71 @@ public static bool IsThisDirectoryEmpty(string path)

}

// Check if savegames will be moved to 'My Games' directory
public static SAVEGAMEMOVING SavegameMustBeMoved()
{

try
{
string originalSavegameFolder = Application.StartupPath + "\\..\\savedata";

string myDocumentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string newSavegameFolder = Path.Combine(myDocumentsPath + "\\My Games\\METAL GEAR SOLID 2 SUBSTANCE");

// CHECK: One/both folder exist but are empty?

if (Directory.Exists(originalSavegameFolder) && IsThisDirectoryEmpty(originalSavegameFolder))
{
// Directory esist, but there aren't files inside the old savegame folder
Directory.Delete(originalSavegameFolder, true);
PrintToDebugConsole("[ SAVEGAMEMUSTBEMOVED ] " + originalSavegameFolder + " folder is empty, and has been deleted");
}

if (Directory.Exists(newSavegameFolder) && IsThisDirectoryEmpty(newSavegameFolder))
{
// Directory esist, but there aren't files inside the new savegame folder
Directory.Delete(newSavegameFolder, true);
PrintToDebugConsole("[ SAVEGAMEMUSTBEMOVED ] " + newSavegameFolder + " folder is empty, and has been deleted");
}

// Now both folder has been purged, and if they exist mean that they contain files that I can't arbitrary delete

// Check if savegame can be moved to the new location in "My Games"
if (Directory.Exists(originalSavegameFolder))
{

// There are files inside the old savegame directory. Must move things!

// Check if the new location already have savegames...

if (Directory.Exists(newSavegameFolder))
{
return SAVEGAMEMOVING.BothFolderExist;

}

return SAVEGAMEMOVING.MovingPossible;

}

else
{
return SAVEGAMEMOVING.NoSavegame2Move;
}


}
catch (Exception ex)
{
Ocelot.PrintToDebugConsole("[ EXCEPTION ] " + ex.Message);
}

// It shoudn't even come so far.
return SAVEGAMEMOVING.NoSuccesfulEvaluationPerformed;

}


}// END CLASS

}

0 comments on commit 01a33c1

Please sign in to comment.