-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWowApplicationHelper.cs
More file actions
82 lines (72 loc) · 2.04 KB
/
Copy pathWowApplicationHelper.cs
File metadata and controls
82 lines (72 loc) · 2.04 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
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using WoWSimsApp.Characters;
namespace WoWSimsApp
{
internal class WowApplicationHelper
{
private const string WowDisplayName = "Cataclysm Classic";
public WowApplicationHelper()
{
}
public List<SavedCharacter> GetCharacters()
{
List<SavedCharacter> characters = new List<SavedCharacter>();
string installLocation = GetInstallLocation();
if (string.IsNullOrEmpty( installLocation ))
{
return characters;
}
string accountsPath = Path.Combine( installLocation, "WTF", "Account" );
if (!Directory.Exists( accountsPath ))
{
return characters;
}
foreach (var accountDir in Directory.GetDirectories( accountsPath ))
{
string charactersPath = Path.Combine( accountDir, "SavedVariables", "WowSimsExporter.lua" );
if (!File.Exists( charactersPath ))
{
continue;
}
try
{
var savedCharacters = SavedCharactersParser.ParseFromLuaFile( charactersPath );
characters.AddRange( savedCharacters );
}
catch (Exception ex)
{
Console.WriteLine( $"Error parsing characters from {charactersPath}: {ex.Message}" );
}
}
return characters.OrderBy( x => x.Realm ).ThenBy( x => x.Name ).ToList();
}
public string GetInstallLocation()
{
string installLocation = "";
using RegistryKey key = Registry.LocalMachine.OpenSubKey( @"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" );
if (key == null)
{
return installLocation;
}
foreach (var subkeyName in key.GetSubKeyNames())
{
using RegistryKey subkey = key.OpenSubKey( subkeyName );
var name = subkey?.GetValue( "DisplayName" ) as string;
if (string.Equals( name, WowDisplayName, StringComparison.OrdinalIgnoreCase ))
{
installLocation = subkey.GetValue( "InstallLocation" ) as string;
break;
}
}
if (!string.IsNullOrEmpty( installLocation ))
{
installLocation = $"{installLocation}\\_classic_";
}
return installLocation;
}
}
}