Skip to content

Commit

Permalink
Fixed bugs and added some comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lekco1320 committed Feb 11, 2024
1 parent c44eef4 commit f11fe54
Show file tree
Hide file tree
Showing 18 changed files with 277 additions and 78 deletions.
93 changes: 82 additions & 11 deletions source/Promissum/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Lekco.Promissum.View;
using Lekco.Promissum.ViewModel;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
Expand All @@ -13,22 +14,51 @@
namespace Lekco.Promissum
{
/// <summary>
/// Interaction logic for App.xaml
/// The class of application Lekco Promissum.
/// </summary>
public partial class App : Application
{
/// <summary>
/// The directory of Lekco Promissum in AppData folder.
/// </summary>
public static readonly string AppDir;

/// <summary>
/// The temporary work directory.
/// </summary>
public static readonly string TempDir;

/// <summary>
/// The path of Lekco Promissum Agens.
/// </summary>
public static readonly string AgensPath;

/// <summary>
/// The name of application.
/// </summary>
public static readonly string Name;

/// <summary>
/// The list of command arguments of Lekco Promissum.
/// </summary>
public static readonly string[] Args;

/// <summary>
/// The version of current application.
/// </summary>
public static readonly Version Version;

private static readonly MainWindowVM _mainWindowVM;
private static readonly CancellationTokenSource _taskCancellation;

/// <summary>
/// The notify icon in task bar.
/// </summary>
public readonly NotifyIcon NotifyIcon;

/// <summary>
/// Create an instance of this type.
/// </summary>
public App()
{
InitializeComponent();
Expand All @@ -38,6 +68,9 @@ public App()
NotifyIcon = new NotifyIcon(this);
}

/// <summary>
/// The static constructor of this type.
/// </summary>
static App()
{
Name = "Lekco Promissum";
Expand All @@ -59,24 +92,27 @@ static App()
MenuLeftDisplay();
}

/// <summary>
/// Send arguments to open processes.
/// </summary>
private static void SendArgs()
{
var client = new PipeClient(".", "Lekco Promissum");
foreach (string s in Args)
var client = new PipeClient(".", Name);
for (int i = 1; i < Args.Length; i++)
{
if (File.Exists(s))
{
client.DoRequest(s);
}
client.DoRequest(Args[i]);
}
client.CloseServer();
}

/// <summary>
/// Set up a new server to receive messages sent from other processes.
/// </summary>
private void SetupServer()
{
var serverTask = new Task(() =>
{
var server = new PipeServer("Lekco Promissum");
var server = new PipeServer(Name);
server.Received += Receiving;
server.BeginReceive();
server.Close();
Expand All @@ -85,25 +121,45 @@ private void SetupServer()
serverTask.Start();
}

/// <summary>
/// Receive message from other processes.
/// </summary>
/// <param name="message">Message sent from other processes.</param>
private void Receiving(string message)
{
_mainWindowVM.OpenProject(message);
var files = new List<string>();
if (File.Exists(message))
{
files.Add(message);
}
Current.Dispatcher.BeginInvoke(() =>
{
foreach (var file in files)
{
_mainWindowVM.OpenProject(file);
}
MainWindow ??= new MainWindow(_mainWindowVM);
MainWindow.Show();
});
}

/// <summary>
/// The method to do after application started up completely.
/// </summary>
private void StartUp(object sender, StartupEventArgs e)
{
bool runBackground = false;
foreach (string s in Args)
for (int i = 1; i < Args.Length; i++)
{
if (s == "-background")
var arg = Args[i];
if (arg == "-background")
{
runBackground = true;
}
if (File.Exists(arg))
{
_mainWindowVM.OpenProject(arg);
}
}

if (!runBackground)
Expand All @@ -113,6 +169,9 @@ private void StartUp(object sender, StartupEventArgs e)
}
}

/// <summary>
/// Quit Lekco Promissum.
/// </summary>
public static void Quit()
{
SyncEngine.Dispose();
Expand All @@ -121,6 +180,9 @@ public static void Quit()
Current.Shutdown();
}

/// <summary>
/// Show main window.
/// </summary>
public void ShowMainWindow()
{
if (MainWindow is not View.MainWindow)
Expand All @@ -130,6 +192,9 @@ public void ShowMainWindow()
MainWindow.Show();
}

/// <summary>
/// Checks the temporary work directory's existence and delete all remain files.
/// </summary>
private static void CheckAppTempDir()
{
var dirInfo = new DirectoryInfo(TempDir);
Expand Down Expand Up @@ -162,13 +227,19 @@ private static void CheckAppTempDir()
}
}

/// <summary>
/// Occurs when quit Lekco Promissum.
/// </summary>
private void Exiting(object sender, ExitEventArgs e)
{
SyncEngine.Dispose();
Config.SaveAsFile();
_taskCancellation.Cancel();
}

/// <summary>
/// A helper method to make MenuItem show left.
/// </summary>
private static void MenuLeftDisplay()
{
var ifLeft = SystemParameters.MenuDropAlignment;
Expand Down
8 changes: 5 additions & 3 deletions source/Promissum/Apps/SyncController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;

namespace Lekco.Promissum.Apps
Expand Down Expand Up @@ -171,11 +172,12 @@ public void SetManagingDeletingFilesState()
UpdateDescription();
}

public bool CanManageDeletingFiles(IReadOnlyCollection<FileInfo> deletingFiles)
public bool CanManageDeletingFileRecords(IReadOnlyCollection<DeletionFileRecord> deletingFileRecords)
{
_foundDeletingFilesCount = deletingFiles.Count;
_foundDeletingFilesCount = deletingFileRecords.Count;
IsIndeterminate = false;
UpdateDescription();
var filesList = deletingFileRecords.Select(record => new FileInfo(record.NewFileName!));
return _foundDeletingFilesCount > 0 && (!Config.AlwaysTellsMeWhenDeleteFiles ||
MessageWindow.ShowDialog(
message: $"本次备份将删除{_foundDeletingFilesCount}份过期文件,是否删除?",
Expand All @@ -185,7 +187,7 @@ public bool CanManageDeletingFiles(IReadOnlyCollection<FileInfo> deletingFiles)
autoCountDown: true,
mandatoryTopMost: true,
link: "查看待删除文件",
linkAction: new Action(() => FilesListWindow.ShowFilesList(deletingFiles))
linkAction: new Action(() => FilesListWindow.ShowFilesList(filesList))
));
}

Expand Down
Loading

0 comments on commit f11fe54

Please # to comment.