Windows installer and Path changes, fixing various issues:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 27 May 2011 09:57:53 +0000 (09:57 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 27 May 2011 09:57:53 +0000 (09:57 +0000)
* Windows installer not working for non-admin users and multiple users
* Addon scripts not installing next to user configuration
* Portable install not being taken into account in all places

The main problem was the windows installer was installing system scripts in
AppData next to the user configuration directory, which is not shared between
users. Now these are installed in ProgramFiles, and only addon scripts added
by the users go to AppData.

On all platforms, addon scripts were sometimes getting installed between
system scripts, because the scripts folder in the executable directory was
given precedence over the user configuration folder, that is no longer done
now. So addons now behave like user configuration, they are preserved even
if you download a newer build of the same blender version.

If you have an installation of 2.57 on windows, the addon install location
will not change until we do the version bump to 2.58, to avoid conflicts with
the existing the installed 2.57 version.

The old behavior of giving precedence to the local folder was done to support
portable install, where all configuration is written to the local folder. This
is now implemented differently: if and only if a "config" folder exists in the
local folder, portable install will be assumed, and files will only be written
to that local folder.

build_files/scons/tools/btools.py
release/scripts/startup/bl_operators/wm.py
release/windows/installer/00.sconsblender.nsi
source/blender/blenlib/BLI_path_util.h
source/blender/blenlib/intern/path_util.c
source/blender/editors/space_file/space_file.c
source/blender/python/intern/bpy.c
source/blender/python/intern/bpy_interface.c
source/blender/windowmanager/intern/wm_files.c
source/creator/creator.c
source/gameengine/Ketsji/KX_PythonInit.cpp

index fe6b092..accdde0 100644 (file)
@@ -615,10 +615,7 @@ def NSIS_Installer(target=None, source=None, env=None):
         else:
             if len(df)>0:
                 dp_tmp = dp[l:]
-                if dp_tmp.find('python\\lib') > -1:
-                    datafiles += "\n" +r'SetOutPath $INSTDIR'+dp[l:]+"\n\n"
-                else:
-                    datafiles += "\n"+r'SetOutPath $BLENDERHOME'+dp[l:]+"\n\n"
+                datafiles += "\n" +r'SetOutPath $INSTDIR'+dp[l:]+"\n\n"
 
                 for f in df:
                     outfile = os.path.join(dp,f)
index 53c8d56..3f4a061 100644 (file)
@@ -940,6 +940,14 @@ class WM_OT_copy_prev_settings(bpy.types.Operator):
             self.report({'ERROR'}, "Source path %r exists" % path_src)
         else:
             shutil.copytree(path_src, path_dst)
+
+            # in 2.57 and earlier windows installers, system scripts were copied
+            # into the configuration directory, don't want to copy those
+            system_script = os.path.join(path_dst, 'scripts/modules/bpy_types.py')
+            if os.path.isfile(system_script):
+                shutil.rmtree(os.path.join(path_dst, 'scripts'))
+                shutil.rmtree(os.path.join(path_dst, 'plugins'))
+
             # dont loose users work if they open the splash later.
             if bpy.data.is_saved is bpy.data.is_dirty is False:
                 bpy.ops.wm.read_homefile()
index 03f62f0..42a9b1c 100644 (file)
@@ -33,11 +33,11 @@ RequestExecutionLevel admin
 !insertmacro MUI_PAGE_COMPONENTS
     
 !insertmacro MUI_PAGE_DIRECTORY
-Page custom DataLocation DataLocationOnLeave
 !insertmacro MUI_PAGE_INSTFILES
 !insertmacro MUI_PAGE_FINISH
   
 !insertmacro MUI_UNPAGE_WELCOME
+UninstPage custom un.OptionalRemoveConfig un.OptionalRemoveConfigOnLeave
 !insertmacro MUI_UNPAGE_CONFIRM
 !insertmacro MUI_UNPAGE_INSTFILES
 !insertmacro MUI_UNPAGE_FINISH
@@ -62,7 +62,6 @@ UninstallIcon "[RELDIR]\00.installer.ico"
   LangString DESC_StartMenu ${LANG_ENGLISH} "Add shortcut items to the Start Menu. (Recommended)"
   LangString DESC_DesktopShortcut ${LANG_ENGLISH} "Add a shortcut to Blender on your desktop."
   LangString DESC_BlendRegister ${LANG_ENGLISH} "Blender can register itself with .blend files to allow double-clicking from Windows Explorer, etc."
-  LangString TEXT_IO_TITLE ${LANG_ENGLISH} "Specify User Data Location"
 ;--------------------------------
 ;Data
 
@@ -76,15 +75,15 @@ DirText "Use the field below to specify the folder where you want Blender to be
 
 SilentUnInstall normal
 
-Var BLENDERHOME
 Var SHORTVERSION ; This is blender_version_decimal() from path_util.c
+Var BLENDERCONFIG
+Var REMOVECONFIG
 
 ; Custom controls
 Var HWND
 
-Var HWND_APPDATA
-Var HWND_INSTDIR
-Var HWND_HOMEDIR
+Var HWND_KEEPCONFIG
+Var HWND_REMOVECONFIG
 
 Function .onInit
   ClearErrors
@@ -103,9 +102,12 @@ Function .onInit
 FunctionEnd
 
 Function un.onInit
+  SetShellVarContext current
+  StrCpy $BLENDERCONFIG "$APPDATA\Blender Foundation\Blender"
+  SetShellVarContext all
 FunctionEnd
 
-Function DataLocation
+Function un.OptionalRemoveConfig
   nsDialogs::Create /NOUNLOAD 1018
   Pop $HWND
   
@@ -113,45 +115,27 @@ Function DataLocation
     Abort
   ${EndIf}
   
-  ${NSD_CreateLabel} 0 0 100% 24u "Please specify where you wish to install Blender's user data files. Be aware that if you choose to use your Application Data directory, your preferences and scripts will only be accessible by the current user account."
-  ${NSD_CreateRadioButton} 0 50 100% 12u "Use Application Data directory (recommended)"
-  Pop $HWND_APPDATA
-  ${NSD_CreateRadioButton} 0 80 100% 12u "Use installation directory"
-  Pop $HWND_INSTDIR
-  ${NSD_CreateRadioButton} 0 110 100% 12u "I have defined a %HOME% variable, please install files there"
-  Pop $HWND_HOMEDIR
-  
-  ${If} ${AtMostWinME}
-    GetDlgItem $0 $HWND $HWND_APPDATA
-    EnableWindow $0 0
-    SendMessage $HWND_INSTDIR ${BM_SETCHECK} 1 0
-  ${Else}
-    SendMessage $HWND_APPDATA ${BM_SETCHECK} 1 0
-  ${EndIf}
+  ${NSD_CreateRadioButton} 0 50 100% 12u "Keep configuration files, autosaved .blend files and installed addons (recommended)"
+  Pop $HWND_KEEPCONFIG
+  ${NSD_CreateRadioButton} 0 80 100% 12u "Remove all files, including configuration files, autosaved .blend files and installed addons"
+  Pop $HWND_REMOVECONFIG
+
+  SendMessage $HWND_KEEPCONFIG ${BM_SETCHECK} 1 0
   
   nsDialogs::Show
   
 FunctionEnd
 
-Function DataLocationOnLeave
-  ${NSD_GetState} $HWND_APPDATA $R0
+Function un.OptionalRemoveConfigOnLeave
+  ${NSD_GetState} $HWND_REMOVECONFIG $R0
   ${If} $R0 == "1"
-    SetShellVarContext current
-    StrCpy $BLENDERHOME "$APPDATA\Blender Foundation\Blender"
-    SetShellVarContext all
+    StrCpy $REMOVECONFIG "1"
   ${Else}
-    ${NSD_GetState} $HWND_INSTDIR $R0
-    ${If} $R0 == "1"
-      StrCpy $BLENDERHOME $INSTDIR
-    ${Else}
-      ${NSD_GetState} $HWND_HOMEDIR $R0
-      ${If} $R0 == "1"
-        ReadEnvStr $BLENDERHOME "HOME"
-      ${EndIf}
-    ${EndIf}
+    StrCpy $REMOVECONFIG "0"
   ${EndIf}
 FunctionEnd
 
+
 Section "Blender [VERSION] (required)" InstallFiles
   SectionIn RO
 
@@ -160,7 +144,7 @@ Section "Blender [VERSION] (required)" InstallFiles
   ; The contents of Blender installation root dir
   [ROOTDIRCONTS]
   
-  ; All datafiles (python, scripts, config)
+  ; All datafiles (python, scripts, datafiles)
   [DODATAFILES]
   
   SetOutPath $INSTDIR
@@ -169,7 +153,6 @@ Section "Blender [VERSION] (required)" InstallFiles
   ${EndIf}
   ; Write the installation path into the registry
   WriteRegStr HKLM "SOFTWARE\BlenderFoundation" "Install_Dir" "$INSTDIR"
-  WriteRegStr HKLM "SOFTWARE\BlenderFoundation" "ConfigData_Dir" "$BLENDERHOME"
   WriteRegStr HKLM "SOFTWARE\BlenderFoundation" "ShortVersion" "[SHORTVERSION]"
   ; Write the uninstall keys for Windows
   WriteRegStr   HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Blender" "DisplayName" "Blender"
@@ -204,7 +187,7 @@ Section "Open .blend files with Blender" BlendRegister
   ExecWait '"$INSTDIR\blender.exe" -r'
 SectionEnd
 
-UninstallText "This will uninstall Blender [VERSION], and all installed files. Before continuing make sure you have created backup of all the files you may want to keep: startup.blend, bookmarks.txt, recent-files.txt. Hit 'Uninstall' to continue."
+UninstallText "This will uninstall Blender [VERSION], and all installed files. Hit 'Uninstall' to continue."
 
 Section "Uninstall"
   ; Remove registry keys
@@ -212,7 +195,6 @@ Section "Uninstall"
     SetRegView 64
   ${EndIf}
   
-  ReadRegStr $BLENDERHOME HKLM "SOFTWARE\BlenderFoundation" "ConfigData_Dir"
   ReadRegStr $SHORTVERSION HKLM "SOFTWARE\BlenderFoundation" "ShortVersion"
   DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Blender"
   DeleteRegKey HKLM "SOFTWARE\BlenderFoundation"
@@ -226,21 +208,10 @@ Section "Uninstall"
 
   Delete "$INSTDIR\uninstall.exe"
 
-  MessageBox MB_YESNO "Recursively erase contents of $BLENDERHOME\$SHORTVERSION\scripts? NOTE: This includes all installed scripts and *any* file and directory you have manually created, installed later or copied. This also including .blend files." IDNO NextNoScriptRemove
-  RMDir /r "$BLENDERHOME\$SHORTVERSION\scripts"
-NextNoScriptRemove:
-  MessageBox MB_YESNO "Recursively erase contents from $BLENDERHOME\$SHORTVERSION\config? NOTE: This includes your startup.blend, bookmarks and any other file and directory you may have created in that directory" IDNO NextNoConfigRemove
-  RMDir /r "$BLENDERHOME\$SHORTVERSION\config"
-NextNoConfigRemove:
-  MessageBox MB_YESNO "Recursively erase contents from $BLENDERHOME\$SHORTVERSION\plugins? NOTE: This includes files and subdirectories in this directory" IDNO NextNoPluginRemove
-  RMDir /r "$BLENDERHOME\$SHORTVERSION\plugins"
-NextNoPluginRemove:
-  ; Try to remove dirs, but leave them if they contain anything
-  RMDir "$BLENDERHOME\$SHORTVERSION\plugins"
-  RMDir "$BLENDERHOME\$SHORTVERSION\config"
-  RMDir "$BLENDERHOME\$SHORTVERSION\scripts"
-  RMDir "$BLENDERHOME\$SHORTVERSION"
-  RMDir "$BLENDERHOME"
+  ${If} $REMOVECONFIG == "1"
+    RMDir /r "$BLENDERCONFIG\$SHORTVERSION"
+  ${Endif}
+
   ; Remove shortcuts
   Delete "$SMPROGRAMS\Blender Foundation\Blender\*.*"
   Delete "$DESKTOP\Blender.lnk"
index 360cd1e..81fc8a5 100644 (file)
@@ -50,11 +50,7 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check);
 /* folder_id */
 
 /* general, will find based on user/local/system priority */
