Skip to content

Commit

Permalink
Better Offline mode and Bug Fixes
Browse files Browse the repository at this point in the history
Offline mode is now finally finished, you can browse your entire library when in offline mode it it's downloaded! And a majority of bugs have been fixed.

Even a severe one that occured with each launch, It was caused by the Cod.SysUtils external library which had a function to get the user name, and It was not well inplemented.
  • Loading branch information
Codrax committed May 2, 2023
1 parent 9e8fa46 commit eeb7c9c
Show file tree
Hide file tree
Showing 12 changed files with 493 additions and 178 deletions.
42 changes: 23 additions & 19 deletions BroadcastAPI.pas
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,7 @@ function TTrackItem.GetArtwork(Large: boolean): TJPEGImage;
begin
CachedImage := GetSongArtwork(ArtworkID, TArtSize.Medium);

// Save artstore
if ArtworkStore then
AddToArtworkStore(ID, CachedImage, TDataSource.Tracks);
end;
Expand Down Expand Up @@ -1005,6 +1006,7 @@ function TAlbumItem.GetArtwork: TJPEGImage;
begin
CachedImage := Tracks[GetTrack( TracksID[0] )].GetArtwork();

// Save artstore
if ArtworkStore then
AddToArtworkStore(ID, CachedImage, TDataSource.Albums);
end;
Expand Down Expand Up @@ -1064,27 +1066,28 @@ function TArtistItem.GetArtwork: TJPEGImage;
if ExistsInStore(ID, TDataSource.Artists) then
CachedImage := GetArtStoreCache(ID, TDataSource.Artists)
else
begin
if HasArtwork then
// Get premade
CachedImage := GetSongArtwork(ArtworkID, TArtSize.Medium)
else
// Load from server, save to artowork store
begin
if Length(TracksID) >= 4 then
begin
CachedImage := SongArtCollage(TracksID[0], TracksID[1], TracksID[2], TracksID[3]);
end
else
if Length(TracksID) > 0 then
CachedImage := Tracks[GetTrack( TracksID[0] )].GetArtwork()
// Load from server, save to artowork store
begin
if HasArtwork then
// Get premade
CachedImage := GetSongArtwork(ArtworkID, TArtSize.Medium)
else
begin
if Length(TracksID) >= 4 then
begin
CachedImage := SongArtCollage(TracksID[0], TracksID[1], TracksID[2], TracksID[3]);
end
else
CachedImage := DefaultPicture;
if Length(TracksID) > 0 then
CachedImage := Tracks[GetTrack( TracksID[0] )].GetArtwork()
else
CachedImage := DefaultPicture;
end;

if ArtworkStore and (CachedImage <> DefaultPicture) then
AddToArtworkStore(ID, CachedImage, TDataSource.Artists);
end;
end;
// Save artstore
if ArtworkStore and (CachedImage <> DefaultPicture) then
AddToArtworkStore(ID, CachedImage, TDataSource.Artists);
end;
end;

Result := CachedImage;
Expand Down Expand Up @@ -1160,6 +1163,7 @@ function TPlaylistItem.GetArtwork: TJPEGImage;
CachedImage := DefaultPicture;
end;

