protected void Run() { bar.StartProcess(tasks.Count); OnStart(); while (!Core.Terminated && (Continuous || tasks.Count > 0)) { if (Core.CloseLauncher) { goto TerminateManager; } if (tasks.Count > 0) { CurrentTask = tasks[0]; OnStartTask(CurrentTask); Stopwatch watch = Stopwatch.StartNew(); try { /*if (CurrentTask.CanBeThreaded()) Not supported yet!!! * { * * } * else * { * * }*/ RunTask(CurrentTask); } catch (Exception e) { Log.Log("An error occurred! Please report this on github! {0}", e.Message); } watch.Stop(); Log.Log("Finished task in " + StringUtils.ToString(watch.Elapsed)); OnFinishTask(CurrentTask); bar.FinishStep(); tasks.RemoveAt(0); } else { if (CurrentTask != null) { OnNoTaskFound(); } CurrentTask = null; Idle = true; } } TerminateManager: Active = false; }
protected override bool RunTask(IProgressBar bar) { //CommandUtils.loadLauncherCommands; HttpWebRequest request = HttpWebRequest.CreateHttp("http://creativemd.de/service/version_new.php?name=" + Core.ProgramName); request.UserAgent = "Mozilla/5.0"; request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; try { HttpWebResponse response = (HttpWebResponse)request.GetResponse(); using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { Internet.InternetModule.ChangeState(ModuleState.Loaded); string content = reader.ReadToEnd(); var newest = new Version(content); var current = new Version(Core.ProgramVersion); if (newest.CompareTo(current) > 0) { //Download new version return(true); } else { return(true); } } } catch (Exception) { } Internet.InternetModule.ChangeState(ModuleState.Failed); bar.StartStep(1); bar.FinishStep(); return(true); }
public static bool CopyFolder(string SourcePath, string DestinationPath, Logger Log, bool overwrite = true, IProgressBar bar = null) { if (Log == null) { Log = Core.MainLog; } string[] files = Directory.GetFiles(SourcePath, "*", SearchOption.AllDirectories); if (bar != null) { bar.StartStep(files.Length); } for (int i = 0; i < files.Length; i++) { try { Directory.CreateDirectory(files[i].Replace(SourcePath, DestinationPath)); File.Copy(files[i], files[i].Replace(SourcePath, DestinationPath), overwrite); } catch (IOException e) { Log.Log("Could not copy {0} to {1}! An unexpected error occurred {1}.", files[i], files[i].Replace(SourcePath, DestinationPath), e); } if (bar != null) { bar.SetProgress(i); } } Directory.Delete(SourcePath, true); if (bar != null) { bar.FinishStep(); } return(true); }
public static bool DeleteFolder(string Path, Logger Log, IProgressBar bar = null) { if (Log == null) { Log = Core.MainLog; } string[] files = Directory.GetFiles(Path, "*", SearchOption.AllDirectories); if (bar != null) { bar.StartStep(files.Length); } for (int i = 0; i < files.Length; i++) { try { File.Delete(files[i]); } catch (IOException e) { Log.Log("Could not delete {0}! An unexpected error occurred {1}.", files[i], e); } if (bar != null) { bar.SetProgress(i); } } Directory.Delete(Path, true); if (bar != null) { bar.FinishStep(); } return(true); }