IDE: save project icon: save only once and catch write errors

git-svn-id: trunk@35814 -
This commit is contained in:
mattias 2012-03-07 23:51:00 +00:00
parent d9162800f5
commit 9913f6cb48
2 changed files with 14 additions and 11 deletions

View File

@ -35,8 +35,8 @@ interface
uses
Classes, SysUtils, FileUtil, Process, LCLProc, Controls, Forms,
CodeToolManager, LazConf, Laz_XMLCfg, LResources, resource, groupiconresource,
ProjectIntf, ProjectResourcesIntf;
CodeToolManager, CodeCache, LazConf, Laz_XMLCfg, LResources, resource,
DialogProcs, groupiconresource, ProjectIntf, ProjectResourcesIntf;
type
TIconData = array of byte;
@ -127,7 +127,8 @@ begin
SetFileNames(MainFilename);
if FilenameIsAbsolute(FIcoFileName) then
CreateIconFile;
if not CreateIconFile then
exit(false);
{ to create an lrs with icon we can use this but there is no reason anymore
if AResources.ResourceType <> rtRes then
@ -182,19 +183,20 @@ end;
function TProjectIcon.CreateIconFile: Boolean;
var
FileStream, AStream: TStream;
AStream: TStream;
Code: TCodeBuffer;
begin
Result := False;
AStream := GetStream;
FileStream := nil;
if AStream=nil then exit;
try
FileStream := TFileStream.Create(UTF8ToSys(FicoFileName), fmCreate);
FileStream.CopyFrom(AStream, AStream.Size);
Result := True;
Code:=CodeToolBoss.CreateFile(FicoFileName);
if Code=nil then exit;
Code.LoadFromStream(AStream);
Result:=SaveCodeBuffer(Code) in [mrOk,mrIgnore];
finally
FileStream.Free;
AStream.Free;
end;
AStream.Free;
end;
{-----------------------------------------------------------------------------

View File

@ -369,6 +369,7 @@ function TProjectResources.Update: Boolean;
var
i: integer;
begin
Result:=true;
Clear;
for i := 0 to FResources.Count - 1 do
begin
@ -483,7 +484,7 @@ begin
Result := False;
if (MainFileName = '') then
Exit;
Exit(true);
// remember old codebuffer filenames
LastResFilename := resFileName;