我正在使用NSIS为c#中的桌面应用程序创建exe,我必须为用户将少量文件写入AppData Roaming文件夹
我尝试了以下代码
!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 Local文件夹进行写入,但我想让它可写入漫游文件夹
答案 0 :(得分:1)
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
答案 1 :(得分:1)
如果您查看发布的代码,可以在${ROAMING_FOLDER_ROOT}
调用中看到您引用SetOutPath
定义,但在调用$ROAMING_FOLDER_ROOT
时,您引用了一个名为${}
的变量这可能会产生编译器警告。访问定义时,请确保使用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
语法!
NSIS有一个名为shell上下文的概念,$ AppData常量受此影响:
{{1}}