Author: tom
Date: Wed Nov  5 09:08:22 2008
New Revision: 3282

URL: http://svn.slimdevices.com?rev=3282&root=Jive&view=rev
Log:
Bug 9823:
Description: 
User settings now in <user home>/.squeezeplay/userpath/ . Will check for old 
setting location if new isn't found. This directory is included at the end of 
the lua path.

Modified:
    7.3/trunk/squeezeplay/src/squeezeplay/share/jive/AppletManager.lua
    7.3/trunk/squeezeplay/src/squeezeplay/src/jive.c

Modified: 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/AppletManager.lua
URL: 
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/share/jive/AppletManager.lua?rev=3282&root=Jive&r1=3281&r2=3282&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/AppletManager.lua 
(original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/share/jive/AppletManager.lua Wed Nov  
5 09:08:22 2008
@@ -18,7 +18,7 @@
 --]]
 
 -- stuff we use
-local package, pairs, error, load, loadfile, io, assert = package, pairs, 
error, load, loadfile, io, assert
+local package, pairs, error, load, loadfile, io, assert, os = package, pairs, 
error, load, loadfile, io, assert, os
 local setfenv, getfenv, require, pcall, unpack = setfenv, getfenv, require, 
pcall, unpack
 local tostring, tonumber, collectgarbage = tostring, tonumber, collectgarbage
 
@@ -76,9 +76,37 @@
 -- this just for the side effect of assigning our jnt local
 function __init(self, thejnt)
        jnt = thejnt
+       _initUserpathdir()
        return oo.rawnew(self, {})
 end
 
+
+function _initUserpathdir()
+       local homedir
+       local home = os.getenv("HOME")
+       if home then
+               homedir = home
+       else
+               local homepath = os.getenv("HOMEPATH")
+               homedir = homepath
+       end
+       
+       
+       local userdir = homedir .. "/.squeezeplay"
+       _userpathdir = userdir .. "/userpath"
+       _mkdirIfMissing(userdir)
+       _mkdirIfMissing(_userpathdir)
+       
+end
+
+function _mkdirIfMissing(dir)
+       if lfs.attributes(dir) == nil then
+               local created, err = lfs.mkdir(dir)
+               if not created then
+                       error (string.format ("error creating dir '%s' (%s)", 
dir, err))
+               end     
+       end
+end
 
 -- _saveApplet
 -- creates entries for appletsDb, calculates paths and module names
@@ -98,7 +126,8 @@
                        metaFilepath = dir .. "/" .. name .. "/" .. name .. 
"Meta.lua",
                        appletFilepath = dir .. "/" .. name .. "/" .. name .. 
"Applet.lua",
                        stringsFilepath = dir .. "/" .. name .. "/" .. 
"strings.txt",
-                       settingsFilepath = dir .. "/" .. name .. "/" .. 
"settings.lua",
+                       settingsFilepath = _userpathdir .. "/" .. name .. "_" 
.. "settings.lua",
+                       settingsFilepathLegacy = dir .. "/" .. name .. "/" .. 
"settings.lua",
 
                        -- lua paths
                        appletModule = "applets." .. name .. "." .. name .. 
"Applet",
@@ -562,8 +591,8 @@
 
        local fh = io.open(entry.settingsFilepath)
        if fh == nil then
-               -- no settings file
-               return
+               -- no settings file, look for legacy settings - remove legacy 
usage after in two public releases
+               return _loadSettingsLegacy(entry)
        end
 
        local f, err = load(function() return fh:read() end)
@@ -581,6 +610,37 @@
        end
 end
 
+-- _loadSettingsLegacy - remove legacy usage after in two public releases
+--
+function _loadSettingsLegacy(entry)
+       if entry.settings then
+               -- already loaded
+               return
+       end
+
+       log:debug("_loadSettingsLegacy: ", entry.appletName)
+
+       local fh = io.open(entry.settingsFilepathLegacy)
+       if fh == nil then
+               -- no settings file
+               return
+       end
+
+       local f, err = load(function() return fh:read() end)
+       fh:close()
+
+       if not f then
+               log:error("Error reading ", entry.appletName, " legacy 
settings: ", err)
+       else
+               -- evalulate the settings in a sandbox
+               local env = {}
+               setfenv(f, env)
+               f()
+
+               entry.settings = env.settings
+       end
+end
+
 -- _getLoadPriority
 --
 function _getLoadPriority(appletDir)

Modified: 7.3/trunk/squeezeplay/src/squeezeplay/src/jive.c
URL: 
http://svn.slimdevices.com/7.3/trunk/squeezeplay/src/squeezeplay/src/jive.c?rev=3282&root=Jive&r1=3281&r2=3282&view=diff
==============================================================================
--- 7.3/trunk/squeezeplay/src/squeezeplay/src/jive.c (original)
+++ 7.3/trunk/squeezeplay/src/squeezeplay/src/jive.c Wed Nov  5 09:08:22 2008
@@ -167,7 +167,7 @@
 ** relative to this executable.
 */
 static void paths_setup(lua_State *L, char *app) {
-       char *temp, *binpath, *path;
+       char *temp, *binpath, *path, *userpath;
 
        DEBUG_TRACE("Setting up paths");
 
@@ -184,6 +184,11 @@
        path = malloc(PATH_MAX+1);
        if (!path) {
                l_message("Error", "malloc failure for path");
+               exit(-1);
+       }
+       userpath = malloc(PATH_MAX+1);
+       if (!userpath) {
+               l_message("Error", "malloc failure for userpath");
                exit(-1);
        }
 
@@ -206,6 +211,20 @@
 
        DEBUG_TRACE("* Jive binary directory: %s", binpath);
 
+    const char *home = getenv("HOME");
+       if (home != NULL) {
+               strcpy(userpath, home);
+       } else{
+           const char *homepath = getenv("HOMEPATH");
+               if (homepath != NULL) {
+                       strcpy(userpath, homepath);             
+               } else {
+                       l_message("Error", "No user home directory found, 
looking for HOME and HOMEPATH env vars...");
+                       exit(-1);
+               }
+       }
+       
+       strcat(userpath, "/.squeezeplay/userpath");
 
        // set paths in lua (package.path & package cpath)
        lua_getglobal(L, "package");
@@ -239,6 +258,11 @@
                luaL_addstring(&b, path);
                luaL_addstring(&b, DIR_SEPARATOR_STR "?.lua;");
 
+               luaL_addstring(&b, userpath);
+               luaL_addstring(&b, DIR_SEPARATOR_STR "?.lua;");
+               luaL_addstring(&b, userpath);
+               luaL_addstring(&b, DIR_SEPARATOR_STR "?" DIR_SEPARATOR_STR 
"?.lua;");
+               
                // set lua path
                luaL_pushresult(&b);
 
@@ -289,6 +313,7 @@
        free(temp);
        free(binpath);
        free(path);
+       free(userpath); 
 }
 
 

_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins

Reply via email to