Skip to content

Commit

Permalink
Finish release notes form
Browse files Browse the repository at this point in the history
  • Loading branch information
BazzaCuda committed May 22, 2024
1 parent ba92ac2 commit 3f8d525
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 74 deletions.
1 change: 0 additions & 1 deletion MinimalistMediaPlayer.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,5 @@ begin
Application.MainFormOnTaskbar := True;
TStyleManager.TrySetStyle('Charcoal Dark Slate');
Application.CreateForm(TMMPUI, MMPUI);
Application.CreateForm(TReleaseNotesForm, ReleaseNotesForm);
Application.Run;
end.
2 changes: 1 addition & 1 deletion TKeyboardClass.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
70 changes: 33 additions & 37 deletions TProgramUpdatesClass.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -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'])
Expand All @@ -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);

Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions formAbout.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 6 additions & 8 deletions formAbout.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ TAboutForm = class(TForm)
Label5: TLabel;
lblWebsiteURL: TLabel;
Bevel1: TBevel;
btnOK: TButton;
btnClose: TButton;
Bevel2: TBevel;
Label6: TLabel;
lblBuildVersion: TLabel;
lblLatestReleaseVersion: TLabel;
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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
29 changes: 26 additions & 3 deletions formReleaseNotes.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
83 changes: 62 additions & 21 deletions formReleaseNotes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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.

0 comments on commit 3f8d525

Please sign in to comment.