Ejemplo n.º 1
0
        private void PlayButton_Click(object sender, RoutedEventArgs e)
        {
            CMLauncher.ProgressChanged += (o, ef) =>
            {
                Dispatcher.Invoke(() =>
                {
                    MainProgressBar.Value = ef.ProgressPercentage;
                });
            };
            CMLauncher.FileChanged += (fu) =>
            {
            };
            CMLauncher.LogOutput += (ee, Log) =>
            {
                Dispatcher.Invoke(() =>
                {
                    Label L = new Label()
                    {
                        Content = Log
                    };
                    LogList.Items.Add(L);
                    LogList.ScrollIntoView(L);
                });
            };


            if (!Directory.Exists("Data/Game"))
            {
                Directory.CreateDirectory("Data/Game");
            }

            if (!Directory.Exists("Data/Game/mods"))
            {
                Directory.CreateDirectory("Data/Game/mods");
            }

            if (!File.Exists("Mods.zip"))
            {
                ModDownloader.DownloadFile((obj, prog) =>
                {
                    Dispatcher.Invoke(() => MainProgressBar.Value = prog.ProgressPercentage);
                },
                                           (f, ff) =>
                {
                    Directory.Delete("Data/Game/mods", true);
                    Directory.CreateDirectory("Data/Game/mods");
                    ZipFile.ExtractToDirectory("Mods.zip", "Data/Game/mods");
                    LaunchGame();
                });
            }
            else
            {
                Directory.Delete("Data/Game/mods", true);
                Directory.CreateDirectory("Data/Game/mods");
                ZipFile.ExtractToDirectory("Mods.zip", "Data/Game/mods");
                LaunchGame();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Download and extract the Mod
        /// TODO clean this mess up
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void downloadButton_Click(object sender, EventArgs e)
        {
            var statusObjects = new DownloadStatus()
            {
                ProgressBar    = modDownloadProgress,
                Label          = downloadStatus,
                DonwloadButton = downloadButton,
                CancelButton   = cancelButton,
                UrlLabel       = modUrl
            };
            var modDownloader = new ModDownloader(Mod);

            downloadButton.Enabled = false;

            var task = Task.Run(() => {
                try
                {
                    modDownloader.DownloadMod(statusObjects, (obj, args) => { });
                }
                catch (ModFileUnavailableException ex)
                {
                    statusObjects.Label.Invoke((MethodInvoker)(
                                                   () =>
                    {
                        statusObjects.UrlLabel.Text = ex.Message;
                        statusObjects.UrlLabel.Cursor = Cursors.Hand;
                        statusObjects.UrlLabel.Click +=
                            (send, arg) => System.Diagnostics.Process.Start(ex.Message);

                        statusObjects.Label.Text =
                            @"Couldn't download mod, maybe try manual download.";
                    }));
                }
                catch (Exceptions.TimeoutException)
                {
                    statusObjects.Label.Invoke((MethodInvoker)(
                                                   () =>
                    {
                        statusObjects.Label.Text = @"Couldn't download mod, connection timed out :(";
                    }));
                }
                catch (Exception)
                {
                    statusObjects.Label.Invoke((MethodInvoker)(
                                                   () =>
                    {
                        statusObjects.Label.Text = @"Couldn't download mod :(";
                    }));
                }
            });
            await task;

            App.FactorioLoader.Mods.Init();
        }
Ejemplo n.º 3
0
    protected void TryDownloadAllModUpdates(object sender, EventArgs e)
    {
        foreach (var localMod in ModInfoTools.LocalMods)
        {
            if (localMod.Value.CloudName != null)
            {
                ModInfoHolder cloudModInfo = null;
                if (localMod.Value.FoundOther == 0)
                {
                    bool flag = true;
                    try
                    {
                        var repoItem = GetRepos.GetOneRepo(localMod.Value.CloudName);
                        if (ModInfoTools.GetGithubMod(repoItem))
                        {
                            cloudModInfo = ModInfoTools.lastGithubMod;
                            flag         = false;
                        }
                    }
                    catch (Exception E)
                    {
                        Console.WriteLine(E);
                    }
                    if (flag)
                    {
                        localMod.Value.FoundOther = -1;
                    }
                }
                if (cloudModInfo != null || ModInfoTools.GithubMods.TryGetValue(localMod.Value.CloudName, out cloudModInfo))
                {
                    if (localMod.Value.CurrentVersion == cloudModInfo.CurrentVersion)
                    {
                        continue;
                    }

                    //if (localMod.Value.State == ModInfo.ModState.Disabled)
                    //{
                    //    Log("Can't update a disabled mod! (" + localMod.Value.Name + ")", Color.OrangeRed);
                    //    continue;
                    //}
                    if (ModDownloader.AddModDownload(cloudModInfo, ModListStoreGithub))
                    {
                        ModListStoreLocal.SetValue(localMod.Value.TreeIter, (int)TreeColumnInfo.Desc, "Updating...");
                    }
                    continue;
                }
            }
        }
    }
Ejemplo n.º 4
0
        public AutoHost(TasClient tas, Spring spring, AutoHostConfig conf)
        {
            banList = new BanList(this, tas);

            if (conf == null)
            {
                LoadConfig();
            }
            else
            {
                config = conf;
            }
            SaveConfig();

            this.tas    = tas;
            this.spring = spring;

            tas.Said += new EventHandler <TasSayEventArgs>(tas_Said);

            pollTimer           = new Timer(PollTimeout * 1000);
            pollTimer.Enabled   = false;
            pollTimer.AutoReset = false;
            pollTimer.Elapsed  += new ElapsedEventHandler(pollTimer_Elapsed);

            spring.SpringExited += new EventHandler(spring_SpringExited);
            spring.GameOver     += new EventHandler <SpringLogEventArgs>(spring_GameOver);

            tas.BattleUserLeft          += new EventHandler <TasEventArgs>(tas_BattleUserLeft);
            tas.UserStatusChanged       += new EventHandler <TasEventArgs>(tas_UserStatusChanged);
            tas.BattleUserJoined        += new EventHandler <TasEventArgs>(tas_BattleUserJoined);
            tas.BattleMapChanged        += new EventHandler <TasEventArgs>(tas_BattleMapChanged);
            tas.BattleUserStatusChanged += new EventHandler <TasEventArgs>(tas_BattleUserStatusChanged);
            tas.BattleLockChanged       += new EventHandler <TasEventArgs>(tas_BattleLockChanged);
            tas.BattleOpened            += new EventHandler <TasEventArgs>(tas_BattleOpened);

            linker        = new UnknownFilesLinker(spring);
            mapDownloader = new MapDownloader(spring);
            mapDownloader.DownloadCompleted       += new EventHandler <TasEventArgs>(mapDownloader_DownloadCompleted);
            mapDownloader.DownloadProgressChanged += new EventHandler <TasEventArgs>(mapDownloader_DownloadProgressChanged);

            modDownloader = new ModDownloader(spring);
            modDownloader.DownloadCompleted       += new EventHandler <TasEventArgs>(modDownloader_DownloadCompleted);
            modDownloader.DownloadProgressChanged += new EventHandler <TasEventArgs>(mapDownloader_DownloadProgressChanged);


            tas.BattleFound += new EventHandler <TasEventArgs>(tas_BattleFound);
        }
Ejemplo n.º 5
0
    public AutoHost(TasClient tas, Spring spring, AutoHostConfig conf)
    {
      banList = new BanList(this, tas);

      if (conf == null) LoadConfig(); else config = conf;
      SaveConfig();

      this.tas = tas;
      this.spring = spring;

      tas.Said += new EventHandler<TasSayEventArgs>(tas_Said);

      pollTimer = new Timer(PollTimeout * 1000);
      pollTimer.Enabled = false;
      pollTimer.AutoReset = false;
      pollTimer.Elapsed += new ElapsedEventHandler(pollTimer_Elapsed);

      spring.SpringExited += new EventHandler(spring_SpringExited);
      spring.GameOver += new EventHandler<SpringLogEventArgs>(spring_GameOver);

      tas.BattleUserLeft += new EventHandler<TasEventArgs>(tas_BattleUserLeft);
      tas.UserStatusChanged += new EventHandler<TasEventArgs>(tas_UserStatusChanged);
      tas.BattleUserJoined += new EventHandler<TasEventArgs>(tas_BattleUserJoined);
      tas.BattleMapChanged += new EventHandler<TasEventArgs>(tas_BattleMapChanged);
      tas.BattleUserStatusChanged += new EventHandler<TasEventArgs>(tas_BattleUserStatusChanged);
      tas.BattleLockChanged += new EventHandler<TasEventArgs>(tas_BattleLockChanged);
      tas.BattleOpened += new EventHandler<TasEventArgs>(tas_BattleOpened);

      linker = new UnknownFilesLinker(spring);
      mapDownloader = new MapDownloader(spring);
      mapDownloader.DownloadCompleted += new EventHandler<TasEventArgs>(mapDownloader_DownloadCompleted);
      mapDownloader.DownloadProgressChanged += new EventHandler<TasEventArgs>(mapDownloader_DownloadProgressChanged);

      modDownloader = new ModDownloader(spring);
      modDownloader.DownloadCompleted += new EventHandler<TasEventArgs>(modDownloader_DownloadCompleted);
      modDownloader.DownloadProgressChanged += new EventHandler<TasEventArgs>(mapDownloader_DownloadProgressChanged);


      tas.BattleFound += new EventHandler<TasEventArgs>(tas_BattleFound);

    }
Ejemplo n.º 6
0
        /// <summary>
        /// Gets the screenshot from Gamebanana's API
        /// </summary>
        /// <param name="_ItemType">Gamebanana's Mod Type</param>
        /// <param name="_ItemID">Gamebanana's Mod ID</param>
        /// <param name="_GameID">Gamebanana's Game ID</param>
        /// <param name="_TypeID">Gamebanana's Category ID</param>
        /// <returns></returns>
        public static async Task <int> GetScreenshot(string _ItemType, string _ItemID, string Guid)
        {
            string downloadURL = "";

            queryParameters = GetDefaultParameters();
            queryParameters.Add(new QueryStringItem("itemid", _ItemID));
            queryParameters.Add(new QueryStringItem("itemtype", _ItemType));
            queryParameters.Add(new QueryStringItem("fields", "Preview().sSubFeedImageUrl()"));


            string queryURL = FormatAPIRequest("Core/Item/Data", queryParameters);

            try
            {
                using (HttpClient webClient = new HttpClient())
                {
                    HttpResponseMessage response = await webClient.GetAsync(queryURL);

                    if (response.IsSuccessStatusCode)
                    {
                        string responseText = await response.Content.ReadAsStringAsync();

                        Regex fileMatch = new Regex("sSubFeedImageUrl\\(\\)\":\"(.*?)\"");
                        Match match     = fileMatch.Match(responseText);

                        downloadURL = match.Value;
                        downloadURL = downloadURL.Split('"')[2];
                        downloadURL = downloadURL.Replace("\\/", "/");

                        string downloadextension = downloadURL.Split('.')[downloadURL.Split('.').Length - 1];

                        string imageSource  = Properties.Settings.Default.DefaultDir + @"\Library\Screenshots\" + Guid + "." + downloadextension;
                        string wimageSource = Properties.Settings.Default.DefaultDir + @"\Library\Screenshots\" + Guid + ".webp";

                        await ModDownloader.DownloadFile(downloadURL, imageSource);

                        if (downloadextension != "webp")
                        {
                            try
                            {
                                using (FileStream fsSource = new FileStream(imageSource, FileMode.Open, FileAccess.Read))
                                {
                                    byte[] ImageData = new byte[fsSource.Length];
                                    fsSource.Read(ImageData, 0, ImageData.Length);

                                    using (var webPFileStream = new FileStream(wimageSource, FileMode.Create))
                                    {
                                        using (ImageFactory imageFactory = new ImageFactory(preserveExifData: false))
                                        {
                                            imageFactory.Load(ImageData)
                                            .Format(new WebPFormat())
                                            .Quality(100)
                                            .Save(webPFileStream);
                                        }
                                    }
                                }



                                if (File.Exists(wimageSource))
                                {
                                    File.Delete(imageSource);
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.Message);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Write("fak");
            }

            return(0);
        }
Ejemplo n.º 7
0
 public void DownloadMod(ModInfoHolder ModRef, int TabPage)
 {
     if (TabPage != 0) // Is a server tab
     {
         if (ModRef.FoundOther == 1)
         {
             var localMod = ModInfoTools.LocalMods[ModRef.Name];
             //if (localMod.State == ModInfoHolder.ModState.Disabled)
             //{
             //    Log("Can't update a disabled mod!");
             //    return;
             //}
             if (ModDownloader.AddModDownload(ModRef, ModListStoreGithub))
             {
                 ModListStoreLocal.SetValue(localMod.TreeIter, (int)TreeColumnInfo.Desc, "Updating...");
             }
             return;
         }
         ModDownloader.AddModDownload(ModRef, ModListStoreGithub);
         return;
     }
     if (!string.IsNullOrEmpty(ModRef.CloudName))
     {
         ModInfoHolder cloudModInfo = null;
         if (ModRef.FoundOther == 0)
         {
             bool flag = true;
             try
             {
                 var repoItem = GetRepos.GetOneRepo(ModRef.CloudName);
                 if (ModInfoTools.GetGithubMod(repoItem))
                 {
                     cloudModInfo = ModInfoTools.lastGithubMod;
                     flag         = false;
                 }
             }
             catch (Exception E)
             {
                 Console.WriteLine(E);
             }
             if (flag)
             {
                 Log("Could not locate server mod!");
                 ModRef.FoundOther = -1;
                 return;
             }
         }
         if (cloudModInfo != null || ModInfoTools.GithubMods.TryGetValue(ModRef.CloudName, out cloudModInfo))
         {
             //if (modInfo.State == ModInfoHolder.ModState.Disabled)
             //{
             //    Log("Can't update a disabled mod!");
             //    return;
             //}
             if (ModDownloader.AddModDownload(cloudModInfo, ModListStoreGithub))
             {
                 ModListStoreLocal.SetValue(ModRef.TreeIter, (int)TreeColumnInfo.Desc, "Updating...");
                 return;
             }
         }
     }
     Log("Can't download mod!");
 }