From 3f8d525ec208d8e5669aa3ce479dd3471803883f Mon Sep 17 00:00:00 2001 From: Baz Cuda Date: Wed, 22 May 2024 12:01:43 +0100 Subject: [PATCH] Finish release notes form --- MinimalistMediaPlayer.dpr | 1 - TKeyboardClass.pas | 2 +- TProgramUpdatesClass.pas | 70 ++++++++++++++++----------------- formAbout.dfm | 6 +-- formAbout.pas | 14 +++---- formReleaseNotes.dfm | 29 ++++++++++++-- formReleaseNotes.pas | 83 +++++++++++++++++++++++++++++---------- 7 files changed, 131 insertions(+), 74 deletions(-) diff --git a/MinimalistMediaPlayer.dpr b/MinimalistMediaPlayer.dpr index 30f8bb0..3316732 100644 --- a/MinimalistMediaPlayer.dpr +++ b/MinimalistMediaPlayer.dpr @@ -80,6 +80,5 @@ begin Application.MainFormOnTaskbar := True; TStyleManager.TrySetStyle('Charcoal Dark Slate'); Application.CreateForm(TMMPUI, MMPUI); - Application.CreateForm(TReleaseNotesForm, ReleaseNotesForm); Application.Run; end. diff --git a/TKeyboardClass.pas b/TKeyboardClass.pas index d873294..75e6108 100644 --- a/TKeyboardClass.pas +++ b/TKeyboardClass.pas @@ -345,7 +345,7 @@ function TKeyboard.processKeyStroke(var aKey: word; aShiftState: TShiftState; up koCycleSubs: MP.cycleSubs; koPrevChapter: MP.chapterPrev; koNextChapter: MP.chapterNext; - koThumbnails: UI.toggleThumbnails; +// koThumbnails: UI.toggleThumbnails; end; result := TRUE; diff --git a/TProgramUpdatesClass.pas b/TProgramUpdatesClass.pas index 35dc602..4d21418 100644 --- a/TProgramUpdatesClass.pas +++ b/TProgramUpdatesClass.pas @@ -30,21 +30,19 @@ TProgramUpdates = class(TObject) FReleaseTag: string; private function analyseReleaseNotes(const aReleaseTag: string): boolean; - function downloadAsset(const aURL, aFileName: string): string; + function downloadAsset(const aURL, aFilePath: string; const aSuccess: string = ''): string; function downloadRelease(const aReleaseTag: string): string; function extractRelease(const aReleaseTag: string): boolean; - function getHasReleaseNotes: boolean; function getJSONReleaseTag: string; - function getReleaseNotesFolder: string; - function getReleaseNotesFilePath(const aReleaseTag: string): string; function getReleaseTag: string; function saveReleaseNotes(const aReleaseTag: string): boolean; protected procedure zipOnProgress(sender: TObject; aFileName: string; aHeader: TZipHeader; aPosition: Int64); public - property hasReleaseNotes: boolean read getHasReleaseNotes; - property releaseNotes: string read FReleaseNotes; - property releaseTag: string read getReleaseTag; + function getReleaseNotesFilePath(const aReleaseTag: string): string; + function getReleaseNotesFolder: string; + function hasReleaseNotes(const aReleaseTag: string): boolean; + property releaseTag: string read getReleaseTag; // has a couple of side-effects ;) end; function PU: TProgramUpdates; @@ -167,10 +165,10 @@ function TProgramUpdates.analyseReleaseNotes(const aReleaseTag: string): boolean try vNotes.loadFromFile(getReleaseNotesFilePath(aReleaseTag)); for var i := 0 to vNotes.count - 1 do begin - var vPos := pos('(https://github.com/BazzaCuda/MinimalistMediaPlayerX/assets/', vNotes[i]); - case vPos = 0 of TRUE: CONTINUE; end; + var vPos1 := pos('(https://github.com/BazzaCuda/MinimalistMediaPlayerX/assets/', vNotes[i]); + case vPos1 = 0 of TRUE: CONTINUE; end; - var vAssetURL := copy(vNotes[i], vPos + 1, 255); + var vAssetURL := copy(vNotes[i], vPos1 + 1, 255); var vPos2 := pos(')', vAssetURL); case vPos2 = 0 of TRUE: CONTINUE; end; @@ -181,7 +179,7 @@ function TProgramUpdates.analyseReleaseNotes(const aReleaseTag: string): boolean var vFileName := copy(vAssetURL, vPos3 + 1, 255); - downloadAsset(vAssetURL, vFileName); + downloadAsset(vAssetURL, getReleaseNotesFolder + vFileName); vNotes[i] := replaceStr(vNotes[i], vAssetURL, 'releaseNotes\' + vFileName); end; @@ -192,19 +190,29 @@ function TProgramUpdates.analyseReleaseNotes(const aReleaseTag: string): boolean end; end; -function TProgramUpdates.downloadAsset(const aURL: string; const aFileName: string): string; +function TProgramUpdates.downloadAsset(const aURL: string; const aFilePath: string; const aSuccess: string = ''): string; begin - var vDestFile := getReleaseNotesFolder + aFileName; - case fileExists(vDestFile) of TRUE: EXIT; end; + case fileExists(aFilePath) of TRUE: EXIT; end; - var fs := TFileStream.create(vDestFile, fmCreate); + var fs := TFileStream.create(aFilePath, fmCreate); try - result := fetchURL(aURL, fs); + result := fetchURL(aURL, fs, aSuccess); finally fs.free; end; end; +function TProgramUpdates.downloadRelease(const aReleaseTag: string): string; +begin + result := aReleaseTag; + + case aReleaseTag = '' of TRUE: EXIT; end; // couldn't obtain latest release tag + case (aReleaseTag <> '') AND (CU.getFileVersionFmt('', 'v%d.%d.%d') = aReleaseTag) of TRUE: EXIT; end; // we're running the latest release + case (aReleaseTag <> '') AND (fileExists(updateFile(aReleaseTag))) of TRUE: EXIT; end; // we've already downloaded the release file + + result := downloadAsset('https://github.com/BazzaCuda/MinimalistMediaPlayerX/releases/download/' + aReleaseTag + '/MinimalistMediaPlayer_' + cleanTag(aReleaseTag) + '.full.zip', updateFile(aReleaseTag), aReleaseTag); +end; + function TProgramUpdates.extractRelease(const aReleaseTag: string): boolean; function backupName: string; begin @@ -226,17 +234,13 @@ function TProgramUpdates.extractRelease(const aReleaseTag: string): boolean; end;end; end; -function TProgramUpdates.getHasReleaseNotes: boolean; -begin - result := FReleaseNotes <> ''; -end; - function TProgramUpdates.getJSONReleaseTag: string; var json: string; obj: TJSONObject; begin result := ''; +// json := fetchURL('https://api.github.com/repos/bazzacuda/minimalistmediaplayerx/releases/tags/v2.0.0'); // for DEV only json := fetchURL('https://api.github.com/repos/bazzacuda/minimalistmediaplayerx/releases/latest'); try obj := TJSONObject.ParseJSONValue(json) as TJSONObject; @@ -250,22 +254,6 @@ function TProgramUpdates.getJSONReleaseTag: string; end; end; -function TProgramUpdates.downloadRelease(const aReleaseTag: string): string; -begin - result := aReleaseTag; - - case aReleaseTag = '' of TRUE: EXIT; end; // couldn't obtain latest release tag - case (aReleaseTag <> '') AND (CU.getFileVersionFmt('', 'v%d.%d.%d') = aReleaseTag) of TRUE: EXIT; end; // we're running the latest release - case (aReleaseTag <> '') AND (fileExists(updateFile(aReleaseTag))) of TRUE: EXIT; end; // we've already downloaded the release file - - var fs := TFileStream.create(updateFile(aReleaseTag), fmCreate); - try - result := fetchURL('https://github.com/BazzaCuda/MinimalistMediaPlayerX/releases/download/' + aReleaseTag + '/MinimalistMediaPlayer_' + cleanTag(aReleaseTag) + '.full.zip', fs, aReleaseTag); - finally - fs.free; - end; -end; - function TProgramUpdates.getReleaseNotesFilePath(const aReleaseTag: string): string; begin result := format('%s%s%s%s', [getReleaseNotesFolder, 'releaseNotes ', cleanTag(aReleaseTag), '.md']) @@ -285,7 +273,10 @@ function TProgramUpdates.getReleaseTag: string; result := '(autoUpdate=no)'; case lowerCase(CF.value['autoUpdate']) = 'yes' of FALSE: EXIT; end; + result := '(not available)'; FReleaseTag := getJSONReleaseTag; + case FReleaseTag = '' of TRUE: EXIT; end; + saveReleaseNotes(FReleaseTag); analyseReleaseNotes(FReleaseTag); @@ -294,6 +285,11 @@ function TProgramUpdates.getReleaseTag: string; case (result = FReleaseTag) and fileExists(updateFile(FReleaseTag)) of TRUE: case extractRelease(FReleaseTag) of TRUE: result := result + ' Restart_Required'; end;end; end; +function TProgramUpdates.hasReleaseNotes(const aReleaseTag: string): boolean; +begin + result := fileExists(getReleaseNotesFilePath(aReleaseTag)); +end; + function TProgramUpdates.saveReleaseNotes(const aReleaseTag: string): boolean; begin case FReleaseNotes = '' of TRUE: EXIT; end; diff --git a/formAbout.dfm b/formAbout.dfm index 90c86fc..41751d5 100644 --- a/formAbout.dfm +++ b/formAbout.dfm @@ -2378,14 +2378,14 @@ object AboutForm: TAboutForm Font.Style = [] ParentFont = False end - object btnOK: TButton + object btnClose: TButton Left = 281 Top = 246 Width = 75 Height = 25 - Caption = 'OK' + Caption = '&Close' TabOrder = 0 - OnClick = btnOKClick + OnClick = btnCloseClick end object btnWhatsNew: TButton Left = 504 diff --git a/formAbout.pas b/formAbout.pas index 17cf972..dacbbef 100644 --- a/formAbout.pas +++ b/formAbout.pas @@ -36,7 +36,7 @@ TAboutForm = class(TForm) Label5: TLabel; lblWebsiteURL: TLabel; Bevel1: TBevel; - btnOK: TButton; + btnClose: TButton; Bevel2: TBevel; Label6: TLabel; lblBuildVersion: TLabel; @@ -44,7 +44,7 @@ TAboutForm = class(TForm) Label7: TLabel; btnWhatsNew: TButton; procedure lblWebsiteURLClick(Sender: TObject); - procedure btnOKClick(Sender: TObject); + procedure btnCloseClick(Sender: TObject); procedure lblWebsiteURLMouseEnter(Sender: TObject); procedure lblWebsiteURLMouseLeave(Sender: TObject); procedure btnWhatsNewClick(Sender: TObject); @@ -80,7 +80,7 @@ function showAboutBox(const thisVersion: string; const buildVersion: string): bo setBuildVersion(buildVersion); setLatestReleaseVersion(PU.releaseTag); // if the releaseTag is got, PU also downloads the release zip file and the release notes compareVersions(thisVersion, PU.releaseTag); - setWhatsNew(PU.hasReleaseNotes); + setWhatsNew(PU.hasReleaseNotes(PU.releaseTag)); showModal; finally free; @@ -89,17 +89,14 @@ function showAboutBox(const thisVersion: string; const buildVersion: string): bo end; end; -procedure TAboutForm.btnOKClick(Sender: TObject); +procedure TAboutForm.btnCloseClick(Sender: TObject); begin modalResult := mrOK; end; procedure TAboutForm.btnWhatsNewClick(Sender: TObject); begin - with TReleaseNotesForm.create(NIL) do begin - showModal; - free; - end; + showReleaseNotes(PU.releaseTag); end; function TAboutForm.compareVersions(const thisVersion: string; const latestVersion: string): boolean; @@ -111,6 +108,7 @@ function TAboutForm.compareVersions(const thisVersion: string; const latestVersi procedure TAboutForm.FormShow(Sender: TObject); begin case btnWhatsNew.visible of TRUE: btnWhatsNew.setFocus; end; + btnClose.cancel := TRUE; end; procedure TAboutForm.lblWebsiteURLClick(Sender: TObject); diff --git a/formReleaseNotes.dfm b/formReleaseNotes.dfm index 03303e7..87a9cbd 100644 --- a/formReleaseNotes.dfm +++ b/formReleaseNotes.dfm @@ -11,19 +11,21 @@ object ReleaseNotesForm: TReleaseNotesForm Font.Name = 'Segoe UI' Font.Style = [] Position = poScreenCenter + OnCreate = FormCreate OnShow = FormShow TextHeight = 15 object md: TMarkdownViewer Left = 3 Top = 3 Width = 1233 - Height = 436 + Height = 395 DefFontName = 'Tahoma' MarginWidth = 0 PrintMarginBottom = 2.000000000000000000 PrintMarginLeft = 2.000000000000000000 PrintMarginRight = 2.000000000000000000 PrintMarginTop = 2.000000000000000000 + OnHotSpotClick = mdHotSpotClick Align = alClient TabOrder = 0 FileName = 'B:\Win64_Dev\Programs\MediaPlayerX\README.md' @@ -824,7 +826,28 @@ object ReleaseNotesForm: TReleaseNotesForm '3. Massive credit and thanks are due to Edward Guo for his excel' + 'lent port of the MPV API (libmpv) to Delphi, https://github.com/' + 'nbuyer/libmpvdelphi.') - ExplicitWidth = 620 - ExplicitHeight = 432 + ExplicitLeft = -2 + ExplicitTop = -2 + ExplicitHeight = 363 + end + object Panel1: TPanel + Left = 0 + Top = 401 + Width = 1239 + Height = 41 + Align = alBottom + TabOrder = 1 + ExplicitLeft = 344 + ExplicitTop = 384 + ExplicitWidth = 185 + object btnClose: TButton + Left = 528 + Top = 10 + Width = 75 + Height = 25 + Caption = '&Close' + TabOrder = 0 + OnClick = btnCloseClick + end end end diff --git a/formReleaseNotes.pas b/formReleaseNotes.pas index d6a823f..34e9403 100644 --- a/formReleaseNotes.pas +++ b/formReleaseNotes.pas @@ -7,43 +7,84 @@ interface System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, vcl.stdCtrls, HTMLUn2, HtmlView, MarkDownViewerComponents, - strUtils; + strUtils, Vcl.ExtCtrls; type TReleaseNotesForm = class(TForm) md: TMarkdownViewer; + Panel1: TPanel; + btnClose: TButton; procedure FormShow(Sender: TObject); + procedure btnCloseClick(Sender: TObject); + procedure FormCreate(Sender: TObject); + procedure mdHotSpotClick(Sender: TObject; const SRC: string; var Handled: Boolean); private + function initReleaseNotes: boolean; + function loadReleaseNotes(const aReleaseTag: string): boolean; public end; -var - ReleaseNotesForm: TReleaseNotesForm; +function showReleaseNotes(const aReleaseTag: string): boolean; implementation +uses + winApi.shellApi, + mmpConsts, TProgramUpdatesClass, _debugWindow; + +function showReleaseNotes(const aReleaseTag: string): boolean; +begin + with TReleaseNotesForm.create(NIL) do begin + loadReleaseNotes(aReleaseTag); + showModal; + free; + end; +end; + {$R *.dfm} +procedure TReleaseNotesForm.btnCloseClick(Sender: TObject); +begin + close; +end; + +procedure TReleaseNotesForm.FormCreate(Sender: TObject); +begin + initReleaseNotes; +end; + procedure TReleaseNotesForm.FormShow(Sender: TObject); begin - md.DefBackground := $2B2B2B; - md.defFontColor := $C0C0C0; - md.borderStyle := htNone; - md.defFontName := 'Tahoma'; - md.defFontSize := 11; - SELF.color := md.defBackground; -// SELF.styleElements := []; - md.scrollBars := ssVertical; - md.htOptions := [htOverLinksActive]; - md.serverRoot := 'B:\Win64_Dev\workshops\markdownViewer\Win64\Release\'; - md.loadFromFile('B:\Win64_Dev\workshops\markdownViewer\new 11.md'); - md.LoadFromString(replaceStr(md.MarkdownContent.Text, '\r', #13), FALSE); - md.LoadFromString(replaceStr(md.MarkdownContent.Text, '\n', #10), FALSE); - md.loadFromFile('B:\Win64_Dev\workshops\markdownViewer\README.md'); - md.loadFromFile('B:\Win64_Dev\workshops\markdownViewer\releaseNotes.md'); - md.serverRoot := extractFilePath('B:\Win64_Dev\Programs\MediaPlayerX\Win64\Debug\releaseNotes\releaseNotes v2_2_1.md'); - md.loadFromFile('B:\Win64_Dev\Programs\MediaPlayerX\Win64\Debug\releaseNotes\releaseNotes v2_2_1.md'); -// md.loadFromFile('B:\Win64_Dev\3P\MarkdownHelpViewer\Demo\Help\BrowseTab.md'); + initReleaseNotes; +end; + +function TReleaseNotesForm.initReleaseNotes: boolean; +begin + md.DefBackground := DARK_MODE_DARK; + md.defFontColor := DARK_MODE_SILVER; + md.defHotSpotColor := DARK_MODE_SILVER; + md.defOverLinkColor := DARK_MODE_SILVER; + md.borderStyle := htNone; + md.defFontName := 'Tahoma'; + md.defFontSize := 11; + md.scrollBars := ssVertical; + md.htOptions := [htOverLinksActive]; + SELF.color := md.defBackground; + btnClose.default := TRUE; + btnClose.cancel := TRUE; +end; + +function TReleaseNotesForm.loadReleaseNotes(const aReleaseTag: string): boolean; +begin + SELF.caption := 'Release Notes ' + aReleaseTag; + md.serverRoot := PU.getReleaseNotesFolder; + md.loadFromFile(PU.getReleaseNotesFilePath(aReleaseTag)); +end; + +procedure TReleaseNotesForm.mdHotSpotClick(Sender: TObject; const SRC: string; var Handled: Boolean); +begin + shellExecute(0, 'open', PWideChar(SRC), '', '', SW_SHOW); + handled := TRUE; end; end.