// Save artstore
if ArtworkStore and (CachedImage <> DefaultPicture) then
AddToArtworkStore(ID, CachedImage, TDataSource.Playlists);
end;
Expand Down
64 changes: 39 additions & 25 deletions DebugForm.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,20 @@ object DebugUI: TDebugUI
Height = 21
Caption = 'Ch Active:'
end
object Label11: TLabel
Left = 185
Top = 223
Width = 91
Height = 21
Caption = 'Img-Threads:'
end
object Label12: TLabel
Left = 185
Top = 250
Width = 100
Height = 21
Caption = 'Downl Thread:'
end
object CButton1: CButton
Left = 19
Top = 120
Expand Down Expand Up @@ -981,10 +995,10 @@ object DebugUI: TDebugUI
Text = 'Copy Token'
SubText = 'Hello World!'
State = mbsLeave
Colors.Enter = 8364496
Colors.Leave = 5732776
Colors.Down = 3101056
Colors.BLine = 3101056
Colors.Enter = 8888776
Colors.Leave = 6257056
Colors.Down = 3625336
Colors.BLine = 3625336
Preset.Color = clBlue
Preset.Kind = cbprCustom
Preset.PenColorAuto = True
Expand Down Expand Up @@ -1041,10 +1055,10 @@ object DebugUI: TDebugUI
Text = 'Copy User ID'
SubText = 'Hello World!'
State = mbsLeave
Colors.Enter = 8364496
Colors.Leave = 5732776
Colors.Down = 3101056
Colors.BLine = 3101056
Colors.Enter = 8888776
Colors.Leave = 6257056
Colors.Down = 3625336
Colors.BLine = 3625336
Preset.Color = clBlue
Preset.Kind = cbprCustom
Preset.PenColorAuto = True
Expand Down Expand Up @@ -1120,10 +1134,10 @@ object DebugUI: TDebugUI
Text = 'POST'
SubText = 'Hello World!'
State = mbsLeave
Colors.Enter = 8364496
Colors.Leave = 5732776
Colors.Down = 3101056
Colors.BLine = 3101056
Colors.Enter = 8888776
Colors.Leave = 6257056
Colors.Down = 3625336
Colors.BLine = 3625336
Preset.Color = clBlue
Preset.Kind = cbprCustom
Preset.PenColorAuto = True
Expand Down Expand Up @@ -1180,10 +1194,10 @@ object DebugUI: TDebugUI
Text = 'Copy song URL'
SubText = 'Hello World!'
State = mbsLeave
Colors.Enter = 8364496
Colors.Leave = 5732776
Colors.Down = 3101056
Colors.BLine = 3101056
Colors.Enter = 8888776
Colors.Leave = 6257056
Colors.Down = 3625336
Colors.BLine = 3625336
Preset.Color = clBlue
Preset.Kind = cbprCustom
Preset.PenColorAuto = True
Expand Down Expand Up @@ -1252,10 +1266,10 @@ object DebugUI: TDebugUI
Text = 'Get Queue'
SubText = 'Hello World!'
State = mbsLeave
Colors.Enter = 8364496
Colors.Leave = 5732776
Colors.Down = 3101056
Colors.BLine = 3101056
Colors.Enter = 8888776
Colors.Leave = 6257056
Colors.Down = 3625336
Colors.BLine = 3625336
Preset.Color = clBlue
Preset.Kind = cbprCustom
Preset.PenColorAuto = True
Expand Down Expand Up @@ -1312,10 +1326,10 @@ object DebugUI: TDebugUI
Text = 'DEBG 1'
SubText = 'Hello World!'
State = mbsLeave
Colors.Enter = 8364496
Colors.Leave = 5732776
Colors.Down = 3101056
Colors.BLine = 3101056
Colors.Enter = 8888776
Colors.Leave = 6257056
Colors.Down = 3625336
Colors.BLine = 3625336
Preset.Color = clBlue
Preset.Kind = cbprCustom
Preset.PenColorAuto = True
Expand Down Expand Up @@ -1344,7 +1358,7 @@ object DebugUI: TDebugUI
end
object SearchBox1: TSearchBox
Left = 184
Top = 240
Top = 303
Width = 121
Height = 29
Font.Charset = DEFAULT_CHARSET
Expand Down
8 changes: 6 additions & 2 deletions DebugForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ TDebugUI = class(TForm)
Label9: TLabel;
Label10: TLabel;
SearchBox1: TSearchBox;
Label11: TLabel;
Label12: TLabel;
procedure CButton1Click(Sender: TObject);
procedure CButton2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
Expand Down Expand Up @@ -89,7 +91,7 @@ procedure TDebugUI.CButton5Click(Sender: TObject);

procedure TDebugUI.CButton6Click(Sender: TObject);
begin
ShowMessage( UIForm.ScrollPosition.Max.ToString );
UIForm.SearchToggle.Left := 0;
end;

procedure TDebugUI.DataSyncTimer(Sender: TObject);
Expand All @@ -98,7 +100,9 @@ procedure TDebugUI.DataSyncTimer(Sender: TObject);
Label6.Caption := 'Hover: ' + MainUI.IndexHover.ToString;
Label7.Caption := 'Hover SH: ' + MainUI.IndexHoverID.ToString;
Label9.Caption := '10s Shrink:' + MainUI.Press10Stat.ToString;
Label10.Caption := 'Ch Active::' + BooleanToString( BASS_ChannelIsActive(Player.Stream) = BASS_ACTIVE_PLAYING );
Label10.Caption := 'Ch Active: ' + BooleanToString( BASS_ChannelIsActive(Player.Stream) = BASS_ACTIVE_PLAYING );
Label11.Caption := 'Img-Thread: ' + TotalThreads.ToString;
Label12.Caption := 'Img-Thread: ' + DownloadThreadsE.ToString;
end;

