From 6c7abcc75da8f667bf769bacff331e19d4a4dff2 Mon Sep 17 00:00:00 2001
From: David Macek <david.macek.0@gmail.com>
Date: Thu, 12 Feb 2015 13:04:15 +0100
Subject: [PATCH 3/3] Use FHS

---
 scite/src/SciTEIO.cxx    |  7 -------
 scite/win32/SciTEWin.cxx | 25 ++++++++++++++++++++++++-
 2 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/scite/src/SciTEIO.cxx b/scite/src/SciTEIO.cxx
index 34abc6e..5da0040 100644
--- a/scite/src/SciTEIO.cxx
+++ b/scite/src/SciTEIO.cxx
@@ -52,14 +52,7 @@
 #include "SciTEBase.h"
 #include "Utf8_16.h"
 
-#if defined(GTK)
 const GUI::gui_char propUserFileName[] = GUI_TEXT(".SciTEUser.properties");
-#elif defined(__APPLE__)
-const GUI::gui_char propUserFileName[] = GUI_TEXT("SciTEUser.properties");
-#else
-// Windows
-const GUI::gui_char propUserFileName[] = GUI_TEXT("SciTEUser.properties");
-#endif
 const GUI::gui_char propGlobalFileName[] = GUI_TEXT("SciTEGlobal.properties");
 const GUI::gui_char propAbbrevFileName[] = GUI_TEXT("abbrev.properties");
 
diff --git a/scite/win32/SciTEWin.cxx b/scite/win32/SciTEWin.cxx
index 16c21a8..4929de9 100644
--- a/scite/win32/SciTEWin.cxx
+++ b/scite/win32/SciTEWin.cxx
@@ -426,8 +426,29 @@ static FilePath GetSciTEPath(FilePath home) {
 			return FilePath();
 		// Remove the SciTE.exe
 		GUI::gui_char *lastSlash = wcsrchr(path, pathSepChar);
-		if (lastSlash)
+		if (lastSlash) {
 			*lastSlash = '\0';
+		}
+		// MSYS2: go to $(bindir)/../share/scite
+		lastSlash = wcsrchr(path, pathSepChar);
+		if (lastSlash) {
+			if (lastSlash - path + sizeof("share/scite") >= MAX_PATH) {
+				return FilePath(path); // don't risk overflow, return early
+			}
+			*(lastSlash++) = pathSepChar;
+			*(lastSlash++) = 's';
+			*(lastSlash++) = 'h';
+			*(lastSlash++) = 'a';
+			*(lastSlash++) = 'r';
+			*(lastSlash++) = 'e';
+			*(lastSlash++) = pathSepChar;
+			*(lastSlash++) = 's';
+			*(lastSlash++) = 'c';
+			*(lastSlash++) = 'i';
+			*(lastSlash++) = 't';
+			*(lastSlash++) = 'e';
+			*(lastSlash++) = '\0';
+		}
 		return FilePath(path);
 	}
 }
@@ -450,7 +471,10 @@
 	if (!home) {
 		home = _wgetenv(GUI_TEXT("SciTE_HOME"));
 		if (!home) {
-			home = _wgetenv(GUI_TEXT("USERPROFILE"));
+			home = _wgetenv(GUI_TEXT("HOME"));
+			if (!home) {
+				home = _wgetenv(GUI_TEXT("USERPROFILE"));
+			}
 		}
 	}
 	return GetSciTEPath(home);
-- 
2.3.0
