Skip to content

Commit 44db3ae

Browse files
Write to user dir. if user profiles are enabled
Write the cover art cache and update content to the user directory when user profiles are enabled.
1 parent 479548b commit 44db3ae

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed

CUERipper.Avalonia/App.axaml.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ public override void OnFrameworkInitializationCompleted()
6868
{
6969
var services = new ServiceCollection();
7070

71+
EnsureUserDirectoryExists();
72+
7173
// Register services and viewmodels
7274
ConfigureServices(services);
7375

@@ -161,7 +163,7 @@ private static void OnApplicationShutdown(ServiceProvider serviceProvider)
161163

162164
if (!Design.IsDesignMode)
163165
{
164-
var fileInDir = Directory.GetFiles($"{Constants.PathImageCache}", $"*{Constants.JpgExtension}", SearchOption.TopDirectoryOnly);
166+
var fileInDir = Directory.GetFiles(Constants.PathImageCache, $"*{Constants.JpgExtension}", SearchOption.TopDirectoryOnly);
165167
foreach (var file in fileInDir)
166168
{
167169
File.Delete(file);
@@ -181,5 +183,13 @@ private void DisableAvaloniaDataAnnotationValidation()
181183
BindingPlugins.DataValidators.Remove(plugin);
182184
}
183185
}
186+
187+
private void EnsureUserDirectoryExists()
188+
{
189+
if (!Directory.Exists(Constants.ProfileDir))
190+
{
191+
Directory.CreateDirectory(Constants.ProfileDir);
192+
}
193+
}
184194
}
185195
}

CUERipper.Avalonia/Configuration/CUEConfigFacade.cs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,7 @@ public static CUEConfigFacade Create()
115115