-#define BLENDER_CONFIG                         1
 #define BLENDER_DATAFILES                      2
-#define BLENDER_SCRIPTS                                3
-#define BLENDER_PLUGINS                                4
-#define BLENDER_PYTHON                         5
 
 /* user-specific */
 #define BLENDER_USER_CONFIG                    31
@@ -64,7 +60,6 @@ char *BLI_get_folder_version(const int id, const int ver, const int do_check);
 #define BLENDER_USER_AUTOSAVE          35
 
 /* system */
-#define BLENDER_SYSTEM_CONFIG          51      /* optional */
 #define BLENDER_SYSTEM_DATAFILES       52
 #define BLENDER_SYSTEM_SCRIPTS         53
 #define BLENDER_SYSTEM_PLUGINS         54
index 47e50e3..5056961 100644 (file)
@@ -902,10 +902,23 @@ static int get_path_local(char *targetpath, const char *folder_name, const char
        return 0;
 }
 
+static int is_portable_install(void)
+{
+       /* detect portable install by the existance of config folder */
+       const int ver= BLENDER_VERSION;
+       char path[FILE_MAX];
+
+       return get_path_local(path, "config", NULL, ver);
+}
+
 static int get_path_user(char *targetpath, const char *folder_name, const char *subfolder_name, const char *envvar, const int ver)
 {
        char user_path[FILE_MAX];
        const char *user_base_path;
+
+       /* for portable install, user path is always local */
+       if (is_portable_install())
+               return get_path_local(targetpath, folder_name, subfolder_name, ver);
        
        user_path[0] = '\0';
 
@@ -1011,6 +1024,26 @@ static int get_path_system(char *targetpath, const char *folder_name, const char
        }
 }
 
