Ejemplo n.º 1
0
        public static void RemoveListener(IStatusListener listenerToRemove)
        {
            if (sm_Listeners == null)
            {
                return;
            }

            ListenerNode nodeToRemove = new ListenerNode()
            {
                listener = null, wantsTrace = false
            };

            foreach (var lNode in sm_Listeners)
            {
                if (lNode.listener == listenerToRemove)
                {
                    nodeToRemove = lNode;
                    break;
                }
            }

            if (nodeToRemove.listener != null)
            {
                sm_Listeners.Remove(nodeToRemove);
            }
        }
Ejemplo n.º 2
0
 public void Remove(IStatusListener listener)
 {
     lock (StatusListenerListLock)
     {
         StatusListenerlList.Remove(listener);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// 初始化消息监听器
 /// </summary>
 /// <param name="endPoint"></param>
 public MessageListener(EndPoint endPoint, IStatusListener innerListener)
 {
     _endPoint      = endPoint;
     _innerListener = innerListener;
     _pushTime      = DateTime.Now;
     _appNames      = new List <string>();
     _appNames      = new List <string>();
 }
Ejemplo n.º 4
0
 /// <summary>
 /// 初始化消息监听器
 /// </summary>
 /// <param name="endPoint"></param>
 public MessageListener(EndPoint endPoint, IStatusListener innerListener)
 {
     _endPoint = endPoint;
     _innerListener = innerListener;
     _pushTime = DateTime.Now;
     _appNames = new List<string>();
     _appNames = new List<string>();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 初始化消息监听器
        /// </summary>
        /// <param name="endPoint"></param>
        /// <param name="innerListener"></param>
        /// <param name="options"></param>
        public MessageListener(EndPoint endPoint, IStatusListener innerListener, SubscribeOptions options, string[] subscribeTypes)
            : this(endPoint, innerListener)
        {
            _options = options;

            if (subscribeTypes == null)
                _subscribeTypes = new List<string>();
            else
                _subscribeTypes = new List<string>(subscribeTypes);
        }
Ejemplo n.º 6
0
        public EventProcessor(BlockingCollection <FsEvent> eventList, Synchronizer synchronizer, IStatusListener statusListener)
        {
            this.eventList      = eventList;
            this.synchronizer   = synchronizer;
            this.statusListener = statusListener;

            fileTools = new FileTools();

            stopRequired = 0;
            thread       = new Thread(run);
            thread.Start();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 初始化消息监听器
        /// </summary>
        /// <param name="endPoint"></param>
        /// <param name="innerListener"></param>
        /// <param name="options"></param>
        public MessageListener(EndPoint endPoint, IStatusListener innerListener, SubscribeOptions options, string[] subscribeTypes)
            : this(endPoint, innerListener)
        {
            _options = options;

            if (subscribeTypes == null)
            {
                _subscribeTypes = new List <string>();
            }
            else
            {
                _subscribeTypes = new List <string>(subscribeTypes);
            }
        }
Ejemplo n.º 8
0
        public void Install(string modsStore, string gameFolder, IStatusListener listener)
        {
            DownloadToStore (modsStore);

            string localFile = Path.Combine (modsStore, StoreName);
            string destFile = Path.Combine (gameFolder, "mods", Description.FileName);

            if (File.Exists (destFile)) {
                File.Delete (destFile);
            }

            Directory.CreateDirectory(Path.GetDirectoryName(destFile));
            File.Copy(localFile, destFile);
        }
Ejemplo n.º 9
0
        public static void AddListener(IStatusListener listener, bool wantsTrace)
        {
            if (sm_Listeners == null)
            {
                sm_Listeners = new List <ListenerNode>();
            }

            var node = new ListenerNode()
            {
                listener   = listener,
                wantsTrace = wantsTrace
            };

            sm_Listeners.Add(node);
        }
Ejemplo n.º 10
0
        public bool Add(IStatusListener listener)
        {
            lock (StatusListenerListLock)
            {
                if (listener is OnConsoleStatusListener)
                {
                    bool alreadyPresent = CheckForPresent(StatusListenerlList, listener.GetType());
                    if (alreadyPresent)
                    {
                        return(false);
                    }
                }
                StatusListenerlList.Add(listener);
            }

            return(true);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Input a single file to download. Does not stop until error or completed.
        /// </summary>
        /// <param name="urlFilePATH">Example: "http://www.webaddress.com/file.zip" </param>
        /// <param name="filePATH">Example: "C:\LOCATION\file.zip" </param>
        public void Download(string urlFilePATH, string filePATH, IStatusListener listener)
        {
            ActiveFile = filePATH;
            ActiveURL = urlFilePATH;

            listener.Log("[Downloader] {0} ==> {1}", urlFilePATH, filePATH);

            Directory.CreateDirectory(Path.GetDirectoryName(filePATH));
            using (var webConnect = new WebClient()) {
                webConnect.Headers["User-Agent"] = "Craftalyst/0.1";
                webConnect.DownloadProgressChanged += HandleProgress;
                webConnect.DownloadFile(new Uri(urlFilePATH), filePATH);
            }

            ActiveFile = "";
            ActiveURL = "";
            Progress = 0;
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        private void InstallLibraries(IStatusListener listener)
        {
            listener.Log ("Installing libraries...");
            listener.SetProgress(0);

            var libraries = VersionParameters.Libraries.Where (x => x.AppliesHere).Where (x => x.RequiredForClient).ToList ();

            // Install missing libraries

            int progress = 0;
            int totalCount = libraries.Count ();

            foreach (var lib in libraries) {
                var libUrl = lib.Url;
                var libJar = lib.GetPath(this);
                var libDir = Path.GetDirectoryName(libJar);
                Directory.CreateDirectory(libDir);

                // Download the library if it does not already exist in the libraries directory
                if (!File.Exists (libJar))
                    Downloader.Single(libUrl, libJar, listener);

                // Ugh, apply the extract rules. I hope I do this right.
                // If Extract is present, that means we extract it. Otherwise, the jar just sits there... right??

                if (lib.Extract != null) {
                    ZipUtility.Extract(libJar, Path.Combine (GameLocation, "bin", "natives"), "-META-INF");
                } else {
                    Directory.CreateDirectory(Path.Combine (GameLocation, "bin"));
                    File.Copy (libJar, Path.Combine (GameLocation, "bin", lib.JarName));
                }

                ++progress;

                listener.SetStatus(string.Format ("Installed {0} / {1} libraries", progress, totalCount));
                listener.SetProgress((double)progress / totalCount);
            }

            listener.SetProgress(1);
        }
Ejemplo n.º 14
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.º 15
0
        /// <summary>
        /// Look for & Download required Files
        /// </summary>
        /// <returns>Status of exceptions or success</returns>
        public void Setup(IStatusListener listener)
        {
            if (IsSetup)
                return;

            listener.Log ("Retrieving version information from Minecraft.net...");
            VersionParameters = this.GetVersionParameters(SelectedVersion);
            listener.Log ("Verifying assets...");
            InstallAssets(listener);
            IsSetup = true;
        }
Ejemplo n.º 16
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.º 17
0
        public static void AddListener(IStatusListener listener, bool wantsTrace)
        {
            if (sm_Listeners == null)
            {
                sm_Listeners = new List<ListenerNode>();
            }

            var node = new ListenerNode()
            {
                listener = listener,
                wantsTrace = wantsTrace
            };

            sm_Listeners.Add(node);
        }
Ejemplo n.º 18
0
            private void Download(string assetsDirectory, IStatusListener listener)
            {
                string objectDirectory = Path.Combine (assetsDirectory, "objects");
                Directory.CreateDirectory(objectDirectory);

                string assetFile = Path.Combine (objectDirectory, ObjectFilename);

                for (int i = 0, max = 5; i < max; ++i) {
                    Downloader.Single (Url, assetFile);
                    string actualHash = FileUtility.Hash (assetFile);

                    if (actualHash == null)
                        throw new InvalidOperationException(string.Format ("Failed to create hash to of '{0}' (with expected hash {1})", FileName, Hash));

                    if (actualHash != Hash) {
                        if (i + 1 == max) {
                            throw new Exception(string.Format ("Failed to verify downloaded asset '{0}' (expected hash {1}, got hash {2})",
                                                               FileName, Hash, actualHash));
                        } else {
                                listener.Log ("Error: File '{0}' failed hash check (expected {1}, got {2}) after downloading, retrying (attempt #{3})",
                                                   FileName, Hash, actualHash, i);
                        }
                        continue;
                    } else {
                        //listener.Log ("Verified hash for asset {0} was exactly that hash!", Hash);
                    }

                    break;
                }
            }
Ejemplo n.º 19
0
            public void Install(MinecraftAssetManifest manifest, string assetsDirectory, IStatusListener listener)
            {
                string assetFile = GetAssetFile(assetsDirectory);
                Directory.CreateDirectory(Path.GetDirectoryName(assetFile));

                if (!File.Exists (assetFile))
                    Download (assetsDirectory, listener);

                // If this manifest is virtual, then keep the assets/legacy/virtual directly up to date with the correct
                // version of the file.

                if (manifest.Virtual) {
                    string virtualAssetFile = Path.Combine (assetsDirectory, "legacy", "virtual", FileName);
                    if (!File.Exists (virtualAssetFile) || FileUtility.Hash (virtualAssetFile) != Hash) {
                        if (File.Exists(virtualAssetFile))
                            File.Delete (virtualAssetFile);
                        Directory.CreateDirectory(Path.GetDirectoryName(virtualAssetFile));
                        File.Copy (assetFile, virtualAssetFile);
                    }
                }
            }
Ejemplo n.º 20
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.º 21
0
        public static void RemoveListener(IStatusListener listenerToRemove)
        {
            if (sm_Listeners == null) return;

            ListenerNode nodeToRemove = new ListenerNode() { listener = null, wantsTrace = false };

            foreach (var lNode in sm_Listeners)
            {
                if (lNode.listener == listenerToRemove)
                {
                    nodeToRemove = lNode;
                    break;
                }
            }

            if (nodeToRemove.listener != null)
            {
                sm_Listeners.Remove(nodeToRemove);
            }
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Download a single URL to a given file location.
 /// </summary>
 /// <param name='urlFilePATH'>
 /// URL file PAT.
 /// </param>
 /// <param name='filePATH'>
 /// File PAT.
 /// </param>
 public static void Single(string urlFilePATH, string filePATH, IStatusListener listener)
 {
     var loader = new Downloader();
     loader.Download (urlFilePATH, filePATH, listener);
 }
Ejemplo n.º 23
0
 public UDPServer(IStatusListener listener, int port)
 {
     this.port      = port;
     statusListener = listener;
     pcController   = new PCController(this);
 }
Ejemplo n.º 24
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();
        }