public static void RestartAsAdmin() { if (Utils.IsRunningOnMono()) { return; //Again, mono cannot handle this. } string BatchFile = Path.Combine(System.IO.Path.GetTempPath(), "RestartAsAdmin.bat"); var exeName = Process.GetCurrentProcess().MainModule.FileName; Process proc = new Process(); proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.Arguments = $@"/c {BatchFile}"; proc.StartInfo.Verb = "runas"; proc.StartInfo.CreateNoWindow = true; proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; proc.StartInfo.UseShellExecute = true; try { StreamWriter BatchFileStream = new StreamWriter(BatchFile); try { // Wait a few seconds to allow shutdown later on, use task kill just in case still running string batchline = $"timeout 5 && taskkill /F /IM {AppDomain.CurrentDomain.FriendlyName} /fi \"memusage gt 2\" && \"{exeName}\""; logger.Log(LogLevel.Info, "RestartAsAdmin batch line: " + batchline); BatchFileStream.WriteLine(batchline); } finally { BatchFileStream.Close(); } proc.Start(); ServerSettings.DoServerShutdown(new ServerSettings.ReasonedEventArgs()); Environment.Exit(0); } catch (Exception ex) { logger.Log(LogLevel.Error, "Error occured during RestartAsAdmin(): " + ex.Message); } }
private static Tuple <string, string> GetFilenameAndArgsForOS(string file) { // Windows: avdumpDestination --Auth=.... // Mono: mono avdumpDestination --Auth=... var executable = avdumpDestination; string fileName = (char)34 + file + (char)34; var args = $"--Auth={ServerSettings.Instance.AniDb.Username.Trim()}:" + $"{ServerSettings.Instance.AniDb.AVDumpKey.Trim()}" + $" --LPort={ServerSettings.Instance.AniDb.AVDumpClientPort} --PrintEd2kLink -t {fileName}"; if (Utils.IsRunningOnMono()) { executable = "mono"; args = $"{avdumpDestination} {args}"; } return(Tuple.Create(executable, args)); }
public static string DumpFile(int vid) { var vl = Repo.Instance.VideoLocal.GetByID(vid); if (vl == null) { return("Unable to get videoloocal with id: " + vid); } string file = vl.GetBestVideoLocalPlace(true)?.FullServerPath; if (string.IsNullOrEmpty(file)) { return("Unable to get file: " + vid); } if (Utils.IsRunningOnMono()) { return(DumpFile_Mono(file)); } return(DumpFile(file)); }