-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.xaml.cs
80 lines (68 loc) · 2.54 KB
/
App.xaml.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
using System;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
namespace Torshify.Origo.Embedded
{
public partial class App : Application
{
#region Methods
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
EmbeddOrigo();
}
private void EmbeddOrigo()
{
var args = Environment.GetCommandLineArgs();
if (args.Length != 3)
{
MessageBox.Show("Please provide username and password as command line arguments");
Environment.Exit(-1);
}
Task.Factory.StartNew(() =>
{
AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationName = "Spotify";
setup.ApplicationBase = Environment.CurrentDirectory;
AppDomain origoDomain = AppDomain.CreateDomain("OrigoDomain", null, setup);
AppDomain.CurrentDomain.AssemblyResolve += OrigoDomainOnAssemblyResolve;
OrigoBootstrapper host = origoDomain.CreateInstanceAndUnwrap(
typeof(OrigoBootstrapper).Assembly.FullName,
"Torshify.Origo.OrigoBootstrapper") as OrigoBootstrapper;
AppDomain.CurrentDomain.AssemblyResolve -= OrigoDomainOnAssemblyResolve;
if (host != null)
{
host.Run();
}
});
}
private Assembly OrigoDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
{
try
{
Assembly assembly = Assembly.Load(args.Name);
if (assembly != null)
return assembly;
}
catch
{
// ignore load error
}
// *** Try to load by filename - split out the filename of the full assembly name
// *** and append the base path of the original assembly (ie. look in the same dir)
// *** NOTE: this doesn't account for special search paths but then that never
// worked before either.
string[] parts = args.Name.Split(',');
string file = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\" + parts[0].Trim() +
".dll";
if (File.Exists(file))
{
return Assembly.LoadFrom(file);
}
return null;
}
#endregion Methods
}
}