Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
补充实现 Logs 清理
Browse files Browse the repository at this point in the history
  • Loading branch information
ricky8955555 committed Feb 4, 2021
1 parent 043683f commit eb17d56
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/Configurations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ namespace SeewoHelper
{
public static class Configurations
{
private static readonly string _path = Path.Combine(Constants.BaseDirectory, "configs");

/// <summary>
/// <see cref="SeewoHelper.CoursewareSortingInfo"/> 配置
/// </summary>
public static readonly Configuration<CoursewareSortingInfo> CoursewareSortingInfo = new Configuration<CoursewareSortingInfo>(Path.Combine(_path, "CoursewareSortingInfo.json"), new CoursewareSortingInfo());
public static readonly Configuration<CoursewareSortingInfo> CoursewareSortingInfo = new Configuration<CoursewareSortingInfo>(Path.Combine(Constants.ConfigurationPath, "CoursewareSortingInfo.json"), new CoursewareSortingInfo());

/// <summary>
/// <see cref="SeewoHelper.UISettings"/> 配置
/// </summary>
public static readonly Configuration<UISettings> UISettings = new Configuration<UISettings>(Path.Combine(_path, "UISettings.json"), new UISettings());
public static readonly Configuration<UISettings> UISettings = new Configuration<UISettings>(Path.Combine(Constants.ConfigurationPath, "UISettings.json"), new UISettings());
}
}
11 changes: 11 additions & 0 deletions src/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;

Expand Down Expand Up @@ -39,5 +40,15 @@ public static class Constants
/// 应用运行文件夹路径
/// </summary>
public static readonly string BaseDirectory = Environment.CurrentDirectory;

/// <summary>
/// 日志路径
/// </summary>
public static readonly string LogPath = Path.Combine(BaseDirectory, "logs");

/// <summary>
/// 配置路径
/// </summary>
public static readonly string ConfigurationPath = Path.Combine(BaseDirectory, "configs");
}
}
1 change: 1 addition & 0 deletions src/Forms/WindowMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/Forms/WindowMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private async void ButtonStartCoursewareSorting_Click(object sender, EventArgs e
{
var path = textBoxCoursewareSortingSearchingPath.Text;

if (IOUtilities.IsProperPath(path) && IOUtilities.GetPathType(path) == PathType.Directionary && Directory.Exists(path))
if (!string.IsNullOrWhiteSpace(path) && IOUtilities.IsProperPath(path) && IOUtilities.GetPathType(path) == PathType.Directionary && Directory.Exists(path))
{
var infos = listViewSubjectStorageInfos.Items.Cast<ListViewItem>().Select(x => (SubjectStorageInfo)x.Tag);

Expand Down Expand Up @@ -209,5 +209,13 @@ private void CheckBoxAutoStart_ValueChanged(object sender, bool value)
{
AutoStartUtilities.SetMeStart(checkBoxAutoStart.Checked);
}

private void ButtonCleanLog_Click(object sender, EventArgs e)
{
foreach (var file in Directory.GetFiles(Constants.LogPath).Where(x => x != Program.Logger.Path))
{
File.Delete(file);
}
}
}
}
}
2 changes: 1 addition & 1 deletion src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace SeewoHelper
{
static class Program
{
public static Logger Logger { get; } = new Logger(Path.Combine(Constants.BaseDirectory, "logs", DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".log"));
public static Logger Logger { get; } = new Logger(Path.Combine(Constants.LogPath, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".log"));

public static FormStyleController FormStyleController { get; } = new FormStyleController();

Expand Down

0 comments on commit eb17d56

Please sign in to comment.