static void Main(string[] args) { GamePath = Path.GetFullPath(GamePath); CacheFile cache = new CacheFile("installation.cache"); Setup setup = new Setup(new Uri(Path.Combine(Environment.CurrentDirectory, "TestRepository1") + "/"), cache); setup.Repository.TargetDirectory = new DirectoryInfo(GamePath); foreach (var package in setup.Packages) { if (package.IsInstalled) package.Update(); else package.Install(); } Librarypath = setup.GetStartupLibrarypath(); Classpath = setup.GetStartupClasspath(); StartMinecraft(); System.Threading.Thread.Sleep(-1); }
public void UpdateMinecraft() { SetProgress(); SetStatus("Fetching packages..."); var uri = new Uri("http://repo.update.modernminas.de/"); CacheFile cache = new CacheFile(System.IO.Path.Combine(App.GamePath, "installation.cache")); Repository repository = new Repository(uri, cache) { TargetDirectory = new System.IO.DirectoryInfo(App.GamePath) }; Setup setup = new Setup(uri, repository); Dictionary<string, float> progress = new Dictionary<string,float>(); foreach (var package in setup.Packages) { progress.Add(package.ID + "_preinstall", 0); progress.Add(package.ID + "_download", 0); progress.Add(package.ID + "_install", 0); progress.Add(package.ID + "_uninstall", 0); } int i = 0; repository.StatusChanged += (sender, e) => { switch (e.Status) { case StatusType.Finished: if (!progress.ContainsKey(e.Package.ID + "_install")) break; if (progress[e.Package.ID + "_uninstall"] < 1) progress[e.Package.ID + "_uninstall"] = 1; if (progress[e.Package.ID + "_preinstall"] < 1) progress[e.Package.ID + "_preinstall"] = 1; if (progress[e.Package.ID + "_download"] < 1) progress[e.Package.ID + "_download"] = 1; if(progress[e.Package.ID + "_install"] < 1) progress[e.Package.ID + "_install"] = 1; break; case StatusType.Parsing: case StatusType.Installing: if (!progress.ContainsKey(e.Package.ID + "_install")) break; progress[e.Package.ID + "_install"] = e.Progress; if(progress[e.Package.ID + "_uninstall"] < 1) progress[e.Package.ID + "_uninstall"] = 1; if(progress[e.Package.ID + "_preinstall"] < 1) progress[e.Package.ID + "_preinstall"] = 1; if(progress[e.Package.ID + "_download"] < 1) progress[e.Package.ID + "_download"] = 1; break; case StatusType.Downloading: if (progress.ContainsKey(e.Package.ID + "_download")) { if (progress[e.Package.ID + "_preinstall"] < 1) progress[e.Package.ID + "_preinstall"] = 1; progress[e.Package.ID + "_download"] = e.Progress; } break; case StatusType.CheckingDependencies: case StatusType.InstallingDependencies: if (progress.ContainsKey(e.Package.ID + "_preinstall")) progress[e.Package.ID + "_preinstall"] = e.Progress; break; case StatusType.Uninstalling: SetStatus(string.Format("Package {0}/{1}: Updating...", i, setup.Packages.Count())); if (progress.ContainsKey(e.Package.ID + "_uninstall")) progress[e.Package.ID + "_uninstall"] = e.Progress; break; } SetProgress(progress.Sum(v => v.Value)); foreach (var j in progress.Keys) { Debug.WriteLine(string.Format("{0}: {1}", j, progress[j])); } }; SetProgress(0, setup.Packages.Count() * 4); SetStatus("Updating..."); foreach (var package in setup.Packages) { i++; Debug.WriteLine(string.Format("Current package: {0}", package.ID, null)); SetProgress(progress.Sum(v => v.Value)); if (package.IsInstalled) { SetStatus(string.Format("Package {0}/{1}: Checking for updates...", i, setup.Packages.Count())); package.Update(); } else { SetStatus(string.Format("Package {0}/{1}: Installing...", i, setup.Packages.Count())); package.Install(); } } foreach (var package in from p in setup.Packages where !cache.GetAllCachedPackageIDs().Contains(p.ID) select p) { repository.UninstallPackage(package.ID); } SetStatus("Update finished"); SetProgress(1, 1); App.StartupClasspath = setup.GetStartupClasspath(); App.StartupLibrarypath = setup.GetStartupLibrarypath(); }