Skip to content

Commit

Permalink
[MapleLib] Expanding the ver. detector to prioritise Tespia clients f…
Browse files Browse the repository at this point in the history
…irst, and MapleStoryA.exe
  • Loading branch information
lastbattle committed Sep 27, 2021
1 parent ecb990c commit 2d26e26
Showing 1 changed file with 22 additions and 12 deletions.
34 changes: 22 additions & 12 deletions MapleLib/WzLib/WzFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ private static short GetMapleStoryVerFromExe(string wzFilePath, out MapleStoryLo
// <3 mechpaul
const string MAPLESTORY_EXE_NAME = "MapleStory.exe";
const string MAPLESTORYT_EXE_NAME = "MapleStoryT.exe";
const string MAPLESTORYADMIN_EXE_NAME = "MapleStoryA.exe";

FileInfo wzFileInfo = new FileInfo(wzFilePath);
if (!wzFileInfo.Exists)
Expand All @@ -349,25 +350,34 @@ private static short GetMapleStoryVerFromExe(string wzFilePath, out MapleStoryLo
}

System.IO.DirectoryInfo currentDirectory = wzFileInfo.Directory;
for (int i = 0; i < 5; i++) // just attempt 5 directories here
for (int i = 0; i < 4; i++) // just attempt 4 directories here
{
FileInfo[] msExeFileInfos = currentDirectory.GetFiles(MAPLESTORY_EXE_NAME, SearchOption.TopDirectoryOnly);
FileInfo[] msTExeFileInfos = currentDirectory.GetFiles(MAPLESTORYT_EXE_NAME, SearchOption.TopDirectoryOnly);
FileInfo[] msExeFileInfos = currentDirectory.GetFiles(MAPLESTORY_EXE_NAME, SearchOption.TopDirectoryOnly); // case insensitive
FileInfo[] msTExeFileInfos = currentDirectory.GetFiles(MAPLESTORYT_EXE_NAME, SearchOption.TopDirectoryOnly); // case insensitive
FileInfo[] msAdminExeFileInfos = currentDirectory.GetFiles(MAPLESTORYADMIN_EXE_NAME, SearchOption.TopDirectoryOnly); // case insensitive

FileInfo msExeFileInfo = null;
if (msExeFileInfos.Length > 0 && msExeFileInfos[0].Exists)
List<FileInfo> exeFileInfo = new List<FileInfo>();
if (msTExeFileInfos.Length > 0 && msTExeFileInfos[0].Exists) // prioritize MapleStoryT.exe first
{
msExeFileInfo = msExeFileInfos[0];
}
else if (msTExeFileInfos.Length > 0 && msTExeFileInfos[0].Exists)
exeFileInfo.Add(msTExeFileInfos[0]);
}
if (msAdminExeFileInfos.Length > 0 && msAdminExeFileInfos[0].Exists)
{
msExeFileInfo = msTExeFileInfos[0];
exeFileInfo.Add(msAdminExeFileInfos[0]);
}

if (msExeFileInfo != null)
if (msExeFileInfos.Length > 0 && msExeFileInfos[0].Exists)
{
exeFileInfo.Add(msExeFileInfos[0]);
}

foreach (FileInfo msExeFileInfo in exeFileInfo)
{
var versionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(currentDirectory.FullName, msExeFileInfo.FullName));

if ((versionInfo.FileMajorPart == 1 && versionInfo.FileMinorPart == 0 && versionInfo.FileBuildPart == 0)
|| (versionInfo.FileMajorPart == 0 && versionInfo.FileMinorPart == 0 && versionInfo.FileBuildPart == 0)) // older client uses 1.0.0.1
continue;

int locale = versionInfo.FileMajorPart;
MapleStoryLocalisation localeVersion = MapleStoryLocalisation.Not_Known;
if (Enum.IsDefined(typeof(MapleStoryLocalisation), locale))
Expand All @@ -378,7 +388,7 @@ private static short GetMapleStoryVerFromExe(string wzFilePath, out MapleStoryLo
var msMinorPatchVersion = versionInfo.FileBuildPart;

mapleLocaleVersion = localeVersion; // set
return (short) msVersion;
return (short)msVersion;
}
currentDirectory = currentDirectory.Parent; // check the parent folder on the next run
}
Expand Down

0 comments on commit 2d26e26

Please sign in to comment.