示例#1
0
        private void DownloadNugetPackage(string moduleName)
        {
            var folderPath = string.Format("{0}\\{1}", ApplicationConfig.AppModulePath, moduleName.Replace("/", "_"));
            var filePath   = string.Format("{0}.zip", folderPath);

            try
            {
                if (!File.Exists(filePath))
                {
                    WebClient client      = new WebClientWithTimeout();
                    var       downloadUrl = string.Format("{0}{1}", "https://www.nuget.org/api/v2/package/", moduleName);
                    client.DownloadFile(downloadUrl, filePath);
                }
                ZipFile.ExtractToDirectory(filePath, folderPath);
            }
            catch (Exception ex)
            {
                try
                {
                    File.Delete(filePath);
                    Directory.Delete(folderPath, true);
                }
                catch (Exception e)
                {
                    _logger.Error(e.Message, e);
                }
                _logger.Error(string.Format("Error in downloading nuger package {0}, Error: {1}", moduleName, ex.Message), ex);
            }
        }
 private void DownloadRemoteProductStorage()
 {
     try
     {
         using (var webClient = new WebClientWithTimeout(WebRequestTimeout))
         {
             webClient.DownloadFile(storeRemoteProductRepo, storeLocalTempProductRepo);
         }
     }
     catch (Exception e)
     {
         LogProvider.Log.Error(this, "Remote storage of product app store has not been downloaded.", e);
     }
 }
