我正在使用NSIS为c#中的桌面应用程序制作exe,我必须为用户写几个文件到AppData漫游文件夹
我试过下面的代码
!define ROAMING_FOLDER_ROOT "$APPDATAAPPDUMMYAPPFILES"
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:MYAPPSOURCECODEBINBookStore.sqlite"
SetOverwrite ifnewer
File "C:MYAPPSOURCECODEBINAppSettings.xml"
File "C:MYAPPSOURCECODEBINResourcesdefData.xml"
File "C:MYAPPSOURCECODEBINResourcesdummy.html"
SetOutPath "$ROAMING_FOLDER_ROOTResources"
File "C:MYAPPSOURCECODEBINResourcesappjsfile.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%AppDataRoaming
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 "$APPDATAAPPDUMMYAPPFILES"
SetOutPath "$ROAMING_FOLDER_ROOT"
SetOverwrite off
File "C:MYAPPSOURCECODEModelsBookStore.sqlite"
SetOverwrite ifnewer
File "C:MYAPPSOURCECODEBINAppSettings.xml"
File "C:MYAPPSOURCECODEBINResourcesdefData.xml"
File "C:MYAPPSOURCECODEBINResourcesdummy.html"
SetOutPath "$ROAMING_FOLDER_ROOTResources"
File "C:MYAPPSOURCECODEBINResourcesappjsfile.js"
SectionEnd