add option to redirect to new rlz page, close #86

This commit is contained in:
Basile Burg 2016-07-08 02:35:02 +02:00
parent 9c50cfa789
commit e873bfb483
2 changed files with 110 additions and 3 deletions

View File

@ -13,7 +13,7 @@
<DpiAware Value="True"/> <DpiAware Value="True"/>
</XPManifest> </XPManifest>
<Icon Value="0"/> <Icon Value="0"/>
<Resources Count="85"> <Resources Count="86">
<Resource_0 FileName="../icons/window/layout_add.png" Type="RCDATA" ResourceName="LAYOUT_ADD"/> <Resource_0 FileName="../icons/window/layout_add.png" Type="RCDATA" ResourceName="LAYOUT_ADD"/>
<Resource_1 FileName="../icons/window/layout.png" Type="RCDATA" ResourceName="LAYOUT"/> <Resource_1 FileName="../icons/window/layout.png" Type="RCDATA" ResourceName="LAYOUT"/>
<Resource_2 FileName="../icons/window/application_go.png" Type="RCDATA" ResourceName="APPLICATION_GO"/> <Resource_2 FileName="../icons/window/application_go.png" Type="RCDATA" ResourceName="APPLICATION_GO"/>
@ -99,6 +99,7 @@
<Resource_82 FileName="../icons/arrow/arrow_down.png" Type="RCDATA" ResourceName="ARROW_DOWN"/> <Resource_82 FileName="../icons/arrow/arrow_down.png" Type="RCDATA" ResourceName="ARROW_DOWN"/>
<Resource_83 FileName="../icons/other/case.png" Type="RCDATA" ResourceName="CASE"/> <Resource_83 FileName="../icons/other/case.png" Type="RCDATA" ResourceName="CASE"/>
<Resource_84 FileName="../icons/other/tag_purple.png" Type="RCDATA" ResourceName="TAG_PURPLE"/> <Resource_84 FileName="../icons/other/tag_purple.png" Type="RCDATA" ResourceName="TAG_PURPLE"/>
<Resource_85 FileName="../cesetup/version.txt" Type="RCDATA" ResourceName="VERSION"/>
</Resources> </Resources>
</General> </General>
<i18n> <i18n>

View File

