IDE: initial setup dialog: use SimpleFormat, resourcestrings cannot be trusted during boot

git-svn-id: trunk@47017 -
This commit is contained in:
mattias 2014-11-28 13:08:14 +00:00
parent b20ca2c1af
commit 05a395046c
3 changed files with 80 additions and 38 deletions

View File

@ -40,11 +40,12 @@ unit InitialSetupDlgs;
interface
uses
Classes, SysUtils, strutils, contnrs, LCLProc, Forms, Controls, Buttons, Dialogs, FileUtil,
Laz2_XMLCfg, lazutf8classes, LazFileUtils, LazFileCache, Graphics, ComCtrls, ExtCtrls,
StdCtrls, DefineTemplates, CodeToolManager, TransferMacros, MacroDefIntf, GDBMIDebugger,
DbgIntfDebuggerBase, LazarusIDEStrConsts, LazConf, EnvironmentOpts, IDEProcs, AboutFrm,
IDETranslations, InitialSetupProc;
Classes, SysUtils, strutils, contnrs, LCLProc, Forms, Controls, Buttons,
Dialogs, FileUtil, Laz2_XMLCfg, lazutf8classes, LazFileUtils, LazFileCache,
LazLogger, Graphics, ComCtrls, ExtCtrls, StdCtrls, DefineTemplates,
CodeToolManager, TransferMacros, MacroDefIntf, GDBMIDebugger,
DbgIntfDebuggerBase, LazarusIDEStrConsts, LazConf, EnvironmentOpts, IDEProcs,
AboutFrm, IDETranslations, InitialSetupProc;
type
TInitialSetupDialog = class;
@ -189,8 +190,6 @@ function CheckDebuggerQuality(AFilename: string; out Note: string): TSDFilenameQ
// Search debugger candidates and add them to list, including quality level
function SearchDebuggerCandidates(StopIfFits: boolean): TSDFileInfoList;
function SafeFormat(const Fmt: String; const Args: Array of const): String;
implementation
const
@ -321,22 +320,6 @@ begin
end;
end;
function SafeFormat(const Fmt: String; const Args: array of const): String;
begin
// try with translated resourcestring
try
Result:=Format(Fmt,Args);
exit;
except
end;
// translation didn't work
// => get the default value (English)
// there is no official way to get the default value of a resourcestring
// => reset all resourcestrings
ResetResourceTables;
Result:=Format(Fmt,Args);
end;
function ShowInitialSetupDialog: TModalResult;
var
InitialSetupDialog: TInitialSetupDialog;
@ -523,7 +506,7 @@ begin
Dlg:=TOpenDialog.Create(nil);
try
Filename:='gdb'+GetExecutableExt;
Dlg.Title:=SafeFormat(lisSelectPathTo, [Filename]);
Dlg.Title:=SimpleFormat(lisSelectPathTo, [Filename]);
Dlg.Options:=Dlg.Options+[ofFileMustExist];
Filter:=dlgAllFiles+'|'+GetAllFilesMask;
if ExtractFileExt(Filename)<>'' then
@ -552,7 +535,7 @@ begin
Dlg:=TOpenDialog.Create(nil);
try
Filename:='fpc'+GetExecutableExt;
Dlg.Title:=SafeFormat(lisSelectPathTo, [Filename]);
Dlg.Title:=SimpleFormat(lisSelectPathTo, [Filename]);
Dlg.Options:=Dlg.Options+[ofFileMustExist];
Filter:=dlgAllFiles+'|'+GetAllFilesMask;
if ExtractFileExt(Filename)<>'' then
@ -620,7 +603,7 @@ begin
Dlg:=TOpenDialog.Create(nil);
try
Filename:='make'+GetExecutableExt;
Dlg.Title:=SafeFormat(lisSelectPathTo, [Filename]);
Dlg.Title:=SimpleFormat(lisSelectPathTo, [Filename]);
Dlg.Options:=Dlg.Options+[ofFileMustExist];
Filter:=dlgAllFiles+'|'+GetAllFilesMask;
if ExtractFileExt(Filename)<>'' then
@ -751,7 +734,7 @@ procedure TInitialSetupDialog.UpdateCaptions;
var
s: String;
begin
Caption:=SafeFormat(lisWelcomeToLazarusIDE, [GetLazarusVersionString]);
Caption:=SimpleFormat(lisWelcomeToLazarusIDE, [GetLazarusVersionString]);
StartIDEBitBtn.Caption:=lisStartIDE;
@ -768,26 +751,26 @@ begin
TVNodeDebugger.Text:=DebuggerTabSheet.Caption;
LazDirBrowseButton.Caption:=lisPathEditBrowse;
LazDirLabel.Caption:=SafeFormat(
LazDirLabel.Caption:=SimpleFormat(
lisTheLazarusDirectoryContainsTheSourcesOfTheIDEAndTh, [PathDelim]);
CompilerBrowseButton.Caption:=lisPathEditBrowse;
CompilerLabel.Caption:=SafeFormat(lisTheFreePascalCompilerExecutableTypicallyHasTheName,
CompilerLabel.Caption:=SimpleFormat(lisTheFreePascalCompilerExecutableTypicallyHasTheName,
[DefineTemplates.GetDefaultCompilerFilename,
DefineTemplates.GetDefaultCompilerFilename(GetCompiledTargetCPU)]);
FPCSrcDirBrowseButton.Caption:=lisPathEditBrowse;
FPCSrcDirLabel.Caption:=SafeFormat(lisTheSourcesOfTheFreePascalPackagesAreRequiredForBro,
FPCSrcDirLabel.Caption:=SimpleFormat(lisTheSourcesOfTheFreePascalPackagesAreRequiredForBro,
[SetDirSeparators('rtl/linux/system.pp')]);
ScanLabel.Caption := lisScanning;
StopScanButton.Caption:=lisStop;
MakeExeBrowseButton.Caption:=lisPathEditBrowse;
MakeExeLabel.Caption:=SafeFormat(
MakeExeLabel.Caption:=SimpleFormat(
lisTheMakeExecutableTypicallyHasTheName, ['make'+GetExecutableExt('')]);
DebuggerBrowseButton.Caption:=lisPathEditBrowse;
s:=SafeFormat(lisTheDebuggerExecutableTypicallyHasTheNamePleaseGive, [
s:=SimpleFormat(lisTheDebuggerExecutableTypicallyHasTheNamePleaseGive, [
'gdb'+GetExecutableExt]);
{$IFDEF Windows}
s+=' '+lisAUsefulSettingOnWindowsSystemsIsLazarusDirMingwBin;

View File

@ -33,8 +33,9 @@ interface
uses
Classes, SysUtils, strutils, LazFileCache, LazUTF8Classes, LazFileUtils,
LazLoggerBase, LazUTF8, Laz2_XMLCfg, DefineTemplates, CodeToolManager,
LazarusIDEStrConsts, LazConf, EnvironmentOpts, IDEProcs, contnrs;
LazLoggerBase, LazUTF8, Laz2_XMLCfg, LazLogger, DefineTemplates,
CodeToolManager, LazarusIDEStrConsts, LazConf, EnvironmentOpts, IDEProcs,
contnrs;
type
TSDFilenameQuality = (
@ -104,6 +105,8 @@ function GetValueFromPrimaryConfig(OptionFilename, Path: string): string;
function GetValueFromSecondaryConfig(OptionFilename, Path: string): string;
function GetValueFromIDEConfig(OptionFilename, Path: string): string;
function SafeFormat(const Fmt: String; const Args: Array of const): String;
function SimpleFormat(const Fmt: String; const Args: Array of const): String;
implementation
@ -891,6 +894,62 @@ begin
end;
end;
function SafeFormat(const Fmt: String; const Args: array of const): String;
begin
// try with translated resourcestring
try
Result:=Format(Fmt,Args);
exit;
except
on E: Exception do
debugln(['ERROR: SafeFormat: ',E.Message]);
end;
// translation didn't work
// ToDo: find out how to get the resourcestring default value
//ResetResourceTables;
// use a safe fallback
Result:=SimpleFormat(Fmt,Args);
end;
function SimpleFormat(const Fmt: String; const Args: array of const): String;
var
p: Integer;
i: Integer;
s: String;
begin
Result:=Fmt;
p:=1;
for i:=Low(Args) to High(Args) do
begin
case Args[i].VType of
vtString: s:=Args[i].VString^;
vtAnsiString: s:=AnsiString(Args[i].VAnsiString);
vtChar: s:=Args[i].VChar;
else continue;
end;
while (p<length(Result)) do begin
if (Result[p]='%') then
begin
if (Result[p+1]='s') then
break
else
inc(p,2);
end else
inc(p);
end;
if p<length(Result) then begin
// found %s => replace
ReplaceSubstring(Result,p,2,s);
inc(p,length(s));
end else begin
// missing %s => append
Result+=', '+s;
p:=length(s)+1;
end;
end;
end;
{ TSDFileInfoList }
function TSDFileInfoList.AddNewItem(aFilename, aCaption: string): TSDFileInfo;

View File

@ -1132,7 +1132,7 @@ procedure TMainIDE.LoadGlobalOptions;
var
StartFile: String;
begin
Result:=SafeFormat(lisIfYouWantToUseTwoDifferentLazarusVersionsYouMustSt,
Result:=SimpleFormat(lisIfYouWantToUseTwoDifferentLazarusVersionsYouMustSt,
[LineEnding+LineEnding]) + LineEnding;
StartFile:=Application.ExeName;
if StartedByStartLazarus then
@ -1236,7 +1236,7 @@ begin
debugln([' CurPrgName="',CurPrgName,'"']);
debugln([' AltPrgName="',AltPrgName,'"']);
MsgResult := IDEQuestionDialog(lisIncorrectConfigurationDirectoryFound,
SafeFormat(lisIDEConficurationFoundMayBelongToOtherLazarus,
SimpleFormat(lisIDEConficurationFoundMayBelongToOtherLazarus,
[LineEnding, GetSecondConfDirWarning, GetPrimaryConfigPath,
EnvironmentOptions.LastCalledByLazarusFullPath, CurPrgName]),
mtWarning, [mrOK, lisUpdateInfo, mrIgnore, mrAbort]);
@ -1265,8 +1265,8 @@ begin
begin
IsUpgrade:=CompareLazarusVersion(NowVer,OldVer)>0;
if OldVer='' then
OldVer:=SafeFormat(lisPrior, [GetLazarusVersionString]);
s:=SafeFormat(lisWelcomeToLazarusThereIsAlreadyAConfigurationFromVe,
OldVer:=SimpleFormat(lisPrior, [GetLazarusVersionString]);
s:=SimpleFormat(lisWelcomeToLazarusThereIsAlreadyAConfigurationFromVe,
[GetLazarusVersionString, LineEnding+LineEnding, OldVer, LineEnding, GetPrimaryConfigPath] );
if IsUpgrade then
s+=lisTheOldConfigurationWillBeUpgraded