+#if defined(WIN32) && BLENDER_VERSION < 258
+
+static int path_have_257_script_install(void)
+{
+       const int ver= BLENDER_VERSION;
+       char path[FILE_MAX] = "";
+       char system_pyfile[FILE_MAX];
+
+       if (get_path_user(path, "scripts", NULL, "BLENDER_USER_SCRIPTS", ver)) {
+               BLI_join_dirfile(system_pyfile, sizeof(system_pyfile), path, "modules/bpy_types.py");
+
+               if (BLI_exists(system_pyfile))
+                       return 1;
+       }
+
+       return 0;
+}
+
+#endif
+
 /* get a folder out of the 'folder_id' presets for paths */
 /* returns the path if found, NULL string if not */
 char *BLI_get_folder(int folder_id, const char *subfolder)
@@ -1020,13 +1053,12 @@ char *BLI_get_folder(int folder_id, const char *subfolder)
        
        switch (folder_id) {
                case BLENDER_DATAFILES:         /* general case */
-                       if (get_path_local(path, "datafiles", subfolder, ver)) break;
                        if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break;
+                       if (get_path_local(path, "datafiles", subfolder, ver)) break;
                        if (get_path_system(path, "datafiles", subfolder, "BLENDER_SYSTEM_DATAFILES", ver)) break;
                        return NULL;
                        
                case BLENDER_USER_DATAFILES:
-                       if (get_path_local(path, "datafiles", subfolder, ver)) break;
                        if (get_path_user(path, "datafiles", subfolder, "BLENDER_USER_DATAFILES", ver)) break;
                        return NULL;
                        
@@ -1036,35 +1068,28 @@ char *BLI_get_folder(int folder_id, const char *subfolder)
                        return NULL;
                        
                case BLENDER_USER_AUTOSAVE:
-                       if (get_path_local(path, "autosave", subfolder, ver)) break;
                        if (get_path_user(path, "autosave", subfolder, "BLENDER_USER_DATAFILES", ver))  break;
                        return NULL;
 
-               case BLENDER_CONFIG:            /* general case */
-                       if (get_path_local(path, "config", subfolder, ver)) break;
-                       if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG", ver)) break;
-                       if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG", ver)) break;
-                       return NULL;
-                       
                case BLENDER_USER_CONFIG:
-                       if (get_path_local(path, "config", subfolder, ver)) break;
                        if (get_path_user(path, "config", subfolder, "BLENDER_USER_CONFIG", ver)) break;
                        return NULL;
                        
-               case BLENDER_SYSTEM_CONFIG:
-                       if (get_path_local(path, "config", subfolder, ver)) break;
-                       if (get_path_system(path, "config", subfolder, "BLENDER_SYSTEM_CONFIG", ver)) break;
-                       return NULL;
-                       
-               case BLENDER_SCRIPTS:           /* general case */
-                       if (get_path_local(path, "scripts", subfolder, ver)) break;
-                       if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break;
-                       if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS", ver)) break;
-                       return NULL;
-                       
                case BLENDER_USER_SCRIPTS:
-                       if (get_path_local(path, "scripts", subfolder, ver)) break;
-                       if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break;
+#if defined(WIN32) && BLENDER_VERSION < 258
+                       /* if we have a 2.57 installation, then we may have system script
+                        * files in the user configuration folder. avoid using that folder
+                        * if they are there, until the version gets bumped to 2.58, so
+                        * we can be sure that folder only has addons etc. */
+                       if (path_have_257_script_install()) {
+                               if (get_path_local(path, "scripts", subfolder, ver)) break;
+                       }
+                       else
+#endif
+                       {
+                               if (get_path_user(path, "scripts", subfolder, "BLENDER_USER_SCRIPTS", ver)) break;
+                       }
+
                        return NULL;
                        
                case BLENDER_SYSTEM_SCRIPTS:
@@ -1072,11 +1097,6 @@ char *BLI_get_folder(int folder_id, const char *subfolder)
                        if (get_path_system(path, "scripts", subfolder, "BLENDER_SYSTEM_SCRIPTS", ver)) break;
                        return NULL;
                        
-               case BLENDER_PYTHON:            /* general case */
-                       if (get_path_local(path, "python", subfolder, ver)) break;
-                       if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON", ver)) break;
-                       return NULL;
-                       
                case BLENDER_SYSTEM_PYTHON:
                        if (get_path_local(path, "python", subfolder, ver)) break;
                        if (get_path_system(path, "python", subfolder, "BLENDER_SYSTEM_PYTHON", ver)) break;
index ec0d980..18270bf 100644 (file)
@@ -606,7 +606,7 @@ void ED_spacetype_file(void)
 
 void ED_file_init(void)
 {
-       char *cfgdir = BLI_get_folder(BLENDER_CONFIG, NULL);
+       char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
        
        fsmenu_read_system(fsmenu_get());
 
index afafc9b..450151e 100644 (file)
@@ -239,7 +239,7 @@ void BPy_init_modules( void )
        PyObject *mod;
 
        /* Needs to be first since this dir is needed for future modules */
-       char *modpath= BLI_get_folder(BLENDER_SCRIPTS, "modules");
+       char *modpath= BLI_get_folder(BLENDER_SYSTEM_SCRIPTS, "modules");
        if(modpath) {
                // printf("bpy: found module path '%s'.\n", modpath);
                PyObject *sys_path= PySys_GetObject("path"); /* borrow */
index acd2388..e6f4c57 100644 (file)
@@ -197,7 +197,7 @@ void BPY_python_start(int argc, const char **argv)
        PyImport_ExtendInittab(bpy_internal_modules);
 
        /* allow to use our own included python */
-       PyC_SetHomePath(BLI_get_folder(BLENDER_PYTHON, NULL));
+       PyC_SetHomePath(BLI_get_folder(BLENDER_SYSTEM_PYTHON, NULL));
 
        /* Python 3.2 now looks for '2.57/python/include/python3.2d/pyconfig.h' to parse
         * from the 'sysconfig' module which is used by 'site', so for now disable site.
index ea77fca..1f005ba 100644 (file)
@@ -544,7 +544,7 @@ void WM_read_history(void)
        struct RecentFile *recent;
        char *line;
        int num;
-       char *cfgdir = BLI_get_folder(BLENDER_CONFIG, NULL);
+       char *cfgdir = BLI_get_folder(BLENDER_USER_CONFIG, NULL);
 
        if (!cfgdir) return;
 
index 0c29c80..016c461 100644 (file)
@@ -314,7 +314,6 @@ static int print_help(int UNUSED(argc), const char **UNUSED(argv), void *data)
 
        printf ("\nEnvironment Variables:\n");
        printf ("  $BLENDER_USER_CONFIG      Directory for user configuration files.\n");
-       printf ("  $BLENDER_SYSTEM_CONFIG    Directory for system wide configuration files.\n");
        printf ("  $BLENDER_USER_SCRIPTS     Directory for user scripts.\n");
        printf ("  $BLENDER_SYSTEM_SCRIPTS   Directory for system wide scripts.\n");
        printf ("  $BLENDER_USER_DATAFILES   Directory for user data files (icons, translations, ..).\n");
@@ -1087,7 +1086,6 @@ static void setupArguments(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
        BLI_argsAdd(ba, 1, NULL, "--factory-startup", "\n\tSkip reading the "STRINGIFY(BLENDER_STARTUP_FILE)" in the users home directory", set_factory_startup, NULL);
 
        /* TODO, add user env vars? */
-       BLI_argsAdd(ba, 1, NULL, "--env-system-config",         "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_CONFIG)" environment variable", set_env, NULL);
        BLI_argsAdd(ba, 1, NULL, "--env-system-datafiles",      "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_DATAFILES)" environment variable", set_env, NULL);
        BLI_argsAdd(ba, 1, NULL, "--env-system-scripts",        "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_SCRIPTS)" environment variable", set_env, NULL);
        BLI_argsAdd(ba, 1, NULL, "--env-system-plugins",        "\n\tSet the "STRINGIFY_ARG(BLENDER_SYSTEM_PLUGINS)" environment variable", set_env, NULL);
index a373899..c8a6ae5 100644 (file)
@@ -1781,7 +1781,7 @@ PyObject* initGamePlayerPythonScripting(const STR_String& progname, TPythonSecur
        PyImport_ExtendInittab(bge_internal_modules);
 
        /* find local python installation */
-       PyC_SetHomePath(BLI_get_folder(BLENDER_PYTHON, NULL));
+       PyC_SetHomePath(BLI_get_folder(BLENDER_SYSTEM_PYTHON, NULL));
 
        Py_Initialize();