Skip to content

Commit

Permalink
[Release 0.1.1] Update
Browse files Browse the repository at this point in the history
[Release 0.1.1] Update
  • Loading branch information
AuroraZiling authored Oct 23, 2024
2 parents a060c8c + dc91806 commit 7151469
Show file tree
Hide file tree
Showing 34 changed files with 169 additions and 827 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

<br />
<div align="center">
<a href="https://github.com/Pip-Manager/PipManager.Wpf">
<img src="https://raw.githubusercontent.com/Pip-Manager/PipManager.Wpf/main/src/PipManager/Assets/icon.png" alt="Logo" width="80" height="80">
<a href="https://github.com/Pip-Manager/PipManager.Windows">
<img src="https://raw.githubusercontent.com/Pip-Manager/PipManager.Windows/refs/heads/main/src/Assets/icon.png" alt="Logo" width="80" height="80">
</a>

<h3 align="center">Pip Manager</h3>
Expand All @@ -14,11 +14,11 @@
<a href="https://pipmanager.dev"><strong>Explore the docs (Chinese Simplified) »</strong></a>
<br />
<br />
<a href="https://github.com/Pip-Manager/PipManager.Wpf?tab=readme-ov-file#screenshots">Screenshots</a>
<a href="https://github.com/Pip-Manager/PipManager.Windows?tab=readme-ov-file#screenshots">Screenshots</a>
·
<a href="https://github.com/Pip-Manager/PipManager.Wpf/issues">Report Bug</a>
<a href="https://github.com/Pip-Manager/PipManager.Windows/issues">Report Bug</a>
·
<a href="https://github.com/Pip-Manager/PipManager.Wpf/pulls">Request Feature</a>
<a href="https://github.com/Pip-Manager/PipManager.Windows/pulls">Request Feature</a>
</p>
</div>

Expand Down Expand Up @@ -70,13 +70,11 @@ Double click `PipManager.exe` or `PipManager_withRuntime.exe` *If you have not i
### Arguments

- `/console`: Show console while program running
- `/experiment`: Enable a secret page for test *Currently this feature is useless*

<p align="right">(<a href="#readme-top">back to top</a>)</p>

