Skip to content

Commit

Permalink
LoadEntries fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Oleynikov committed Dec 8, 2019
1 parent e688c37 commit df3c77d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
9 changes: 3 additions & 6 deletions NightscoutWatcher.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<MajorVersionNr Value="2"/>
<MinorVersionNr Value="11"/>
<RevisionNr Value="1"/>
<BuildNr Value="121"/>
<BuildNr Value="122"/>
<StringTable CompanyName="Sergey Oleynikov" LegalCopyright="Sergey Oleynikov" ProductName="Nightscout Watcher"/>
</VersionInfo>
<BuildModes Count="3">
Expand Down Expand Up @@ -119,13 +119,10 @@
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<RequiredPackages Count="2">
<RequiredPackages Count="1">
<Item1>
<PackageName Value="laz_acs_lib"/>
</Item1>
<Item2>
<PackageName Value="LCL"/>
</Item2>
</Item1>
</RequiredPackages>
<Units Count="6">
<Unit0>
Expand Down
2 changes: 1 addition & 1 deletion forms/ufMain.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ function TfMain.LoadEntriesData: Boolean;
IsFileDownloaded: Boolean;
begin
Result := False;
FileName := './entries.tsv';
FileName := TSettings.GetEntriesFileName;
Entries.Clear;
if not DebugMode then
begin
Expand Down
43 changes: 28 additions & 15 deletions units/uSettings.pas
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ interface
TSettings = class
private
function GetEntryMinsWithTimeZoneCorrection(DateFirst, DateLast: TDateTime): Integer;
class function GetOptionDir(): string;
public
AlphaBlendValue: Integer;
AlarmAudioFile: string;
Expand Down Expand Up @@ -102,6 +103,7 @@ TSettings = class
WallpaperFileName: string;
WindowRect: TRect;
class function GetOptionFileName(): string;
class function GetEntriesFileName(): string;
class function IsPortable(): Boolean;
constructor Create();
function Clone(): TSettings;
Expand Down Expand Up @@ -511,33 +513,44 @@ class function TSettings.IsPortable(): Boolean;
Result := FileExists('Portable.lock');
end;

// Search Option.ini in the next order:
class function TSettings.GetOptionFileName(): string;
const
cOptionFileName = 'Options.ini';
begin
Result := IncludeTrailingBackslash(GetOptionDir) + cOptionFileName;
end;

class function TSettings.GetEntriesFileName(): string;
const
cEntriesFileName = 'entries.tsv';
begin
Result := IncludeTrailingBackslash(GetOptionDir) + cEntriesFileName;
end;

// Search Option dir in the next order:
// 1) \Users\<user>\AppData\Local\Nightscout Watcher\
// 2) \ProgramData\Nightscout Watcher\
// 3) \<current app dir>\
// The first one is default

class function TSettings.GetOptionFileName(): string;
const
cOptionFileName = 'Options.ini';
class function TSettings.GetOptionDir(): string;
var
UserLocalAppDataFile, ProgramDataFile, AppDirFile: String;
UserLocalAppDataDir, ProgramDataDir, AppDir: String;
begin
UserLocalAppDataFile := GetAppConfigDir(False) + cOptionFileName;
ProgramDataFile := GetAppConfigDir(True) + cOptionFileName;
AppDirFile := ExtractFilePath(ParamStr(0)) + cOptionFileName;
UserLocalAppDataDir := ExcludeTrailingBackslash(GetAppConfigDir(False));
ProgramDataDir := ExcludeTrailingBackslash(GetAppConfigDir(True));
AppDir := ExcludeTrailingBackslash(ExtractFilePath(ParamStr(0)));

if IsPortable() then
begin
Result := AppDirFile;
Result := AppDir;
Exit;
end;

Result := UserLocalAppDataFile;
if FileExists(ProgramDataFile) then
Result := ProgramDataFile
else if FileExists(AppDirFile) then
Result := AppDirFile;
Result := UserLocalAppDataDir;
if DirectoryExists(ProgramDataDir) then
Result := ProgramDataDir
else if DirectoryExists(AppDir) then
Result := AppDir;
end;

function TSettings.GetGlucoseLevelDateText(DateFirst, DateLast: TDateTime; out OutColor: TColor): string;
Expand Down

0 comments on commit df3c77d

Please sign in to comment.