示例#3
0
        private static void ValidateUrl(string url, string title, string genre)
        {
            Console.WriteLine("Trying url: {0}", url);

            try
            {
                Uri    uri      = new Uri(url);
                string hostName = uri.DnsSafeHost;

                //if (!QueryDnsWithTimeout(hostName, 300))
                //{
                //    Console.WriteLine("\t   -> Url: {0} is not valid (DNS error)", url);
                //    return;
                //}

                List <String> urlsToCkeck = new List <string>();

                if (IsPlaylist(url))
                {
                    string fileName = Path.GetFileName(uri.LocalPath);
                    string tempFile = @"c:\temp.pls";

                    using (WebClientWithTimeout wc = new WebClientWithTimeout())
                    {
                        wc.Timeout = 500;
                        wc.Proxy   = AppSettings.GetWebProxy();
                        wc.DownloadFile(uri, tempFile);
                    }

                    if (File.Exists(tempFile))
                    {
                        Playlist p = new Playlist();
                        p.LoadPlaylist(tempFile);

                        File.Delete(tempFile);

                        foreach (PlaylistItem item in p.AllItems)
                        {
                            urlsToCkeck.Add(item.Path);
                        }
                    }
                }
                else
                {
                    urlsToCkeck.Add(url);
                }

                foreach (string url2 in urlsToCkeck)
                {
                    //if (!QueryDnsWithTimeout(url2, 300))
                    //  continue;

                    ShoutcastStream ss = new ShoutcastStream(url2, 500);
                    if (ss.Connected)
                    {
                        RadioStation rs = new RadioStation {
                            Genre = genre, Title = title, Url = url2
                        };
                        data.RadioStations.Add(rs);

                        Console.WriteLine("\t   -> Added radio station: {0}", url2);

                        ss.Close();
                        ss.Dispose();
                        ss = null;
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("\t   ->" + ex.Message);
            }

            Console.WriteLine("\t   -> Url: {0} is not valid", url);
        }
示例#4
0
        private static void ValidateUrl(string url, string title, string genre)
        {
            Console.WriteLine("Trying url: {0}", url);

            try
            {
                Uri uri = new Uri(url);
                string hostName = uri.DnsSafeHost;

                //if (!QueryDnsWithTimeout(hostName, 300))
                //{
                //    Console.WriteLine("\t   -> Url: {0} is not valid (DNS error)", url);
                //    return;
                //}

                List<String> urlsToCkeck = new List<string>();

                if (IsPlaylist(url))
                {
                    string fileName = Path.GetFileName(uri.LocalPath);
                    string tempFile = @"c:\temp.pls";

                    using (WebClientWithTimeout wc = new WebClientWithTimeout())
                    {
                        wc.Timeout = 500;
                        wc.Proxy = AppSettings.GetWebProxy();
                        wc.DownloadFile(uri, tempFile);
                    }

                    if (File.Exists(tempFile))
                    {
                        Playlist p = new Playlist();
                        p.LoadPlaylist(tempFile);

                        File.Delete(tempFile);

                        foreach (PlaylistItem item in p.AllItems)
                        {
                            urlsToCkeck.Add(item.Path);
                        }
                    }
                }
                else
                {
                    urlsToCkeck.Add(url);
                }

                foreach(string url2 in urlsToCkeck)
                {
                    //if (!QueryDnsWithTimeout(url2, 300))
                      //  continue;

                    ShoutcastStream ss = new ShoutcastStream(url2, 500);
                    if (ss.Connected)
                    {
                        RadioStation rs = new RadioStation { Genre = genre, Title = title, Url = url2 };
                        data.RadioStations.Add(rs);

                        Console.WriteLine("\t   -> Added radio station: {0}", url2);

                        ss.Close();
                        ss.Dispose();
                        ss = null;
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine("\t   ->" + ex.Message);
            }

            Console.WriteLine("\t   -> Url: {0} is not valid", url);

        }
示例#5
0
        public void DoModNetJob()
        {
            File.Delete("ModManager.dat");

            if (!Directory.Exists("modules"))
            {
                Directory.CreateDirectory("modules");
            }
            if (!Directory.Exists("scripts"))
            {
                Directory.CreateDirectory("scripts");
            }
            String[] GlobalFiles         = new string[] { "dinput8.dll", "global.ini" };
            String[] ModNetReloadedFiles = new string[] { "7z.dll", "PocoFoundation.dll", "PocoNet.dll", "ModLoader.asi" };
            String[] ModNetLegacyFiles   = new string[] { "modules/udpcrc.soapbox.module", "modules/udpcrypt1.soapbox.module", "modules/udpcrypt2.soapbox.module", "modules/xmppsubject.soapbox.module",
                                                          "scripts/global.ini", "lightfx.dll", "ModManager.asi", "global.ini" };

            String[] RemoveAllFiles = GlobalFiles.Concat(ModNetReloadedFiles).Concat(ModNetLegacyFiles).ToArray();

            foreach (string file in RemoveAllFiles)
            {
                if (File.Exists(file))
                {
                    try {
                        File.Delete(file);
                    } catch {
                        MessageBox.Show($"File {file} cannot be deleted.", "GameLauncher", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }

            actionText.Text = "Detecting ModNetSupport for " + serverText.SelectedItem.ToString();
            String jsonModNet = ModNetReloaded.ModNetSupported(serverText.SelectedValue.ToString());

            if (jsonModNet != String.Empty)
            {
                actionText.Text = "ModNetReloaded support detected, downloading required files...";

                string[] newFiles = GlobalFiles.Concat(ModNetReloadedFiles).ToArray();
                try {
                    try { if (File.Exists("lightfx.dll"))
                          {
                              File.Delete("lightfx.dll");
                          }
                    } catch { }

                    WebClientWithTimeout newModNetFilesDownload = new WebClientWithTimeout();
                    foreach (string file in newFiles)
                    {
                        actionText.Text = "Fetching ModNetReloaded Files: " + file;
                        Application.DoEvents();
                        newModNetFilesDownload.DownloadFile("https://cdn.soapboxrace.world/modules/" + file, file);
                    }

                    try {
                        newModNetFilesDownload.DownloadFile("https://launcher.worldunited.gg/legacy/global.ini", "global.ini");
                    }
                    catch { }

                    SimpleJSON.JSONNode MainJson = SimpleJSON.JSON.Parse(jsonModNet);

                    Uri    newIndexFile = new Uri(MainJson["basePath"] + "/index.json");
                    String jsonindex    = new WebClientWithTimeout().DownloadString(newIndexFile);

                    SimpleJSON.JSONNode IndexJson = SimpleJSON.JSON.Parse(jsonindex);

                    CountFilesTotal = IndexJson["entries"].Count;

                    String path = Path.Combine("MODS", MDFive.HashPassword(MainJson["serverID"]).ToLower());
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    foreach (JSONNode modfile in IndexJson["entries"])
                    {
                        if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() != modfile["Checksum"])
                        {
                            WebClientWithTimeout client2 = new WebClientWithTimeout();
                            client2.DownloadFileAsync(new Uri(MainJson["basePath"] + "/" + modfile["Name"]), path + "/" + modfile["Name"]);

                            client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                            client2.DownloadFileCompleted   += (test, stuff) => {
                                if (SHA.HashFile(path + "/" + modfile["Name"]).ToLower() == modfile["Checksum"])
                                {
                                    CountFiles++;

                                    if (CountFiles == CountFilesTotal)
                                    {
                                        launchGame();
                                    }
                                }
                                else
                                {
                                    File.Delete(path + "/" + modfile["Name"]);
                                    Console.WriteLine(modfile["Name"] + " must be removed.");
                                    DoModNetJob();
                                }
                            };
                        }
                        else
                        {
                            CountFiles++;

                            if (CountFiles == CountFilesTotal)
                            {
                                launchGame();
                            }
                        }
                    }
                } catch (Exception ex) {
                    MessageBox.Show(ex.Message);
                }
            }
            else
            {
                string[] newFiles = GlobalFiles.Concat(ModNetLegacyFiles).ToArray();

                WebClientWithTimeout newModNetFilesDownload = new WebClientWithTimeout();
                foreach (string file in newFiles)
                {
                    actionText.Text = "Fetching LegacyModnet Files: " + file;
                    Application.DoEvents();
                    newModNetFilesDownload.DownloadFile("http://launcher.worldunited.gg/legacy/" + file, file);
                }

                if (result["modsUrl"] != null)
                {
                    actionText.Text = "Electron support detected, checking mods...";

                    Uri    newIndexFile           = new Uri(result["modsUrl"] + "/index.json");
                    String jsonindex              = new WebClientWithTimeout().DownloadString(newIndexFile);
                    SimpleJSON.JSONNode IndexJson = SimpleJSON.JSON.Parse(jsonindex);

                    CountFilesTotal = IndexJson.Count;

                    String electronpath = (new Uri(serverText.SelectedValue.ToString()).Host).Replace(".", "-");
                    String path         = Path.Combine("MODS", electronpath);
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }

                    File.WriteAllText(path + ".json", jsonindex);

                    using (var fs = new FileStream("ModManager.dat", FileMode.Create))
                        using (var bw = new BinaryWriter(fs)) {
                            bw.Write(CountFilesTotal);

                            foreach (JSONNode file in IndexJson)
                            {
                                var originalPath = Path.Combine(file["file"]).Replace("/", "\\").ToUpper();
                                var modPath      = Path.Combine(path, file["file"]).Replace("/", "\\").ToUpper();

                                bw.Write(originalPath.Length);
                                bw.Write(originalPath.ToCharArray());
                                bw.Write(modPath.Length);
                                bw.Write(modPath.ToCharArray());
                            }
                        }

                    foreach (JSONNode modfile in IndexJson)
                    {
                        String directorycreate = Path.GetDirectoryName(path + "/" + modfile["file"]);
                        Directory.CreateDirectory(directorycreate);

                        if (ElectronModNet.calculateHash(path + "/" + modfile["file"]) != modfile["hash"])
                        {
                            WebClientWithTimeout client2 = new WebClientWithTimeout();
                            client2.DownloadFileAsync(new Uri(result["modsUrl"] + "/" + modfile["file"]), path + "/" + modfile["file"]);

                            client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                            client2.DownloadFileCompleted   += (test, stuff) => {
                                if (ElectronModNet.calculateHash(path + "/" + modfile["file"]) == modfile["hash"])
                                {
                                    CountFiles++;

                                    if (CountFiles == CountFilesTotal)
                                    {
                                        launchGame();
                                    }
                                }
                                else
                                {
                                    File.Delete(path + "/" + modfile["file"]);
                                    Console.WriteLine(modfile["file"] + " must be removed.");
                                    DoModNetJob();
                                }
                            };
                        }
                        else
                        {
                            CountFiles++;

                            if (CountFiles == CountFilesTotal)
                            {
                                launchGame();
                            }
                        }
                    }
                }
                else if ((bool)result["rwacallow"] == true)
                {
                    actionText.Text = "RWAC support detected, checking mods...";

                    String rwacpath   = MDFive.HashPassword(new Uri(serverText.SelectedValue.ToString()).Host);
                    String path       = Path.Combine("MODS", rwacpath);
                    Uri    rwac_wev2  = new Uri(result["homePageUrl"] + "/rwac/fileschecker_sbrw.xml");
                    String getcontent = new WebClient().DownloadString(rwac_wev2);

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.LoadXml(getcontent);
                    var nodes = xmlDoc.SelectNodes("rwac/files/file");

                    CountFilesTotal = nodes.Count;

                    //ModManager.dat
                    using (var fs = new FileStream("ModManager.dat", FileMode.Create))
                        using (var bw = new BinaryWriter(fs)) {
                            bw.Write(nodes.Count);

                            foreach (XmlNode files in nodes)
                            {
                                string realfilepath    = Path.Combine(files.Attributes["path"].Value, files.Attributes["name"].Value);
                                String directorycreate = Path.GetDirectoryName(path + "/" + realfilepath);

                                var originalPath = Path.Combine(realfilepath).Replace("/", "\\").ToUpper();
                                var modPath      = Path.Combine(path, realfilepath).Replace("/", "\\").ToUpper();

                                bw.Write(originalPath.Length);
                                bw.Write(originalPath.ToCharArray());
                                bw.Write(modPath.Length);
                                bw.Write(modPath.ToCharArray());

                                Directory.CreateDirectory(directorycreate);
                                if (files.Attributes["download"].Value != String.Empty)
                                {
                                    if (MDFive.HashFile(path + "/" + realfilepath).ToLower() != files.InnerText)
                                    {
                                        WebClientWithTimeout client2 = new WebClientWithTimeout();
                                        client2.DownloadFileAsync(new Uri(files.Attributes["download"].Value), path + "/" + realfilepath);

                                        client2.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
                                        client2.DownloadFileCompleted   += (test, stuff) => {
                                            if (MDFive.HashFile(path + "/" + realfilepath).ToLower() == files.InnerText)
                                            {
                                                CountFiles++;

                                                if (CountFiles == CountFilesTotal)
                                                {
                                                    launchGame();
                                                }
                                            }
                                            else
                                            {
                                                File.Delete(path + "/" + realfilepath);
                                                Console.WriteLine(realfilepath + " must be removed.");
                                                DoModNetJob();
                                            }
                                        };
                                    }
                                    else
                                    {
                                        CountFiles++;

                                        if (CountFiles == CountFilesTotal)
                                        {
                                            launchGame();
                                        }
                                    }
                                }
                                else
                                {
                                    CountFiles++;

                                    if (CountFiles == CountFilesTotal)
                                    {
                                        launchGame();
                                    }
                                }
                            }
                        }
                }
                else
                {
                    actionText.Text = "Deprecated modnet detected. Aborting...";
                    launchGame();
                }
            }
        }