Skip to content

Commit

Permalink
Work in Progress: Better portability
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielGausi committed Apr 11, 2020
1 parent ba64558 commit 5ab9465
Show file tree
Hide file tree
Showing 17 changed files with 2,316 additions and 885 deletions.
114 changes: 85 additions & 29 deletions src/AudioFileHelper.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
interface

uses Windows, Classes, Contnrs, SysUtils, StrUtils, Math, IniFiles, Dialogs,
Nemp_ConstantsAndTypes, Hilfsfunktionen, NempAudioFiles, DateUtils, System.UITypes;
Nemp_ConstantsAndTypes, Hilfsfunktionen, NempAudioFiles, DriveRepairTools,
DateUtils, System.UITypes;

const SORT_MAX = 10;

Expand Down Expand Up @@ -82,10 +83,10 @@ procedure SynchNewFileWithBib(aNewFile: TAudioFile; WithCover: Boolean = True);
procedure SynchAFileWithDisc(aNewFile: TAudioFile; WithCover: Boolean = True);


procedure LoadPlaylistFromFile(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean);
procedure LoadPlaylistFromFile(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean; aDriveManager: TDriveManager);
procedure LoadPlaylistFromFileM3U8(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean);
procedure LoadPlaylistFromFilePLS(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean);
procedure LoadPlaylistFromFileNPL(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean);
procedure LoadPlaylistFromFileNPL(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean; aDriveManager: TDriveManager);
procedure LoadPlaylistFromFileASX(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean);


