Ejemplo n.º 1
0
        private void InstallAssets(IStatusListener listener)
        {
            listener.SetTitle("Installing Minecraft assets...");
            listener.SetProgress(0);

            listener.Log ("Installing assets...");

            var manifest = AssetManifest;

            listener.Log ("Found {0} assets in manifest...", manifest.Objects.Count);

            //var toInstall = manifest.Objects.Where (x => !x.IsInstalled(AssetsLocation));
            var toInstall = manifest.Objects;
            listener.Log ("Need to get {0} assets from Minecraft.net...", toInstall.Count ());

            int progress = 0;
            int total = toInstall.Sum (x => x.Size);
            int count = 0;
            int totalCount = toInstall.ToList().Count;

            foreach (var obj in toInstall) {
                obj.Install (manifest, AssetsLocation, listener);
                progress += obj.Size;
                count += 1;

                listener.SetProgress((double)progress / (double)total);
                listener.SetStatus(
                    string.Format (
                        "Installed {0} / {1} assets. Downloaded {2} / {3} MB",
                        count, totalCount,
                        Math.Round(progress / 1024.0 / 1024.0 * 100.0) / 100.0,
                        Math.Round (total / 1024.0 / 1024.0 * 100.0) / 100.0));
                Thread.Sleep(5);
            }

            listener.Log("Successfully installed all assets!");

            listener.SetProgress(1);
        }
Ejemplo n.º 2
0
        public void Install(IStatusListener listener)
        {
            listener.SetTitle("Installing Minecraft...");
            listener.SetProgress(0);

            Directory.CreateDirectory(this.GameLocation);
            Directory.CreateDirectory(Path.Combine (this.GameLocation, "bin"));

            listener.Log ("Retrieving version information from Minecraft.net...");
            VersionParameters = this.GetVersionParameters(SelectedVersion);

            listener.Log ("Craftalyst Minecraft setup...");

            listener.Log ("Installing assets...");
            InstallAssets(listener);

            listener.Log ("Installing libraries...");
            InstallLibraries(listener);
            listener.Log ("Installing game...");
            InstallGame();
        }
Ejemplo n.º 3
0
        public void Sync(IStatusListener listener)
        {
            listener.SetTitle("Synchronizing with server");
            listener.SetStatus("Please wait...");
            listener.SetProgress(0);
            listener.Log("Retrieving server-side instance description...");

            InstanceDescription fromServer = null;
            try {
                fromServer = FetchServerInstanceDescription();
            } catch (FailedDownloadException e) {
                listener.Log ("An error occurred fetching server-side instance description: {0}", e.Message);
                listener.Log ("Exception: {0}", e);
                return;
            }

            if (fromServer == null) {
                listener.Log ("Sync failed: Could not retrieve server-side instance description");
                return;
            }

            if (Description.StartRam == null)
                Description.StartRam = fromServer.StartRam;

            if (Description.MaxRam == null)
                Description.StartRam = fromServer.MaxRam;

            listener.SetStatus("Received server-side instance description...");
            listener.Log("Successfully retrieved server-side instance description");
            listener.Log("Checking for changes to instance configuration...");

            var oldDescription = Description;
            Description = fromServer;

            // Query for mods which have been removed

            listener.Log ("Checking for removed mods...");
            listener.SetStatus("Checking for removed mods...");
            var removedMods = oldDescription.Mods
                    .Where (x => !Description.Mods.Any (newMod => newMod.ArtifactId == x.ArtifactId));

            // Query for mods which have been added

            listener.Log ("Checking for newly installed mods...");
            listener.SetStatus("Checking for newly installed mods...");

            var addedMods = Description.Mods.Where (x => !oldDescription.Mods.Any (oldMod => oldMod.ArtifactId == x.ArtifactId));

            int count = 0;
            int total = removedMods.Count () + addedMods.Count ();

            foreach (var removedMod in removedMods) {
                listener.SetStatus(string.Format ("Removing {0} version {1}", removedMod.Name, removedMod.Version));
                listener.Log ("Server removed mod {0}: removing...", removedMod.ArtifactId);
                new Mod (removedMod).Remove (this.GameFolder);

                listener.SetProgress((double)count / (double)total);
                ++count;
            }

            foreach (var addedMod in addedMods) {
                listener.SetStatus(string.Format ("Installing {0} version {1}", addedMod.Name, addedMod.Version));
                listener.Log ("Server added mod {0}: installing...", addedMod.ArtifactId);
                new Mod (addedMod).Install (this.ModsStoreFolder, this.GameFolder, listener);

                listener.SetProgress((double)count / (double)total);
                ++count;
            }

            // Download new configuration files...

            listener.Log ("Checking configuration version..");
            listener.Log ("Local: {0}       Remote: {1}", oldDescription.ConfigVersion, Description.ConfigVersion);

            if (oldDescription.ConfigVersion < Description.ConfigVersion) {
                listener.Log (" * Need to update configuration from server...");
                UpdateConfigFiles (listener); // A change is needed...
            } else {
                listener.Log(" - Up to date");
            }

            listener.SetStatus("Writing updated instance description...");
            using (var sw = new StreamWriter(Path.Combine (GameFolder, "craftalyst-instance.json")))
                sw.Write(Description.ToJson());

            SaveDescription();

            listener.SetProgress(1);
        }