procedure TDebugUI.FormCreate(Sender: TObject);
Expand Down
26 changes: 20 additions & 6 deletions Dependencies/Cod.SysUtils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1024,15 +1024,29 @@ function GetUserNameString: string;

function GetCompleteUserName: string;
const
NameFormat = NameDisplay;
nameType = NameDisplay;
var
Size: Cardinal;
dwSize: DWORD;
userName: PWideChar;
begin
Size := 0;
if GetUserNameEx(NameFormat, nil, Size) <> S_OK then
dwSize := 0;
if Succeeded(GetUserNameEx(nameType, nil, dwSize)) then
begin
GetMem(userName, dwSize * SizeOf(WideChar));
try
if Succeeded(GetUserNameEx(nameType, userName, dwSize)) then
begin
// use the name
Result := PChar(userName);
end
else
RaiseLastOSError;
finally
FreeMem(userName);
end;
end
else
RaiseLastOSError;
SetLength(Result, Size - 1);
GetUserNameEx(NameFormat, PWideChar(Result), Size);
end;

function IsAdministrator: boolean;
Expand Down
17 changes: 7 additions & 10 deletions InfoForm.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ object InfoBox: TInfoBox
Caption = 'Panel1'
ShowCaption = False
TabOrder = 1
ExplicitHeight = 246
object Song_Name: TLabel
AlignWithMargins = True
Left = 25
Top = 5
Width = 199
Width = 384
Height = 37
Margins.Left = 25
Margins.Top = 5
Expand All @@ -57,12 +56,13 @@ object InfoBox: TInfoBox
Font.Style = []
ParentFont = False
WordWrap = True
ExplicitWidth = 199
end
object Song_Info: TLabel
AlignWithMargins = True
Left = 25
Top = 52
Width = 195
Width = 384
Height = 21
Margins.Left = 25
Margins.Top = 5
Expand All @@ -77,6 +77,7 @@ object InfoBox: TInfoBox
Font.Style = []
ParentFont = False
WordWrap = True
ExplicitWidth = 195
end
end
object Panel2: TPanel
Expand All @@ -95,7 +96,6 @@ object InfoBox: TInfoBox
ParentColor = True
ShowCaption = False
TabOrder = 2
ExplicitHeight = 246
object Song_Cover: CImage
AlignWithMargins = True
Left = 25
Expand All @@ -114,7 +114,7 @@ object InfoBox: TInfoBox
DrawMode = dmCenterFit
ExplicitWidth = 372
end
object CButton24: CButton
object Download_Item: CButton
AlignWithMargins = True
Left = 15
Top = 235
Expand All @@ -124,8 +124,8 @@ object InfoBox: TInfoBox
Margins.Top = 5
Margins.Right = 15
Margins.Bottom = 0
OnEnter = CButton24Enter
OnClick = CButton24Click
OnEnter = Download_ItemEnter
OnClick = Download_ItemClick
TabOrder = 0
Align = alTop
BSegoeIcon = #59542
Expand Down Expand Up @@ -181,9 +181,6 @@ object InfoBox: TInfoBox
Animations.PAAnimateEngine = cbneAtDraw
Animations.FadeAnimation = True
Animations.FASpeed = 10
ExplicitLeft = 0
ExplicitTop = 242
ExplicitWidth = 240
end
end
end
10 changes: 5 additions & 5 deletions InfoForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ TInfoBox = class(TForm)
Song_Info: TLabel;
Panel2: TPanel;
Song_Cover: CImage;
CButton24: CButton;
Download_Item: CButton;
procedure FormCreate(Sender: TObject);
procedure CButton24Enter(Sender: TObject);
procedure CButton24Click(Sender: TObject);
procedure Download_ItemEnter(Sender: TObject);
procedure Download_ItemClick(Sender: TObject);
private
{ Private declarations }
public
Expand All @@ -41,7 +41,7 @@ implementation

{$R *.dfm}

procedure TInfoBox.CButton24Click(Sender: TObject);
procedure TInfoBox.Download_ItemClick(Sender: TObject);
var
ListIndex: integer;
LastValue: string;
Expand Down Expand Up @@ -82,7 +82,7 @@ procedure TInfoBox.CButton24Click(Sender: TObject);
UIForm.UpdateDownloads;
end;

procedure TInfoBox.CButton24Enter(Sender: TObject);
procedure TInfoBox.Download_ItemEnter(Sender: TObject);
begin
with CButton(Sender) do
if Tag <> 0 then
Expand Down
Loading

0 comments on commit eeb7c9c

Please sign in to comment.