@ -8,13 +8,13 @@ uses
Classes, SysUtils, LazFileUtils, SynEditKeyCmds, SynHighlighterLFM, Forms, Classes, SysUtils, LazFileUtils, SynEditKeyCmds, SynHighlighterLFM, Forms,
StdCtrls, AnchorDocking, AnchorDockStorage, AnchorDockOptionsDlg, Controls, StdCtrls, AnchorDocking, AnchorDockStorage, AnchorDockOptionsDlg, Controls,
Graphics, strutils, Dialogs, Menus, ActnList, ExtCtrls, process, Graphics, strutils, Dialogs, Menus, ActnList, ExtCtrls, process,
XMLPropStorage, SynExportHTML, XMLPropStorage, SynExportHTML, fphttpclient, xfpjson, xjsonparser, xjsonscanner,
ce_common, ce_dmdwrap, ce_nativeproject, ce_synmemo, ce_writableComponent, ce_common, ce_dmdwrap, ce_nativeproject, ce_synmemo, ce_writableComponent,
ce_widget, ce_messages, ce_interfaces, ce_editor, ce_projinspect, ce_projconf, ce_widget, ce_messages, ce_interfaces, ce_editor, ce_projinspect, ce_projconf,
ce_search, ce_miniexplorer, ce_libman, ce_libmaneditor, ce_todolist, ce_observer, ce_search, ce_miniexplorer, ce_libman, ce_libmaneditor, ce_todolist, ce_observer,
ce_toolseditor, ce_procinput, ce_optionseditor, ce_symlist, ce_mru, ce_processes, ce_toolseditor, ce_procinput, ce_optionseditor, ce_symlist, ce_mru, ce_processes,
ce_infos, ce_dubproject, ce_dialogs, ce_dubprojeditor, (*ce_gdb,*) ce_dfmt, ce_infos, ce_dubproject, ce_dialogs, ce_dubprojeditor, (*ce_gdb,*) ce_dfmt,
ce_lcldragdrop, ce_projgroup, ce_projutils; ce_lcldragdrop, ce_projgroup, ce_projutils, ce_stringrange;
type type
@ -474,6 +474,7 @@ type
fDetectMain: boolean; fDetectMain: boolean;
fDetectRunnableImports: boolean; fDetectRunnableImports: boolean;
fSplitterScrollSpeed: byte; fSplitterScrollSpeed: byte;
fAutoCheckUpdates: boolean;
function getAdditionalPATH: string; function getAdditionalPATH: string;
procedure setAdditionalPATH(const value: string); procedure setAdditionalPATH(const value: string);
function getDubCompiler: TCECompiler; function getDubCompiler: TCECompiler;
@ -486,6 +487,7 @@ type
procedure setSplitterScsrollSpeed(value: byte); procedure setSplitterScsrollSpeed(value: byte);
published published
property additionalPATH: string read getAdditionalPATH write setAdditionalPath; property additionalPATH: string read getAdditionalPATH write setAdditionalPath;
property autoCheckUpdates: boolean read fAutoCheckUpdates write fAutoCheckUpdates;
property coverModuleTests: boolean read fCovModUt write fCovModUt; property coverModuleTests: boolean read fCovModUt write fCovModUt;
property floatingWidgetOnTop: boolean read fFloatingWidgetOnTop write fFloatingWidgetOnTop; property floatingWidgetOnTop: boolean read fFloatingWidgetOnTop write fFloatingWidgetOnTop;
property reloadLastDocuments: boolean read fReloadLastDocuments write fReloadLastDocuments; property reloadLastDocuments: boolean read fReloadLastDocuments write fReloadLastDocuments;
@ -1395,7 +1397,99 @@ begin
end; end;
end; end;
function checkForUpdate: string;
var
prs: TJSONParser = nil;
dat: TJSONData = nil;
tgg: TJSONData = nil;
url: TJSONData = nil;
str: string;
mn0: byte = 0;
mj0: byte;
kd0: string;
mn1: byte = 0;
mj1: byte;
kd1: string;
can: boolean = false;
rng: TStringRange = (ptr:nil; pos:0; len: 0);
cli: TFPHTTPClient;
lst: TStringList = nil;
res: TResourceStream = nil;
begin
result := '';
cli := TFPHTTPClient.Create(nil);
try
try
cli.AddHeader('User-Agent','Mozilla/5.0 (compatible; fpweb)');
str := cli.Get('https://api.github.com/repos/BBasile/Coedit/releases/latest');
prs := TJSONParser.Create(str, [joUTF8, joIgnoreTrailingComma]);
dat := prs.Parse;
if dat.isNotNil then
begin
url := dat.FindPath('html_url');
tgg := dat.FindPath('tag_name');
if url.isNotNil and tgg.isNotNil then
begin
// TODO: change version.txt format
// version.txt has a different format than the git tags
// txt: <major><kind><minor>
// git: <major>_<kind>_<minor>
// when <kind> = 'gold' no minor version is present
// => related to regexp on txt, could be changed with #54
res:= TResourceStream.Create(HINSTANCE, 'VERSION', RT_RCDATA);
lst := TstringList.Create;
lst.LoadFromStream(res);
str := lst.Text;
if str.length < 6 then
raise Exception.Create('');
rng.init(str);
mj0 := rng.takeWhile(['0'..'9']).yield.toIntNoExcept;
kd0 := rng.takeUntil(['0'..'9']).yield;
mn0 := rng.takeWhile(['0'..'9']).yield.toIntNoExcept;
str := tgg.AsString;
rng.init(str);
mj1 := rng.takeWhile(['0'..'9']).yield.toIntNoExcept;
rng.popFront;
kd1 := rng.takeUntil('_').yield;
if (kd1 <> 'gold') and not rng.empty then
begin
rng.popFront;
mn1 := rng.takeWhile(['0'..'9']).yield.toIntNoExcept;
end;
if mj1 > mj0 then
can := true
else if mj1 < mj0 then
can := false
else if kd0 = kd1 then
can := (mj1 = mj0) and (mn1 > mn0)
else if (kd0 = 'alpha') and (kd1 <> 'alpha') then
can := (mj1 = mj0) and (mn1 > mn0)
else if (kd0 = 'beta') and (kd1 <> 'alpha') and (kd1 <> 'beta') then
can := (mj1 = mj0) and (mn1 > mn0)
else if (kd0 = 'gold') and (kd1 = 'update') and (kd1 <> 'beta') then
can := (mj1 = mj0) and (mn1 > mn0);
if can then
result := url.AsString;
end;
end;
except
dlgOkError('The latest release cannot be determined');
end;
finally
cli.free;
prs.free;
dat.free;
lst.free;
res.free;
end;
end;
procedure TCEMainForm.DoShow; procedure TCEMainForm.DoShow;
var
url: string;
begin begin
inherited; inherited;
if (not fFirstShown) then if (not fFirstShown) then
@ -1412,6 +1506,17 @@ begin
if fFirstTimeCoedit then if fFirstTimeCoedit then
actFileNewRun.Execute; actFileNewRun.Execute;
if fAppliOpts.autoCheckUpdates then
begin
url := checkForUpdate;
if url <> '' then
begin
if dlgYesNo('An new release is available, do you wish to visit the release page ?' +
lineEnding + '(' + url +')') = mrYes then
openUrl(url);
end;
end;
fFirstShown := true; fFirstShown := true;
end; end;
setSplitterWheelEvent; setSplitterWheelEvent;
@ -1597,6 +1702,7 @@ begin
// //
srcLst.Clear; srcLst.Clear;
end; end;
{$ENDREGION} {$ENDREGION}
{$REGION ICEMultiDocMonitor ----------------------------------------------------} {$REGION ICEMultiDocMonitor ----------------------------------------------------}