Ejemplo n.º 4
0
        void UpdateConfigFiles(IStatusListener listener)
        {
            listener.SetTitle("Syncing client configuration from server...");
            listener.Log("Updating configuration files from the server...");
            listener.SetStatus("Please wait...");
            listener.SetProgress(0);

            List<string> configFiles = new List<string>();

            foreach (var list in Description.Mods.Select (x => x.ConfigFiles).Where (x => x != null))
                configFiles.AddRange(list);

            configFiles.AddRange(Description.SyncConfigs);

            int total = configFiles.Count();
            int count = 0;

            foreach (string configFile in configFiles) {
                string localFile = Path.Combine(GameFolder, "config", configFile);
                if (File.Exists(localFile))
                    File.Delete(localFile);

                listener.SetStatus(string.Format ("Pulling {0}", configFile));
                Downloader.Single(string.Format("{0}/config/{1}", Description.SyncUrl, configFile), localFile);

                listener.SetProgress((double)count / (double)total);
                ++count;
            }
            listener.SetProgress(1);
        }
Ejemplo n.º 5
0
        public void Install(IStatusListener listener)
        {
            Directory.CreateDirectory(GameFolder);
            Directory.CreateDirectory(AssetsFolder);
            Directory.CreateDirectory(VersionsFolder);
            Directory.CreateDirectory(LibraryFolder);

            listener.Log("");
            listener.Log("");
            listener.Log("Installing Minecraft...");

            var mc = CreateMinecraft();
            mc.Install(listener);

            // Install mods...

            listener.Log("");
            listener.Log("");
            listener.Log("Installing mods...");
            listener.SetTitle("Installing mods...");

            int count = 0;
            int total = Description.Mods.Count ();

            foreach (var addedMod in Description.Mods) {
                listener.Log("Installing mod {0}", addedMod.ArtifactId);
                listener.SetStatus(string.Format ("Installing mod {0} {1}...", addedMod.Name, addedMod.Version));
                new Mod(addedMod).Install(this.ModsStoreFolder, this.GameFolder, listener);
                listener.SetProgress((double)count / (double)total);
            }

            listener.Log("Saving instance description...");
            listener.SetTitle("Saving instance...");
            listener.SetStatus("Just a bit longer!");

            SaveDescription();

            // Install configuration files...
            UpdateConfigFiles(listener);

            listener.Log("Performing synchronization with server...");
            // Update to latest from server
            Sync (listener);

            listener.SetTitle("All is done!");
            listener.SetProgress(1);
        }