General code refactor and reformat.

This commit is contained in:
2018-12-31 13:17:27 +00:00
parent 6b12cd1a8e
commit f2caa8c40f
413 changed files with 3554 additions and 6549 deletions

View File

@@ -63,6 +63,28 @@ namespace DiscImageChef.CommonTypes.Interop
GetRealPlatformID() == PlatformID.Win32Windows || GetRealPlatformID() == PlatformID.WinCE ||
GetRealPlatformID() == PlatformID.WindowsPhone || GetRealPlatformID() == PlatformID.Xbox;
public static bool IsAdmin
{
get
{
if(!IsWindows) return Environment.UserName == "root";
bool isAdmin;
WindowsIdentity user = null;
try
{
user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch(UnauthorizedAccessException ex) { isAdmin = false; }
catch(Exception ex) { isAdmin = false; }
finally { user?.Dispose(); }
return isAdmin;
}
}
[DllImport("libc", SetLastError = true)]
static extern int uname(out utsname name);
@@ -276,28 +298,6 @@ namespace DiscImageChef.CommonTypes.Interop
}
}
public static bool IsAdmin
{
get
{
if(!IsWindows) return Environment.UserName == "root";
bool isAdmin;
WindowsIdentity user = null;
try
{
user = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(user);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch(UnauthorizedAccessException ex) { isAdmin = false; }
catch(Exception ex) { isAdmin = false; }
finally { user?.Dispose(); }
return isAdmin;
}
}
/// <summary>
/// POSIX uname structure, size from OSX, big enough to handle extra fields
/// </summary>