Example #1
0
 public void Invoke(Document document)
 {
     if (StatusHandler.IsRequiredStatus(document))
     {
         StatusHandler.Invoke(document);
         StatusHandler.FinishStatus(document);
     }
 }
Example #2
0
        //Callback handler for battery information.
        private void ReceiveStatus(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return;
            }

            BatteryInfo info = JsonUtility.FromJson <BatteryInfo>(json);

            if (OnStatus != null)
            {
                OnStatus.Invoke(info);
            }
        }
        //Receive status including initialization and errors.
        private void ReceiveStatus(string message)
        {
            StatusMessage = message;
            if (initialized == -1)  //At first time (As long as it is the same language)
            {
                initialized      = message.StartsWith("SUCCESS_INIT") ? 1 : 0;
                initializeStatus = message;
            }

            if (OnStatus != null)
            {
                OnStatus.Invoke(message);
            }
        }
        //Callback handler for CPU Rate information.
        private void ReceiveStatus(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return;
            }

            string[]      items = json.Split('\n');
            CpuRateInfo[] infos = new CpuRateInfo[items.Length];

            for (int i = 0; i < infos.Length; i++)
            {
                infos[i] = JsonUtility.FromJson <CpuRateInfo>(items[i]);
            }

            if (OnStatus != null)
            {
                OnStatus.Invoke(infos);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="mod"></param>
        /// <returns></returns>
        public async Task <bool> DownloadMod(ModApiObject mod)
        {
            // check if mod need to download
            if (mod.IsInstalled() && !string.IsNullOrEmpty(mod.InstalledVersion) && !mod.IsNew())
            {
                _logger.LogInformation("{0} v{1} ({2}) already installed.", mod.Name, mod.Version, mod.GameVersion);

                return(true);
            }

            _logger.LogInformation("downloading {0} v{1}...", mod.Name, mod.Version);
            Console.WriteLine(mod.Name);
            StatusHandler?.Invoke(null, new StatusEvent($"Downloading {mod.Name}..."));

            var tmpFileName = $"mod-{mod.Name}-{mod.Version}.zip";

            if (!await _httpHelper.DownloadFile(new Uri(ModApiBasicUrl + mod.Downloads.First().Url), tmpFileName))
            {
                _logger.LogError("Download failed");
                return(false);
            }

            // extract
            _logger.LogInformation("Downloading finished. Extracting...");
            _fileHelper.Extract(tmpFileName, SettingsHandler.Instance.GetSettings().GamePath);

            // delete tmp file
            _logger.LogInformation("Deleting temporary download file...");
            File.Delete(tmpFileName);

            SettingsHandler.Instance.AddInstalledMod(mod);

            _logger.LogInformation("{0} v{1} installed", mod.Name, mod.Version);

            return(true);
        }