116116
if (!Design.IsDesignMode)
117117
{
118-
#if NET47
119-
var appDirectory = AppDomain.CurrentDomain.BaseDirectory;
120-
#else
121-
var appDirectory = Environment.ProcessPath;
122-
#endif
123-
124-
var settingsReader = new SettingsReader("CUERipper", "settings.txt", appDirectory);
118+
var settingsReader = new SettingsReader(Constants.ApplicationUserContentFolder, "settings.txt", Constants.ApplicationPath);
125119
cueConfig.Load(settingsReader);
126120

127121
try
@@ -163,13 +157,7 @@ public static CUEConfigFacade Create()
163157
private readonly static XmlWriterSettings xmlEmptySettings = new() { Indent = true, OmitXmlDeclaration = true };
164158
public void Save()
165159
{
166-
#if NET47
167-
var appDirectory = AppDomain.CurrentDomain.BaseDirectory;
168-
#else
169-
var appDirectory = Environment.ProcessPath;
170-
#endif
171-
172-
var sw = new SettingsWriter("CUERipper", "settings.txt", appDirectory);
160+
var sw = new SettingsWriter(Constants.ApplicationUserContentFolder, "settings.txt", Constants.ApplicationPath);
173161
_cueConfig.Save(sw);
174162

175163
sw.Save("OutputAudioType", (int)OutputCompression);

CUERipper.Avalonia/Constants.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ You should have received a copy of the GNU General Public License along
1717
*/
1818
#endregion
1919
using CUETools.Processor;
20+
using CUETools.Processor.Settings;
21+
using System;
22+
using System.IO;
2023

2124
namespace CUERipper.Avalonia
2225
{
@@ -45,8 +48,6 @@ public static class Constants
4548
public const string ApplicationName = $"CUERipper.Avalonia {CUESheet.CUEToolsVersion}";
4649

4750
public const string PathNoto = "avares://CUERipper.Avalonia/Assets/noto-emoji/32/";
48-
public const string PathImageCache = "./CUERipper/.AlbumCache/";
49-
public const string PathUpdate = "./.cueupdate/";
5051

5152
public const int HiResImageMaxDimension = 2048;
5253

@@ -58,5 +59,18 @@ public static class Constants
5859
public const int MaxCoverFetchConcurrency = 4;
5960

6061
public const char NullDrive = '\0';
62+
63+
64+
public const string ApplicationUserContentFolder = "CUERipper";
65+
#if NET47
66+
public static readonly string ApplicationPath = AppDomain.CurrentDomain.BaseDirectory;
67+
#else
68+
public static readonly string ApplicationPath = Environment.ProcessPath ?? throw new NullReferenceException("Can't determine path.");
69+
#endif
70+
public static readonly string ProfileDir = SettingsShared.GetProfileDir(ApplicationUserContentFolder, ApplicationPath);
71+
72+
public static readonly string PathImageCache = Path.Combine(ProfileDir, ".AlbumCache/");
73+
public static readonly string PathUpdateFolder = Path.Combine(ProfileDir, ".cueupdate/");
74+
public static readonly string PathUpdateCacheFile = Path.Combine(ProfileDir, "CT_LAST_UPDATE_CHECK");
6175
}
6276
}

CUERipper.Avalonia/Services/UpdateService.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ namespace CUERipper.Avalonia.Services
2020
{
2121
public class UpdateService : IUpdateService
2222
{
23-
private const string UpdateCheckFilePath = "CT_LAST_UPDATE_CHECK";
24-
2523
private readonly HttpClient _httpClient;
2624
private readonly ICUEConfigFacade _config;
2725
private readonly ILogger _logger;
@@ -137,19 +135,19 @@ private async Task<GithubReleaseContainer> GetLatestReleaseAsync()
137135
/// <returns></returns>
138136
private GithubReleaseContainer GetLatestReleaseFromDiskCache()
139137
{
140-
if (!File.Exists(UpdateCheckFilePath)) return new(false, null, null);
138+
if (!File.Exists(Constants.PathUpdateCacheFile)) return new(false, null, null);
141139

142-
string[] content = File.ReadAllLines(UpdateCheckFilePath);
140+
string[] content = File.ReadAllLines(Constants.PathUpdateCacheFile);
143141
if (content.Length != 4)
144142
{
145-
_logger.LogError("Content of {File} is incorrect.", UpdateCheckFilePath);
143+
_logger.LogError("Content of {File} is incorrect.", Constants.PathUpdateCacheFile);
146144
return new(false, null, null);
147145
}
148146

149147
if (!DateTime.TryParseExact(content[0], "yyyyMMdd", null, System.Globalization.DateTimeStyles.None
150148
, out DateTime lastUpdateCheck))
151149
{
152-
_logger.LogError("Content of {File} is incorrect, can't parse to datetime.", UpdateCheckFilePath);
150+
_logger.LogError("Content of {File} is incorrect, can't parse to datetime.", Constants.PathUpdateCacheFile);
153151
return new(false, null, null);
154152
}
155153

@@ -188,7 +186,7 @@ private void WriteReleasesToDiskCache(GithubRelease? githubRelease, string? auth
188186
fileContent.Append(Environment.NewLine);
189187
fileContent.Append("EOF");
190188

191-
File.WriteAllText(UpdateCheckFilePath, fileContent.ToString());
189+
File.WriteAllText(Constants.PathUpdateCacheFile, fileContent.ToString());
192190
}
193191
catch (Exception ex)
194192
{
@@ -269,15 +267,15 @@ public async Task<bool> DownloadAsync(EventHandler<GenericProgressEventArgs> pro
269267
{
270268
if (!UpdateMetadata.UpdateAvailable()) return false;
271269

272-
if (!Directory.Exists(Constants.PathUpdate))
270+
if (!Directory.Exists(Constants.PathUpdateFolder))
273271
{
274-
Directory.CreateDirectory(Constants.PathUpdate);
272+
Directory.CreateDirectory(Constants.PathUpdateFolder);
275273
}
276274

277275
try
278276
{
279-
var setupFile = $"{Constants.PathUpdate}Update-{UpdateMetadata!.Version}.exe";
280-
var hashFile = $"{Constants.PathUpdate}Update-{UpdateMetadata.Version}.sha256";
277+
var setupFile = $"{Constants.PathUpdateFolder}Update-{UpdateMetadata!.Version}.exe";
278+
var hashFile = $"{Constants.PathUpdateFolder}Update-{UpdateMetadata.Version}.sha256";
281279

282280
await DownloadFile(UpdateMetadata!.Uri
283281
, contentSize: UpdateMetadata.Size
@@ -340,7 +338,7 @@ private bool VerifyFile(string setupFile, string hashFile)
340338

341339
public void Install()
342340
{
343-
var setupFile = $"{Constants.PathUpdate}Update-{UpdateMetadata!.Version}.exe";
341+
var setupFile = $"{Constants.PathUpdateFolder}Update-{UpdateMetadata!.Version}.exe";
344342
Process.Start(new ProcessStartInfo
345343
{
346344
FileName = Path.GetFullPath(setupFile),

CUETools.Processor/Settings/SettingsShared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
namespace CUETools.Processor.Settings
55
{
6-
static class SettingsShared
6+
public static class SettingsShared
77
{
88
public static string GetMyAppDataDir(string appName)
99
{

0 commit comments

Comments
 (0)