-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
executable file
·105 lines (94 loc) · 2.97 KB
/
Program.cs
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using Pfs.Fuse;
using Pfs.Plex;
namespace Pfs
{
public static class Program
{
private static bool _terminateReceived;
private static FuseFileSystem _fs;
private static void HandleFatalException(Exception ex)
{
Debug.WriteLine(ex?.Message);
Debug.WriteLine(ex?.StackTrace);
if (_terminateReceived)
{
Environment.Exit(1);
}
_terminateReceived = true;
try
{
if (!IsWindows())
{
_fs?.UnMount();
}
Environment.Exit(1);
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
Environment.Exit(1);
}
}
private static bool IsWindows()
{
var env = Environment.OSVersion.Platform;
return env == PlatformID.Win32NT ||
env == PlatformID.Win32S ||
env == PlatformID.Win32Windows ||
env == PlatformID.WinCE ||
env == PlatformID.Xbox;
}
private static void WindowsMain()
{
Console.WriteLine("In interactive query mode. Write a file path and press return to query.");
Console.WriteLine("An empty line terminates input.");
Console.WriteLine("-----------");
while (true)
{
Console.Write("> ");
var line = Console.ReadLine();
if (string.IsNullOrWhiteSpace(line))
{
break;
}
Console.WriteLine(_fs.TestInput(line));
}
}
public static async Task Main()
{
AppDomain.CurrentDomain.UnhandledException +=
(sender, e) => HandleFatalException(e.ExceptionObject as Exception);
var config = Configuration.LoadConfig();
if (string.IsNullOrWhiteSpace(config.Cid) || string.IsNullOrWhiteSpace(config.Token))
{
var (cid, token) = await PlexOAuth.GetLoginDetails();
config.Cid = cid;
config.Token = token;
if (config.SaveLoginDetails)
{
Configuration.SaveConfig(config);
}
}
try
{
_fs = new FuseFileSystem(config);
if (IsWindows())
{
WindowsMain();
}
else
{
_fs.Mount();
}
}
catch (Exception e)
{
HandleFatalException(e);
}
}
}
}