使用NSIS脚本将文件写入漫游文件夹
本文关键字:漫游 文件夹 文件 NSIS 脚本 使用 | 更新日期: 2023-09-27 18:18:23
我正在使用NSIS为c#中的桌面应用程序制作exe,我必须为用户写几个文件到AppData漫游文件夹
我试过下面的代码
!define ROAMING_FOLDER_ROOT "$APPDATA'APPDUMMY'APPFILES"
MessageBox MB_OK 'AppDATA FOLDER "${ROAMING_FOLDER_ROOT}"' #here i am getting the correct path of the Appdata roaming folder frm variable
Section -Additional
SetOutPath "$ROAMING_FOLDER_ROOT"
SetOverwrite off
File "C:'MYAPPSOURCECODE'BIN'BookStore.sqlite"
SetOverwrite ifnewer
File "C:'MYAPPSOURCECODE'BIN'AppSettings.xml"
File "C:'MYAPPSOURCECODE'BIN'Resources'defData.xml"
File "C:'MYAPPSOURCECODE'BIN'Resources'dummy.html"
SetOutPath "$ROAMING_FOLDER_ROOT'Resources"
File "C:'MYAPPSOURCECODE'BIN'Resources'appjsfile.js"
SectionEnd
而我试图做同样的$LocalAppData写入AppDAta本地文件夹,但我想使其可写入漫游文件夹
如果您查看您发布的代码,您会看到在MessageBox
调用中引用了${ROAMING_FOLDER_ROOT}
定义,但在调用SetOutPath
时,您引用了一个名为$ROAMING_FOLDER_ROOT
的变量,这可能会产生编译器警告。确保在访问定义时使用${}
语法!
NSIS有一个叫做shell上下文的概念,$AppData常量受此影响:
SetShellVarContext current ; Current is the default
DetailPrint AppData=$AppData ; C:'Users'%username%'AppData'Roaming
SetShellVarContext all
DetailPrint AppData=$AppData ; C:'ProgramData (This is in the All Users folder on XP)
SetShellVarContext current ; Restore it back to the default
看来,您正在使用普通的shell上下文尝试设置
SetShellVarContext current
在你得到$APPDATA之前。
Var ROAMING_FOLDER_ROOT
MessageBox MB_OK 'AppDATA FOLDER "${ROAMING_FOLDER_ROOT}"' #here i am getting the correct path of the Appdata roaming folder frm variable
Section -Additional
SetShellVarContext current
StrCpy $ROAMING_FOLDER_ROOT "$APPDATA'APPDUMMY'APPFILES"
SetOutPath "$ROAMING_FOLDER_ROOT"
SetOverwrite off
File "C:'MYAPPSOURCECODE'Models'BookStore.sqlite"
SetOverwrite ifnewer
File "C:'MYAPPSOURCECODE'BIN'AppSettings.xml"
File "C:'MYAPPSOURCECODE'BIN'Resources'defData.xml"
File "C:'MYAPPSOURCECODE'BIN'Resources'dummy.html"
SetOutPath "$ROAMING_FOLDER_ROOT'Resources"
File "C:'MYAPPSOURCECODE'BIN'Resources'appjsfile.js"
SectionEnd