From 2d26e26d1d04ef4afc1fa361ae8162fbaac73694 Mon Sep 17 00:00:00 2001 From: lastbattle <4586194+lastbattle@users.noreply.github.com> Date: Mon, 27 Sep 2021 18:57:24 +0800 Subject: [PATCH] [MapleLib] Expanding the ver. detector to prioritise Tespia clients first, and MapleStoryA.exe --- MapleLib/WzLib/WzFile.cs | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/MapleLib/WzLib/WzFile.cs b/MapleLib/WzLib/WzFile.cs index c39768d3..0635eab2 100644 --- a/MapleLib/WzLib/WzFile.cs +++ b/MapleLib/WzLib/WzFile.cs @@ -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) @@ -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 exeFileInfo = new List(); + 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)) @@ -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 }