See the [Open Issues](https://github.com/Pip-Manager/PipManager.Wpf/issues) for a full list of proposed features (and known issues).


## Contributing

1. Fork the Project
Expand Down
17 changes: 2 additions & 15 deletions src/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using PipManager.Core.Services.PackageSearchService;
using PipManager.Windows.Services;
using PipManager.Windows.Services.Action;
using PipManager.Windows.Services.Configuration;
using PipManager.Windows.Services.Environment;
using PipManager.Windows.Services.Mask;
using PipManager.Windows.Services.Overlay;
Expand Down Expand Up @@ -39,9 +38,6 @@
namespace PipManager.Windows;

using AboutViewModel = ViewModels.Pages.About.AboutViewModel;
using ActionViewModel = ViewModels.Pages.Action.ActionViewModel;
using LibraryViewModel = ViewModels.Pages.Library.LibraryViewModel;
using SearchViewModel = ViewModels.Pages.Search.SearchViewModel;
using SettingsViewModel = ViewModels.Pages.Settings.SettingsViewModel;

/// <summary>
Expand Down Expand Up @@ -78,7 +74,6 @@ public partial class App
services.AddSingleton<ISnackbarService, SnackbarService>();
services.AddSingleton<IMaskService, MaskService>();
services.AddSingleton<IToastService, ToastService>();
services.AddSingleton<IConfigurationService, ConfigurationService>();
services.AddSingleton<IEnvironmentService, EnvironmentService>();
services.AddSingleton<IActionService, ActionService>();
services.AddSingleton<IThemeService, ThemeService>();
Expand Down Expand Up @@ -141,7 +136,7 @@ public static T GetService<T>()
private static partial void FreeConsole();

private bool _showConsoleWindow;
private bool _experimentMode;
public static bool IsDebugMode { get; private set; }

/// <summary>
/// Occurs when the application is loading.
Expand All @@ -157,10 +152,6 @@ private void OnStartup(object sender, StartupEventArgs e)
case "/debug":
_showConsoleWindow = true;
break;

case "/experiment":
_experimentMode = true;
break;
}
}
var appStarting = new AppStarting
Expand All @@ -169,13 +160,9 @@ private void OnStartup(object sender, StartupEventArgs e)
};
appStarting.StartLogging();
appStarting.LoadLanguage();
appStarting.LogDeletion();
appStarting.CrushesDeletion();
appStarting.CachesDeletion();
Host.Start();
GetService<IConfigurationService>().DebugMode = _showConsoleWindow;
GetService<IConfigurationService>().ExperimentMode = _experimentMode;
GetService<MainWindowViewModel>().ExperimentMode = _experimentMode;
IsDebugMode = _showConsoleWindow;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/AppInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class AppInfo
{
public static readonly string AppVersion = Assembly.GetExecutingAssembly().GetName().Version!.ToString(3);

public static readonly string ConfigPath = Path.Combine(Directory.GetCurrentDirectory(), "config.json");
public static readonly string ConfigDirectory = Directory.GetCurrentDirectory();
public static readonly string CrushesDir = Path.Combine(Directory.GetCurrentDirectory(), "crashes");
public static readonly string LogDir = Path.Combine(Directory.GetCurrentDirectory(), "logs");
public static readonly string CachesDir = Path.Combine(Directory.GetCurrentDirectory(), "caches");
Expand Down
87 changes: 10 additions & 77 deletions src/AppStarting.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using PipManager.Windows.Services.Configuration;
using Serilog;
using Serilog;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
using PipManager.Windows.Helpers;
using PipManager.Windows.Models;
using PipManager.Core.Configuration;

namespace PipManager.Windows;

Expand All @@ -14,20 +12,19 @@ public partial class AppStarting
[return: MarshalAs(UnmanagedType.Bool)]
private static partial void AllocConsole();

private readonly AppConfig _config;
public bool ShowConsoleWindow = false;

public AppStarting()
{
_config = ConfigurationService.LoadConfiguration();
Configuration.Initialize(AppInfo.ConfigDirectory);
Directory.CreateDirectory(AppInfo.CrushesDir);
Directory.CreateDirectory(AppInfo.LogDir);
Directory.CreateDirectory(AppInfo.CachesDir);
}

public void LoadLanguage()
{
var language = _config.Personalization.Language;
var language = Configuration.AppConfig!.Personalization.Language;
if (language != "Auto")
{
I18NExtension.Culture = new CultureInfo(language);
Expand All @@ -40,80 +37,16 @@ public void StartLogging()
if (ShowConsoleWindow)
{
AllocConsole();
Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("Version", AppInfo.AppVersion)
.MinimumLevel.Debug()
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] (Thread: {ThreadId}) {Message}{NewLine}{Exception}")
.Enrich.With(new ThreadIdEnricher())
.WriteTo.File(Path.Combine(AppInfo.LogDir, $"log_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.txt"), outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] (Thread: {ThreadId}) {Message}{NewLine}{Exception}")
.CreateLogger();
}
else
{
Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("Version", AppInfo.AppVersion)
.MinimumLevel.Debug()
.Enrich.With(new ThreadIdEnricher())
.WriteTo.File(Path.Combine(AppInfo.LogDir, $"log_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}.txt"), outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] (Thread: {ThreadId}) {Message}{NewLine}{Exception}")
.CreateLogger();
}
Log.Logger = new LoggerConfiguration()
.Enrich.WithProperty("Version", AppInfo.AppVersion)
.MinimumLevel.Debug()
.WriteTo.Console(outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}")
.WriteTo.File(Path.Combine(AppInfo.LogDir, "log_.txt"), outputTemplate: "{Timestamp:HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true)
.CreateLogger();
Log.Information("Logging started");
}

public void LogDeletion()
{
if (!_config.Personalization.LogAutoDeletion || !Directory.Exists(AppInfo.LogDir)) return;
var fileList = Directory.GetFileSystemEntries(AppInfo.LogDir);
var logFileAmount = fileList.Count(file => File.Exists(file) && file.EndsWith(".txt"));
if (logFileAmount < _config.Personalization.LogAutoDeletionTimes)
{
return;
}

var directoryInfo = new DirectoryInfo(AppInfo.LogDir);
var filesInfo = directoryInfo.GetFileSystemInfos();
foreach (var file in filesInfo)
{
if (file.Extension != ".txt") continue;
try
{
File.Delete(file.FullName);
}
catch
{
Log.Warning("Failed to delete log: {FileFullName}", file.FullName);
}
}
Log.Information($"{logFileAmount} log file(s) deleted");
}

public void CrushesDeletion()
{
if (!_config.Personalization.CrushesAutoDeletion || !Directory.Exists(AppInfo.CrushesDir)) return;
var fileList = Directory.GetFileSystemEntries(AppInfo.CrushesDir);
var crushFileAmount = fileList.Count(file => File.Exists(file) && file.EndsWith(".txt"));
if (crushFileAmount < _config.Personalization.CrushesAutoDeletionTimes)
{
return;
}

var directoryInfo = new DirectoryInfo(AppInfo.CrushesDir);
var filesInfo = directoryInfo.GetFileSystemInfos();
foreach (var file in filesInfo)
{
if (file.Extension != ".txt") continue;
try
{
File.Delete(file.FullName);
}
catch
{
Log.Warning("Failed to delete crush file: {FileFullName}", file.FullName);
}
}
Log.Information($"{crushFileAmount} crush file(s) deleted");
}

public void CachesDeletion()
{
if (!Directory.Exists(AppInfo.CachesDir)) return;
Expand Down
29 changes: 18 additions & 11 deletions src/Converters/PackageSourceEnumToBooleanConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,35 @@ internal class PackageSourceEnumToBooleanConverter : IValueConverter
{
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (parameter is not string enumString)
if (value == null || parameter == null)
{
throw new ArgumentException("ExceptionPackageSourceTypeToBooleanConverterParameterMustBeAnEnumName");
return false;
}

if (value != null && !Enum.IsDefined(typeof(PackageSourceType), value))
var currentPackageSource = (string)value;
var currentParameter = (string)parameter;

if (currentPackageSource == "default" && currentParameter == "Official")
{
throw new ArgumentException("ExceptionPackageSourceTypeToBooleanConverterValueMustBeAnEnum");
return true;
}

var enumValue = Enum.Parse(typeof(PackageSourceType), enumString);

return enumValue.Equals(value);
return currentPackageSource.Equals(currentParameter, StringComparison.OrdinalIgnoreCase);
}

public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (parameter is not string enumString)
if (value == null || parameter == null)
{
throw new ArgumentException("ExceptionPackageSourceTypeToBooleanConverterParameterMustBeAnEnumName");
return "default";
}

return Enum.Parse(typeof(PackageSourceType), enumString);
var isChecked = (bool)value;
var currentParameter = (string)parameter;

if (isChecked)
{
return currentParameter == "Official" ? "default" : currentParameter;
}
return "default";
}
}
46 changes: 0 additions & 46 deletions src/Helpers/PackageValidator.cs

This file was deleted.

13 changes: 0 additions & 13 deletions src/Helpers/ThreadIdEnricher.cs

This file was deleted.

12 changes: 0 additions & 12 deletions src/Models/AppConfig.cs

This file was deleted.

23 changes: 0 additions & 23 deletions src/Models/AppConfigModels/EnvironmentItem.cs

This file was deleted.

10 changes: 0 additions & 10 deletions src/Models/AppConfigModels/PackageSource.cs

This file was deleted.

Loading

0 comments on commit 7151469

Please sign in to comment.