Skip to content

Commit

Permalink
Fix crash if UserMapsFolder is invalid (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
GreepTheSheep committed Dec 25, 2021
1 parent 440c055 commit 215f8cf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/Main.as
Expand Up @@ -199,9 +199,15 @@ string changeEnumStyle(string enumName){
}

string UserMapsFolder(){
CSystemFids@ userFolder = Fids::GetUserFolder('Maps');
if (userFolder is null) return "<Invalid>";
CSystemFids@ Tree = userFolder.Trees[0];
CSystemFidFile@ Fid = Tree.Leaves[0];
return Fid.ParentFolder.ParentFolder.FullDirName;
try {
CSystemFids@ userFolder = Fids::GetUserFolder('Maps');
if (userFolder is null) return "<Invalid>";
CSystemFids@ Tree = userFolder.Trees[0];
if (Tree is null) return "<Invalid>";
CSystemFidFile@ Fid = Tree.Leaves[0];
if (Fid is null) return "<Invalid>";
return Fid.ParentFolder.ParentFolder.FullDirName;
} catch {
return "<Invalid>";
}
}
2 changes: 2 additions & 0 deletions src/Utils/MX/Methods.as
Expand Up @@ -35,6 +35,8 @@ namespace MX

void DownloadMap(int mapId)
{
if (UserMapsFolder() == "<Invalid>") return;

string downloadedMapFolder = UserMapsFolder() + "Downloaded";
string mxDLFolder = downloadedMapFolder + "/" + pluginName;
if (!IO::FolderExists(downloadedMapFolder)) IO::CreateFolder(downloadedMapFolder);
Expand Down

0 comments on commit 215f8cf

Please sign in to comment.