This repository was archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
83 lines (78 loc) · 2.6 KB
/
Copy pathProgram.cs
File metadata and controls
83 lines (78 loc) · 2.6 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace Handoff
{
internal class Program
{
[DllImport("kernel32.dll")]
static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;
static void Main(string[] args)
{
var handle = GetConsoleWindow();
// Hide
ShowWindow(handle, SW_HIDE);
if (args.Length != 0 && args[0].Contains("--setup"))
{
if(args[0] != "--setup-admin") Elevate();
string DocuPath = HandoffToken.GetOrDefault();
string FdPath = DocuPath + "\\InstallationPath.handoff";
StreamWriter a = File.CreateText(FdPath);
a.Write(DocuPath);
a.Close();
using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("freedeck"))
{
if (key != null)
{
key.SetValue("", "Freedeck Handoff");
key.SetValue("URL Protocol", "");
}
}
using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("freedeck\\shell\\open\\command"))
{
if (key != null)
{
key.SetValue("", System.IO.Directory.GetCurrentDirectory()+"\\handoff.exe %1");
}
}
} else
{
string action = args[0].Split('/')[2];
string appid = args[0].Split('/')[3];
switch (action)
{
case "download":
Downloader.Download(args[0].Split('/'));
break;
default:
Console.WriteLine("This doesn't exist.. sorry!");
break;
}
}
}
private static void Elevate()
{
var SelfProc = new ProcessStartInfo
{
UseShellExecute = true,
WorkingDirectory = Environment.CurrentDirectory,
FileName = "handoff.exe",
Arguments = "--setup-admin",
Verb = "runas"
};
try
{
Process.Start(SelfProc);
}
catch
{
Console.WriteLine("Unable to elevate!");
}
}
}
}