瀏覽代碼

Fix installing to system directories on linux (#256)

* Use standard directory for app state on Linux

* Ensure config directory exists before saving file
tobil4sk 11 月之前
父節點
當前提交
7c1960c47e
共有 2 個文件被更改,包括 24 次插入3 次删除
  1. 8 3
      hide/Config.hx
  2. 16 0
      hide/tools/IdeData.hx

+ 8 - 3
hide/Config.hx

@@ -74,8 +74,13 @@ class Config {
 		var fullPath = ide.getPath(path);
 		if( Reflect.fields(source).length == 0 )
 			try sys.FileSystem.deleteFile(fullPath) catch( e : Dynamic ) {};
-		else
+		else {
+			var directory = haxe.io.Path.directory(fullPath);
+			if( !sys.FileSystem.exists(directory) ) {
+				sys.FileSystem.createDirectory(directory);
+			}
 			sys.io.File.saveContent(fullPath, ide.toJSON(source));
+		}
 	}
 
 	public function sync() {
@@ -157,7 +162,7 @@ class Config {
 			Sys.exit(-1);
 		}
 
-		var userGlobals = loadConfig(new Config(defaults), hidePath + "/props.json");
+		var userGlobals = loadConfig(new Config(defaults), Ide.inst.userStatePath + "/props.json");
 
 		if( userGlobals.source.hide == null )
 			userGlobals.source.hide = {
@@ -208,4 +213,4 @@ class Config {
 		return allowSave ? parent : new Config(parent);
 	}
 
-}
+}

+ 16 - 0
hide/tools/IdeData.hx

@@ -6,6 +6,7 @@ class IdeData {
 	public var projectDir(get,never) : String;
 	public var resourceDir(get,never) : String;
 	public var appPath(get, null): String;
+	public var userStatePath(get, null): String;
 	public var database : cdb.Database = new cdb.Database();
 	public var fileWatcher : hide.tools.FileWatcher;
 
@@ -111,6 +112,21 @@ class IdeData {
 		return appPath = hidePath;
 	}
 
+	function get_userStatePath() {
+		var appPath = appPath;
+		if( sys.FileSystem.exists(appPath + "/props.json") ) {
+			return appPath;
+		}
+		if( Sys.systemName() ==  "Linux" ) {
+			var statePath = Sys.getEnv("XDG_STATE_HOME");
+			if( statePath == null ) {
+				statePath = Sys.getEnv("HOME") + "/.local/state";
+			}
+			return statePath + "/hide";
+		}
+		return appPath;
+	}
+
 	public function makeRelative( path : String ) {
 		path = path.split("\\").join("/");
 		if( StringTools.startsWith(path.toLowerCase(), resourceDir.toLowerCase()+"/") )