From 3a8ea868fef058cc8d9a27732baeb651e8587030 Mon Sep 17 00:00:00 2001 From: M Hightower <27247790+mhightower83@users.noreply.github.com> Date: Mon, 16 Jan 2023 17:09:40 -0800 Subject: [PATCH 1/3] Fix for Windows 11 preferences.txt not found - maybe Works on Windows 10. I don't have an 11 platform to test on. Uses the prefered method for finding path to `AppData\Local` Cleaned up return with undefined fqfn2. --- tools/mkbuildoptglobals.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tools/mkbuildoptglobals.py b/tools/mkbuildoptglobals.py index 5c98ce3f7a..38877e1d7d 100644 --- a/tools/mkbuildoptglobals.py +++ b/tools/mkbuildoptglobals.py @@ -447,23 +447,22 @@ def find_preferences_txt(runtime_ide_path): # verified on Windows 10 with Arduino IDE 1.8.19 if os.path.exists(fqfn): return [fqfn, None] + # It is never simple. Arduino from the Windows APP store or the download # Windows 8 and up option will save "preferences.txt" in one location. # The downloaded Windows 7 (and up version) will put "preferences.txt" # in a different location. When both are present due to various possible - # scenarios, use the more modern. + # scenarios, give preference to the APP store. fqfn = os.path.expanduser("~\Documents\ArduinoData\preferences.txt") # Path for "Windows app" - verified on Windows 10 with Arduino IDE 1.8.19 from APP store - fqfn2 = os.path.expanduser("~\AppData\local\Arduino15\preferences.txt") + fqfn2 = os.path.normpath(os.getenv("LOCALAPPDATA") + "\Arduino15\preferences.txt") # Path for Windows 7 and up - verified on Windows 10 with Arduino IDE 1.8.19 if os.path.exists(fqfn): if os.path.exists(fqfn2): print_err("Multiple 'preferences.txt' files found:") print_err(" " + fqfn) print_err(" " + fqfn2) - return [fqfn, None] - else: - return [fqfn, fqfn2] + return [fqfn, None] elif os.path.exists(fqfn2): return [fqfn2, None] elif "Darwin" == platform_name: From c7fb78a30f4947144f166b7d511fa1f56863f942 Mon Sep 17 00:00:00 2001 From: M Hightower <27247790+mhightower83@users.noreply.github.com> Date: Tue, 17 Jan 2023 09:02:02 -0800 Subject: [PATCH 2/3] Correct the correction --- tools/mkbuildoptglobals.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/mkbuildoptglobals.py b/tools/mkbuildoptglobals.py index 38877e1d7d..b70ba08e7a 100644 --- a/tools/mkbuildoptglobals.py +++ b/tools/mkbuildoptglobals.py @@ -447,7 +447,6 @@ def find_preferences_txt(runtime_ide_path): # verified on Windows 10 with Arduino IDE 1.8.19 if os.path.exists(fqfn): return [fqfn, None] - # It is never simple. Arduino from the Windows APP store or the download # Windows 8 and up option will save "preferences.txt" in one location. # The downloaded Windows 7 (and up version) will put "preferences.txt" @@ -462,7 +461,9 @@ def find_preferences_txt(runtime_ide_path): print_err("Multiple 'preferences.txt' files found:") print_err(" " + fqfn) print_err(" " + fqfn2) - return [fqfn, None] + return [fqfn, fqfn2] + else: + return [fqfn, None] elif os.path.exists(fqfn2): return [fqfn2, None] elif "Darwin" == platform_name: From e5af060c43492c2fb90ebb9ca8e042d44f10e764 Mon Sep 17 00:00:00 2001 From: M Hightower <27247790+mhightower83@users.noreply.github.com> Date: Tue, 17 Jan 2023 21:54:36 -0800 Subject: [PATCH 3/3] Changed os.utime calls to not use unsupported fd (Windows). --- tools/mkbuildoptglobals.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/mkbuildoptglobals.py b/tools/mkbuildoptglobals.py index b70ba08e7a..53fd12dfd3 100644 --- a/tools/mkbuildoptglobals.py +++ b/tools/mkbuildoptglobals.py @@ -529,16 +529,19 @@ def check_preferences_txt(runtime_ide_path, preferences_file): def touch(fname, times=None): with open(fname, "ab") as file: - os.utime(file.fileno(), times) + file.close(); + os.utime(fname, times) def synchronous_touch(globals_h_fqfn, commonhfile_fqfn): global debug_enabled # touch both files with the same timestamp touch(globals_h_fqfn) with open(globals_h_fqfn, "rb") as file: - ts = os.stat(file.fileno()) - with open(commonhfile_fqfn, "ab") as file2: - os.utime(file2.fileno(), ns=(ts.st_atime_ns, ts.st_mtime_ns)) + file.close() + with open(commonhfile_fqfn, "ab") as file2: + file2.close() + ts = os.stat(globals_h_fqfn) + os.utime(commonhfile_fqfn, ns=(ts.st_atime_ns, ts.st_mtime_ns)) if debug_enabled: print_dbg("After synchronous_touch")