-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (59 loc) · 2.25 KB
/
Program.cs
File metadata and controls
69 lines (59 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Avalonia;
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
namespace ShowWrite
{
internal class Program
{
[DllImport("kernel32.dll")]
private static extern bool AllocConsole();
[DllImport("kernel32.dll")]
private static extern bool FreeConsole();
public static bool RandomNoteMode { get; private set; }
public static List<string> FilesToOpen { get; private set; } = new List<string>();
private static readonly string[] SupportedImageExtensions = { ".jpg", ".jpeg", ".png", ".bmp", ".gif" };
private static readonly string[] SupportedPdfExtensions = { ".pdf" };
private static readonly string[] SupportedPptExtensions = { ".pptx", ".ppt" };
[STAThread]
public static void Main(string[] args)
{
foreach (var arg in args)
{
if (arg.Equals("--randomnote", StringComparison.OrdinalIgnoreCase) ||
arg.Equals("-rn", StringComparison.OrdinalIgnoreCase))
{
RandomNoteMode = true;
break;
}
var ext = Path.GetExtension(arg).ToLowerInvariant();
if (IsSupportedExtension(ext) && File.Exists(arg))
{
FilesToOpen.Add(arg);
}
}
if (!RandomNoteMode)
{
AllocConsole();
Console.Title = "ShowWrite - 控制台输出";
}
BuildAvaloniaApp().StartWithClassicDesktopLifetime(args);
}
private static bool IsSupportedExtension(string ext)
{
foreach (var supported in SupportedImageExtensions)
if (ext == supported) return true;
foreach (var supported in SupportedPdfExtensions)
if (ext == supported) return true;
foreach (var supported in SupportedPptExtensions)
if (ext == supported) return true;
return false;
}
public static AppBuilder BuildAvaloniaApp()
=> AppBuilder.Configure<App>()
.UsePlatformDetect()
.WithInterFont()
.LogToTrace();
}
}