Expand Down Expand Up @@ -924,17 +925,23 @@ procedure LoadPlaylistFromFilePLS(aFilename: UnicodeString; TargetList: TObjectL
end;


procedure LoadPlaylistFromFileNPL(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean);
procedure LoadPlaylistFromFileNPL(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean; aDriveManager: TDriveManager);
var aStream: TFileStream;
NPLHeader: AnsiString;
FileCount, i: Integer;
NewAudioFile: TAudioFile;
NPLVersion: AnsiString;
FileIsCurrentVersion, SupportedFormat: Boolean;

SavedDriveList: TDriveList;
currentDriveID: Integer;
CurrentDriveChar: Char;

const
Check1: AnsiString = 'NempPlaylist';
Deprecatd_Version: AnsiString = '3.1';
Current_Version : AnsiString = '5.0'; // like in the GMP, new in Nemp 4.13
Deprecatd_Version : AnsiString = '3.1';
Current_Version : AnsiString = '5.0'; // like in the GMP, new in Nemp 4.13
Current_Version_Ext : AnsiString = '5.1'; // additional Drive-Information stored at the beginning of the File

begin
try
Expand All @@ -952,32 +959,79 @@ procedure LoadPlaylistFromFileNPL(aFilename: UnicodeString; TargetList: TObjectL
if (NPLVersion = Current_Version) then
FileIsCurrentVersion := True;

SupportedFormat := (NPLVersion = Deprecatd_Version) OR (NPLVersion = Current_Version);
SupportedFormat := (NPLVersion = Deprecatd_Version)
or (NPLVersion = Current_Version)
or (NPLVersion = Current_Version_Ext);

if (NPLHeader = Check1) AND SupportedFormat then // file starts with "NempPlaylist"
begin
SavedDriveList := TDriveList.Create(True);
try
// new in Nemp 4.14: NPL-Files also contain Drive-Information about the used TDrives
// These are used to fix Drive Letters just as the MediaLibrary does it for a long time now...
if NPLVersion = Current_Version_Ext then
begin
aDriveManager.LoadDrivesFromStream(aStream, SavedDriveList);
aDriveManager.SynchronizeDrives(SavedDriveList);
end;

// initialise variables for fixing Drive Letters
CurrentDriveChar := ' ';
currentDriveID := -2;

// Read the AudioFiles from the Stream
aStream.Read(FileCount, SizeOf(Integer));
for i := 1 to FileCount do
begin
NewAudioFile := TAudioFile.Create;
if FileIsCurrentVersion then
NewAudioFile.LoadDataFromStream(aStream, True, False)
else
NewAudioFile.LoadFromStreamForPlaylist_DEPRECATED(aStream);

if NewAudioFile.isCDDA then
SetCDDADefaultInformation(NewAudioFile);

// Nemp Version 4.14 or later:
// NPL-Files contain TDrives-Information to fix Drive Letters
if NPLVersion = Current_Version_Ext then
begin
if newAudioFile.DriveID <> -5 then
begin
if currentDriveID <> newAudioFile.DriveID then
begin
// currentDriveChar does not match, we need to find the correct one
if newAudioFile.DriveID <= -1 then
CurrentDriveChar := '\'
else
begin
if newAudioFile.DriveID < SavedDriveList.Count then
CurrentDriveChar := SavedDriveList[newAudioFile.DriveID].Drive[1]
else // something is wrong with the file here
begin
MessageDlg('Invalid playlist: Invalid AudioData: DriveID not found.', mtError, [mbOK], 0);
break;
end;
end;
// anyway, we've got a new ID here, and we can set the next drive with this ID faster
currentDriveID := newAudioFile.DriveID;
end;
// now *actually* assign the proper drive letter ;-)
newAudioFile.SetNewDriveChar(CurrentDriveChar);
end;
end;

aStream.Read(FileCount, SizeOf(Integer));
for i := 1 to FileCount do
begin
NewAudioFile := TAudioFile.Create;
if FileIsCurrentVersion then
NewAudioFile.LoadDataFromStream(aStream, True)
else
NewAudioFile.LoadFromStreamForPlaylist_DEPRECATED(aStream);

if NewAudioFile.isCDDA then
SetCDDADefaultInformation(NewAudioFile);

//if NewAudioFile.isStream then
// NewAudioFile.Description := NewAudioFile.Titel;
// after that: scan the file (if wanted)
if AutoScan then
NewAudioFile.ReCheckExistence
else
NewAudioFile.FileIsPresent := True;

if AutoScan then
NewAudioFile.ReCheckExistence
else
NewAudioFile.FileIsPresent := True;
TargetList.Add(NewAudioFile);
end;

TargetList.Add(NewAudioFile);
finally
SavedDriveList.Free;
end;
end else
MessageDlg('Invalid playlist', mtError, [mbOK], 0);
Expand Down Expand Up @@ -1059,8 +1113,7 @@ procedure LoadPlaylistFromFileASX(aFilename: UnicodeString; TargetList: TObjectL
end;



procedure LoadPlaylistFromFile(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean);
procedure LoadPlaylistFromFile(aFilename: UnicodeString; TargetList: TObjectList; AutoScan: Boolean; aDriveManager: TDriveManager);
var ext: UnicodeString;
begin
// Evtl. Todo in Zukunft:
Expand All @@ -1070,6 +1123,9 @@ procedure LoadPlaylistFromFile(aFilename: UnicodeString; TargetList: TObjectList
if Not FileExists(aFilename) then
exit;

// !!! LoadPlaylistFromFile is called with aDriveManager=NIL from downloaded Shoutcast-Playlists
// => Never use the DriveManager in files coming frome there (i.e. only for our own *.npl-files)

SetCurrentDir(ExtractFilePath(aFileName));

ext := LowerCase(ExtractFileExt(aFilename));
Expand All @@ -1084,7 +1140,7 @@ procedure LoadPlaylistFromFile(aFilename: UnicodeString; TargetList: TObjectList
LoadPlaylistFromFilePLS(aFilename, TargetList, AutoScan)
else
if ext = '.npl' then
LoadPlaylistFromFileNPL(aFilename, TargetList, AutoScan)
LoadPlaylistFromFileNPL(aFilename, TargetList, AutoScan, aDriveManager)
else
if (ext = '.asx') or (ext = '.wax') then
LoadPlaylistFromFileASX(aFilename, TargetList, AutoScan);
Expand Down
8 changes: 7 additions & 1 deletion src/CreateHelper.pas
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ implementation
MedienbibliothekClass, Nemp_SkinSystem, Spectrum_vis,
Nemp_ConstantsAndTypes, NempApi, NempAudioFiles, Nemp_RessourceStrings,
MainFormHelper, UpdateUtils, SystemHelper, TreeHelper, languagecodes,
SplitForm_Hilfsfunktionen, Mp3FileUtils,
SplitForm_Hilfsfunktionen, Mp3FileUtils, DriveRepairTools,

MedienListeUnit, AuswahlUnit, ExtendedControlsUnit, PlaylistUnit,
WindowsVersionInfo;
Expand Down Expand Up @@ -102,6 +102,11 @@ function LoadSettings: Boolean;


ReadNempOptions(ini, NempOptions, NempFormBuildOptions);
// Read Portable settings
TDrivemanager.EnableUSBMode := ini.ReadBool('Nemp Portable','EnableUSBMode' , True);
TDrivemanager.EnableCloudMode := ini.ReadBool('Nemp Portable','EnableCloudMode' , True);


if NempOptions.Language = '' then
// overwrite the default setting with the curent system language
NempOptions.Language := GetCurrentLanguage;
Expand Down Expand Up @@ -215,6 +220,7 @@ function LoadSettings: Boolean;
end;
}
SetRecentPlaylistsMenuItems;
SetPlaylistManagerMenuItems;

end;
end;
Expand Down
Loading

0 comments on commit 5ab9465

Please sign in to comment.