К сожалению тоже ничего не меняет. Как были файлы readonly так и остались, пока полный путь вручную не прописать.@Xenium, чтобы работало надо задавать:
Exec(ExpandConstant('{cmd}'), ExpandConstant('/C attrib -R -H "appdir\*.*" /s /d'), '', SW_SHOW, ewWaitUntilTerminated, ResultCode);
Или задать значение appdir уже сразу:
appdir := ExpandConstant('{app}');
function GetFileAttributes(lpFileName: PAnsiChar): DWORD;
external 'GetFileAttributesA@kernel32.dll stdcall';
function SetFileAttributes(lpFileName: PAnsiChar;
dwFileAttributes: DWORD): BOOL;
external 'SetFileAttributesA@kernel32.dll stdcall';
procedure RemoveReadOnly(FileName : String);
var
Attr : DWord;
begin
Attr := GetFileAttributes(FileName);
if (Attr and 1) = 1 then
begin
Attr := Attr -1;
SetFileAttributes(FileName,Attr);
end;
end;
SvfList := TStringList.Create;
SvfList.LoadFromFile(ExpandConstant('{app}\INSTALL.LOG'));
for i := 0 to SvfList.Count-1 do
RemoveReadOnly(ExpandConstant('{app}\'+SvfList[i]));
DeleteFile(ExpandConstant('{app}\'+SvfList[i]));
К сожалению тоже ничего не меняет.
Exec('attrib', ExpandConstant(' -h -s -r /D "{app}\*.*"'),'', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Exec('attrib', ExpandConstant(' -h -s -r "{app}\*.*"'),'', SW_HIDE, ewWaitUntilTerminated, ResultCode);
Так сработало, спасибо)потом выполняете приведенный пример очистки.Код:Exec('attrib', ExpandConstant(' -h -s -r /D "{app}\*.*"'),'', SW_HIDE, ewWaitUntilTerminated, ResultCode); Exec('attrib', ExpandConstant(' -h -s -r "{app}\*.*"'),'', SW_HIDE, ewWaitUntilTerminated, ResultCode);
@Echo Off
SetLocal EnableDelayedExpansion
Set DataRoot=%~dp0
Set OutFile=filelist.list
For /F "delims=" %%A In ('Dir "%DataRoot%\*.*" /B /S /A-D 2^>nul') Do (
Set str=%%A
Set stra=!str:%~dp0=!
Echo !stra!>>"%OutFile%")
Pause
//Удаление файлов по списку - start
procedure ScanDir(SearchPath: String);
var
FindRec: TFindRec;
begin
if FindFirst(ExpandConstant(AddBackslash(SearchPath)+'*.*'), FindRec) then
begin
try
repeat
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then
begin
if (FindRec.Name<>'.') and (FindRec.Name<>'..') then
begin
List.Add(AddBackslash(SearchPath) + FindRec.Name + '\');
ScanDir(AddBackslash(SearchPath) + FindRec.Name + '\');
end;
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
end;
function GetFileAttributes(lpFileName: PAnsiChar): DWORD;
external 'GetFileAttributesA@kernel32.dll stdcall';
function SetFileAttributes(lpFileName: PAnsiChar; dwFileAttributes: DWORD): BOOL;
external 'SetFileAttributesA@kernel32.dll stdcall';
procedure RemoveReadOnly(FileName : String);
var
Attr : DWord;
begin
Attr := GetFileAttributes(FileName);
if (Attr and 1) = 1 then
begin
Attr := Attr -1;
SetFileAttributes(FileName,Attr);
end;
end;
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
i: integer;
z: integer;
n: integer;
SvfList: TStringlist;
Checked: TStringlist;
ResultCode: Integer;
begin
if (CurUninstallStep = usUninstall) then
begin
// fix "read-only" status of only files for
SvfList := TStringList.Create;
SvfList.LoadFromFile(ExpandConstant('{app}\Uninstall\filelist.list'))
for i := 0 to SvfList.Count-1 do
RemoveReadOnly(ExpandConstant('{app}\'+SvfList[i]));
begin
for z := 0 to SvfList.Count-1 do
DeleteFile(ExpandConstant('{app}\'+SvfList[z]));
// delete empty folders
begin
List := TStringList.Create;
ScanDir(ExpandConstant('{app}\'));
if (List.Count<>0) then
begin
for n:= List.Count-1 downto 0 do
RemoveDir(List[n]);
end;
List.Free;
DeleteFile(ExpandConstant('{app}\Uninstall\filelist.list'))
end;
end;
end
end;
//Удаление файлов по списку - end
есть косяк с BAT, в одной игре, файлы которой сканировал, был в папке файл COW!.wav. Так вот этот BAT восклицательный знак, возможно и какие-то другие подобные, не видит и записывает просто как COW.wav@Formular и для всех интересующихся данной проблемой)
1- Необходимо создать .bat файл со следующим содержимым:
- Кидаем батник в папку с нашими файлами(которые потом будут устанавливаться на ПК юзеру)Код:@Echo Off SetLocal EnableDelayedExpansion Set DataRoot=%~dp0 Set OutFile=filelist.list For /F "delims=" %%A In ('Dir "%DataRoot%\*.*" /B /S /A-D 2^>nul') Do ( Set str=%%A Set stra=!str:%~dp0=! Echo !stra!>>"%OutFile%") Pause
- Запускаем батник, после чего он создаст файл filelist.list
- filelist.list - пакуем в наши архивы
Далее код, который использую я (спасибо всем, кто откликнулся ранее)
Обращаю внимание, что ЛОГ создаем батником, а не средствами Inno Setup (т.к инно пропускает некоторые файлы, что в итоге выливается в проблему при удалении - не все файлы будут удалены)Код://Удаление файлов по списку - start procedure ScanDir(SearchPath: String); var FindRec: TFindRec; begin if FindFirst(ExpandConstant(AddBackslash(SearchPath)+'*.*'), FindRec) then begin try repeat if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then begin if (FindRec.Name<>'.') and (FindRec.Name<>'..') then begin List.Add(AddBackslash(SearchPath) + FindRec.Name + '\'); ScanDir(AddBackslash(SearchPath) + FindRec.Name + '\'); end; end; until not FindNext(FindRec); finally FindClose(FindRec); end; end; end; function GetFileAttributes(lpFileName: PAnsiChar): DWORD; external 'GetFileAttributesA@kernel32.dll stdcall'; function SetFileAttributes(lpFileName: PAnsiChar; dwFileAttributes: DWORD): BOOL; external 'SetFileAttributesA@kernel32.dll stdcall'; procedure RemoveReadOnly(FileName : String); var Attr : DWord; begin Attr := GetFileAttributes(FileName); if (Attr and 1) = 1 then begin Attr := Attr -1; SetFileAttributes(FileName,Attr); end; end; procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep); var i: integer; z: integer; n: integer; SvfList: TStringlist; Checked: TStringlist; ResultCode: Integer; begin if (CurUninstallStep = usUninstall) then begin // fix "read-only" status of only files for SvfList := TStringList.Create; SvfList.LoadFromFile(ExpandConstant('{app}\Uninstall\filelist.list')) for i := 0 to SvfList.Count-1 do RemoveReadOnly(ExpandConstant('{app}\'+SvfList[i])); begin for z := 0 to SvfList.Count-1 do DeleteFile(ExpandConstant('{app}\'+SvfList[z])); // delete empty folders begin List := TStringList.Create; ScanDir(ExpandConstant('{app}\')); if (List.Count<>0) then begin for n:= List.Count-1 downto 0 do RemoveDir(List[n]); end; List.Free; DeleteFile(ExpandConstant('{app}\Uninstall\filelist.list')) end; end; end end; //Удаление файлов по списку - end
Сделай создание лога на самом ISесть косяк с BAT, в одной игре, файлы которой сканировал, был в папке файл COW!.wav. Так вот этот BAT восклицательный знак, возможно и какие-то другие подобные, не видит и записывает просто как COW.wav
[Setup]
AppName = MyApp
AppVerName = MyApp
DefaultDirname = {pf}\MyApp
OutputDir=.
[Code]
var
WayScan: String;
procedure MaskScanFilesInListStr(ADirName,AFileName,AFileName2,Mask:String);
var
FindRec: TFindRec;
SD: String;
begin
if FindFirst(AddBackslash(ADirName)+'*.*', FindRec) then begin
try
repeat
if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then begin
if (FindRec.Name <> '.') and (FindRec.Name <> '..') then begin
MaskScanFilesInListStr(AddBackslash(ADirName)+FindRec.Name,AFileName,AFileName2,Mask);
end;
end else begin
SD:= AddBackslash(ADirName)+FindRec.Name;
if (Pos(AnsiLowerCase(AFileName), AnsiLowerCase(SD)) = 0) and
(Pos(AnsiLowerCase(AFileName2), AnsiLowerCase(SD)) = 0) then
begin
StringChangeEx(SD, WayScan, Mask, true);
SaveStringToFile(AFileName2, SD+#13#10, True);
end;
end;
until not FindNext(FindRec);
finally
FindClose(FindRec);
end;
end;
end;
function InitializeSetup: Boolean;
var
strFileName: String;
strTextfile: TArrayOfString;
begin
WayScan:= ExpandConstant('{src}');
strFileName:= ExpandConstant('{src}\Install.log');
if FileExists(strFileName) then DeleteFile(strFileName);
MaskScanFilesInListStr(WayScan,ExtractFileName(ExpandConstant('{srcexe}')),ExtractFileName(strFileName),'ForChange');
if MsgBox('Хотите сконвертировать файл из ANSI в UTF8?', mbInformation, MB_YESNO) = IDYES then begin
LoadStringsFromFile(strFileName, strTextfile);
SaveStringsToUTF8File(strFileName, strTextfile,False);
end;
Result:= False;
end;
Он так не все файлы пишет в лог, если Вы тему читали внимательно)Сделай создание лога на самом IS
Код:[Setup] AppName = MyApp AppVerName = MyApp DefaultDirname = {pf}\MyApp OutputDir=. [Code] procedure MaskScanFilesInListStr(ADirName,AFileName,AFileName2:String); var FindRec: TFindRec; SD: String; begin if FindFirst(AddBackslash(ADirName)+'*.*', FindRec) then begin try repeat if FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0 then begin if (FindRec.Name <> '.') and (FindRec.Name <> '..') then begin MaskScanFilesInListStr(AddBackslash(ADirName)+FindRec.Name,AFileName,AFileName2); end; end else begin SD:= AddBackslash(ADirName)+FindRec.Name; if (Pos(AnsiLowerCase(AFileName), AnsiLowerCase(SD)) = 0) and (Pos(AnsiLowerCase(AFileName2), AnsiLowerCase(SD)) = 0) then begin StringChangeEx(SD, ExpandConstant('{src}\'), '', true); SaveStringToFile(ExpandConstant('{src}')+'\'+AFileName2, SD+#13#10, True); end; end; until not FindNext(FindRec); finally FindClose(FindRec); end; end; end; function InitializeSetup: Boolean; begin if FileExists(ExpandConstant('{src}\Install.log')) then DeleteFile(ExpandConstant('{src}\Install.log')); MaskScanFilesInListStr(ExpandConstant('{src}'),ExtractFileName(ExpandConstant('{srcexe}')),'Install.log'); Result:= False; end;
Вы можете сделать решение на PowerShell и поделиться с коллегами)есть косяк с BAT, в одной игре, файлы которой сканировал, был в папке файл COW!.wav. Так вот этот BAT восклицательный знак, возможно и какие-то другие подобные, не видит и записывает просто как COW.wav
а тут не при установке делается чтением распаковываемого файла, а запуском сканирования после конкретной папки или за ранее до сжатия. Пишет все, покрайней мере у меняОн так не все файлы пишет в лог, если Вы тему читали внимательно)
@Echo off
Set "DataRoot=%~dp0"
Set "OutFile=FILELIST.TXT"
>"%OutFile%" (For /F "delims=" %%A in ('2^>nul Dir "%DataRoot%\*.*" /B /S /A-D') Do (
Set "Str=%%A"
Call Echo Type: files; Name: "{app}\%%str:%~dp0=%%"
))
>>"%OutFile%" (For /F "delims=" %%A in ('2^>nul Dir "%DataRoot%\*.*" /B /S /A:D ^|Sort/R') Do (
Set "Str=%%A"
Call Echo Type: dirifempty; Name: "{app}\%%str:%~dp0=%%"
))
Exit /B