private void D3Prefs()
{
var imp = new Impersonator();
if (Parent.UseWindowsUser)
imp.Impersonate(Parent.WindowsUserName, "localhost", Parent.WindowsUserPassword);
// Copy D3Prefs
Logger.Instance.Write("Replacing D3Prefs for user: {0}", Environment.UserName);
var currentprefs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) +
@"\Diablo III\D3Prefs.txt";
if (Directory.Exists(Path.GetDirectoryName(currentprefs)))
{
Logger.Instance.Write("Copy custom D3Prefs file to: {0}", currentprefs);
try
{
File.Copy(Parent.D3PrefsLocation, currentprefs, true);
}
catch (Exception ex)
{
Logger.Instance.Write("Failed to copy D3Prefs file: {0}", ex);
}
}
else
Logger.Instance.Write("D3Prefs Failed: Path to \"{0}\" does not exist!", currentprefs);
if (imp != null)
imp.Dispose();
// Also replace Default User D3Prefs
var defaultprefs =
Regex.Match(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
string.Format(@"(.+)\\{0}.*", Environment.UserName)).Groups[1].Value;
if (Directory.Exists(defaultprefs + "\\Default"))
defaultprefs += "\\Default";
else if (Directory.Exists(defaultprefs + "\\Default User"))
defaultprefs += "\\Default User";
else
return;
defaultprefs += @"\Diablo III\D3Prefs.txt";
if (Directory.Exists(Path.GetDirectoryName(defaultprefs)))
{
Logger.Instance.Write("Copy custom D3Prefs file to: {0}", defaultprefs);
try
{
File.Copy(Parent.D3PrefsLocation, defaultprefs, true);
}
catch (Exception ex)
{
Logger.Instance.Write("Failed to copy d3prefs file: {0}", ex);
}
}
Thread.Sleep(1000);
}