2014-10-18 1 views
1

무작위로 생성 된 폴더 안에있는 $ APPDATA 폴더의 파일에 1 줄의 텍스트를 추가하려고하므로 전체 경로를 모르겠습니다. 같은 :NSIS 하위 디렉토리 내에서 APPDATA 파일에 쓰기

C:\Users\MyUser\AppData\Roaming\MyApp\RANDOM_CRAP\config.json 

RANDOM_CRAPG4F6Hh3L 같은 폴더에 대한 몇 가지 임의의 문자열처럼 보이지만.

내 옵션에는 어떤 것들이 있습니까? Search For a File 또는 Search for a File or Directory (Alternative) 중 하나를 사용해야합니까? MyApp폴더의 유일한 하위 폴더는 편집하려는 파일이 포함 된RANDOM_CRAP폴더입니다.

검색하지 않고이 파일에 액세스 할 수있는 다른 방법이 없다면 시도했지만 시도 할 수 없습니다.

Push "config.json" 
Push "$APPDATA" 
Push $0 
GetFunctionAddress $0 "myCallback" 
Exch $0 
Push "1" ; include subfolders because my desired file is in the random folder 
Push "0" ; no need the . option 
Call SearchFile 

내가 SearchFile code from this post을 복사 콜백 넣어 것보다 :

Function myCallback 
    Exch 3 
    Pop $R4 
    MessageBox MB_OK "Callback executing!" 
    MessageBox MB_OK "File is at : $R4" 
FunctionEnd 
을 나는 (대체 접근 방식) 시도했다

이것은 (나는 NSIS에 아주 새로운 해요)

SearchFile이 실행 중이며 (MessageBox를 내부에 넣었습니다.) myCallback이 호출되지 않은 것 같습니다.

감사합니다.

답변

1

당신은 알려진 파일을 찾고 및 경로에 하나의 디렉토리 만은 그때는 아마 단지 기본 FindFirst 검색 할 수있는 알 수없는 경우 :

Section 
; Create "random" folders: 
CreateDirectory "$temp\MyApp\foo" 
System::Call kernel32::GetTickCount()i.r1 ; random enough 
CreateDirectory "$temp\MyApp\bar$1" 
FileOpen $0 "$temp\MyApp\bar$1\config.json" a 
FileWrite $0 '{bogus:"data"}$\n' 
FileClose $0 
CreateDirectory "$temp\MyApp\baz" 

!include LogicLib.nsh 
; Do the actual search: 
StrCpy $9 "$temp\MyApp" ; The folder we are going to search in 
FindFirst $0 $1 "$temp\MyApp\*" 
loop: 
    StrCmp $1 "" done 
    ${If} ${FileExists} "$9\$1\config.json" 
     DetailPrint "Found: $9\$1\config.json" 
    ${EndIf} 
    FindNext $0 $1 
    Goto loop 
done: 
FindClose $0 
SectionEnd