Subversion Repositories fastphp

Compare Revisions

Regard whitespace Rev 74 → Rev 75

/trunk/EditorMain.pas
945,7 → 945,7
end;
FreeAndNil(SrcRep);
 
if hMutex <> 0 then CloseHandle(hMutex);
if hMutex <> 0 then CloseHandle(hMutex); // Note: ReleaseMutex does not work as expected!
 
if Assigned(codeExplorer) then
begin
990,7 → 990,7
begin
if hMutex = 0 then
begin
hMutex := CreateMutex(nil, True, PChar('FastPHP'+md5(ScrapFile)));
hMutex := CreateMutex(nil, True, PChar('FastPHP'+md5(UpperCase(ScrapFile))));
if GetLastError = ERROR_ALREADY_EXISTS then
begin
// TODO: It would be great if the window of that FastPHP instance would switched to foreground
1025,9 → 1025,23
end;
 
procedure TForm1.Saveas1Click(Sender: TObject);
var
hMutexNew: THandle;
begin
if SaveDialog1.Execute then
begin
{$REGION 'Switch mutex'}
hMutexNew := CreateMutex(nil, True, PChar('FastPHP'+md5(UpperCase(SaveDialog1.FileName))));
if GetLastError = ERROR_ALREADY_EXISTS then
begin
ShowMessageFmt('Cannot save because file "%s", because it is alrady open in another FastPHP window!', [SaveDialog1.FileName]);
Close;
end;
 
if hMutex <> 0 then CloseHandle(hMutex); // Note: ReleaseMutex does not work as expected!
hMutex := hMutexNew;
{$ENDREGION}
 
FSaveAsFilename := SaveDialog1.FileName;
Caption := Copy(Caption, 1, Pos(' - ', Caption)-1) + ' - ' + FSaveAsFilename;
Button7.Click;
/trunk/Functions.pas
22,7 → 22,8
function GetTempDir: string;
function GetSpecialFolder(const aCSIDL: Integer): string;
function GetMyDocumentsFolder: string;
function md5(value: string): string;
function MD5(const str: string): string;
function MD5Stream(const s: TStream): string;
 
implementation
 
328,17 → 329,50
Result := GetSpecialFolder(CSIDL_PERSONAL);
end;
 
function md5(value: string): string;
 
{$IF gsIdVersion <> '10.1.5'} // Delphi 2007 built-in Indy10; gsIdVersion requires idGlobal.pas
{$DEFINE NewIndy}
{$IFEND}
 
function MD5Stream(const s: TStream): string;
var
hashMessageDigest5 : TIdHashMessageDigest5;
idmd5: TIdHashMessageDigest5;
begin
hashMessageDigest5 := nil;
idmd5 := TIdHashMessageDigest5.Create;
try
hashMessageDigest5 := TIdHashMessageDigest5.Create;
Result := IdGlobal.IndyLowerCase(hashMessageDigest5.HashStringAsHex(value));
{$IFDEF NewIndy}
result := idmd5.HashStreamAsHex(s);
{$ELSE}
result := idmd5.AsHex(idmd5.HashValue(s));
{$ENDIF}
finally
hashMessageDigest5.Free;
idmd5.Free;
end;
end;
 
function MD5(const str: string): string;
{$IFDEF NewIndy}
var
idmd5: TIdHashMessageDigest5;
begin
idmd5 := TIdHashMessageDigest5.Create;
try
result := idmd5.HashStringAsHex(str,IndyTextEncoding_OSDefault);
finally
idmd5.Free;
end;
{$ELSE}
var
ss: TStringStream;
begin
ss := TStringStream.Create(str);
try
result := MD5Stream(ss);
finally
ss.Free;
end;
{$ENDIF}
end;
 
 
end.