diff --git a/IDE/src/Settings.bf b/IDE/src/Settings.bf index 0786e926..0ad71d9a 100644 --- a/IDE/src/Settings.bf +++ b/IDE/src/Settings.bf @@ -22,9 +22,11 @@ namespace IDE public String mBin64Path = new .() ~ delete _; public List mLib32Paths = new .() ~ DeleteContainerAndItems!(_); public List mLib64Paths = new .() ~ DeleteContainerAndItems!(_); + public bool mManuallySet; public void Serialize(StructuredData sd) { + sd.Add("ManuallySet", mManuallySet); sd.Add("Bin32Path", mBin32Path); sd.Add("Bin64Path", mBin64Path); using (sd.CreateArray("Lib32Paths")) @@ -41,6 +43,10 @@ namespace IDE public void Deserialize(StructuredData sd) { + mManuallySet = sd.GetBool("ManuallySet"); + if ((!mManuallySet) && (!mBin64Path.IsEmpty)) + return; + sd.GetString("Bin32Path", mBin32Path); sd.GetString("Bin64Path", mBin64Path); @@ -85,6 +91,7 @@ namespace IDE public void SetDefaults() { + mManuallySet = false; #if BF_PLATFORM_WINDOWS StringView vsInfo = .(VSSupport_Find()); @@ -111,6 +118,25 @@ namespace IDE } #endif } + + bool Equals(List lhs, List rhs) + { + if (lhs.Count != rhs.Count) + return false; + for (int idx < lhs.Count) + if (lhs[idx] != rhs[idx]) + return false; + return true; + } + + public bool Equals(VSSettings vsSettings) + { + return + (Equals(mLib32Paths, vsSettings.mLib32Paths)) && + (Equals(mLib64Paths, vsSettings.mLib64Paths)) && + (mBin32Path == vsSettings.mBin32Path) && + (mBin64Path == vsSettings.mBin64Path); + } } public class DebuggerSettings diff --git a/IDE/src/ui/SettingsDialog.bf b/IDE/src/ui/SettingsDialog.bf index 6a9ca3ac..7c60909f 100644 --- a/IDE/src/ui/SettingsDialog.bf +++ b/IDE/src/ui/SettingsDialog.bf @@ -395,7 +395,18 @@ namespace IDE.ui { if (propPage == null) continue; - ApplyChanges(propPage, ref hadChanges); + bool pageHadChanges = false; + ApplyChanges(propPage, ref pageHadChanges); + if (pageHadChanges) + { + hadChanges = true; + if ((CategoryType)@propPage == .VisualStudio) + { + Settings.VSSettings defaultSettings = scope .(); + defaultSettings.SetDefaults(); + gApp.mSettings.mVSSettings.mManuallySet = !defaultSettings.Equals(gApp.mSettings.mVSSettings); + } + } } if (hadChanges) diff --git a/IDEHelper/VSSupport.cpp b/IDEHelper/VSSupport.cpp index f2bcf79c..262fc99e 100644 --- a/IDEHelper/VSSupport.cpp +++ b/IDEHelper/VSSupport.cpp @@ -58,6 +58,7 @@ struct Find_Result { wchar_t *windows_sdk_root = NULL; + wchar_t* vs_version = NULL; wchar_t *vs_exe32_path = NULL; wchar_t *vs_exe64_path = NULL; wchar_t *vs_library32_path = NULL; @@ -68,6 +69,7 @@ Find_Result find_visual_studio_and_windows_sdk(); void free_resources(Find_Result *result) { free(result->windows_sdk_root); + free(result->vs_version); free(result->vs_exe32_path); free(result->vs_exe64_path); free(result->vs_library32_path); @@ -447,8 +449,7 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res if (!success) continue; auto version_bytes = (tools_file_size.QuadPart + 1) * 2; // Warning: This multiplication by 2 presumes there is no variable-length encoding in the wchars (wacky characters in the file could betray this expectation). - wchar_t *version = (wchar_t *)malloc(version_bytes); - defer{ free(version); }; + wchar_t *version = (wchar_t *)malloc(version_bytes); auto read_result = fgetws(version, (int)version_bytes, f); if (!read_result) continue; @@ -459,17 +460,41 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res auto library32_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\lib\\x86"); auto library64_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\lib\\x64"); auto library_file = concat(library32_path, L"\\vcruntime.lib"); // @Speed: Could have library_path point to this string, with a smaller count, to save on memory flailing! + auto vs_exe64_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\bin\\Hostx64\\x64"); + auto vs_exe64_link_path = concat(vs_exe64_path, L"\\link.exe"); - if (os_file_exists(library_file)) { - result->vs_exe32_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\bin\\Hostx86\\x86"); - result->vs_exe64_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\bin\\Hostx64\\x64"); - result->vs_library32_path = library32_path; - result->vs_library64_path = library64_path; - return; + bool use = false; + if ((os_file_exists(library_file)) && (os_file_exists(vs_exe64_link_path))) + { + if (result->vs_version == NULL) + { + use = true; + } + else if (wcscmp(version, result->vs_version) > 0) + { + use = true; + } } - free(library32_path); - free(library64_path); + if (use) + { + result->vs_version = version; + result->vs_exe64_path = vs_exe64_path; + result->vs_exe32_path = concat(bstr_inst_path, L"\\VC\\Tools\\MSVC\\", version, L"\\bin\\Hostx86\\x86"); + + result->vs_library32_path = library32_path; + result->vs_library64_path = library64_path; + } + else + { + free(version); + free(vs_exe64_path); + free(library32_path); + free(library64_path); + } + + free(library_file); + free(vs_exe64_link_path); /* Ryan Saunderson said: @@ -480,6 +505,9 @@ void find_visual_studio_by_fighting_through_microsoft_craziness(Find_Result *res */ } + if (result->vs_exe64_path != NULL) + return; + // If we get here, we didn't find Visual Studio 2017. Try earlier versions. HKEY vs7_key;