Beispiel #1
0
        private async Task <List <string> > DownloadCDBSFromGithub(string destinationFolder)
        {
            List <string> listOfCDBs = GitAccess.GetAllFilesWithExtensionFromYGOPRO("/", ".cdb");
            string        cdbFolder  = Path.Combine(destinationFolder, "cdb");

            if (!await FileDownload("cards.cdb", cdbFolder, "https://github.com/szefo09/cdb/raw/master/", true))
            {
                await FileDownload("cards.cdb", cdbFolder, "https://github.com/shadowfox87/ygopro2/raw/master/cdb/", true);
            }
            progressBar.Invoke(new Action(() => progressBar.Maximum = listOfCDBs.Count));
            List <string> listOfDownloadedCDBS = new List <string>()
            {
                Path.Combine(cdbFolder, "cards.cdb")
            };

            if (await FileDownload("prerelease-nfw.cdb", cdbFolder, "https://github.com/szefo09/cdb/raw/master/", true))
            {
                listOfDownloadedCDBS.Add(Path.Combine(cdbFolder, "prerelease-nfw.cdb"));
            }
            List <Task> downloadList = new List <Task>();

            foreach (string cdb in listOfCDBs)
            {
                FileDownload(cdb, cdbFolder, "https://github.com/Ygoproco/Live2017Links/raw/master/", true);
                listOfDownloadedCDBS.Add(Path.Combine(cdbFolder, cdb));
                progressBar.Invoke(new Action(() => progressBar.Increment(1)));
            }
            while (downloads > 1 - throttleValue)
            {
                Thread.Sleep(1);
            }
            return(listOfDownloadedCDBS);
        }
Beispiel #2
0
 public static bool CheckForUpdate()
 {
     try
     {
         List <GitHubCommit> gits    = GitAccess.GetHeaderCommit();
         List <string>       gitshas = new List <string>();
         foreach (GitHubCommit git in gits)
         {
             gitshas.Add(git.Sha);
         }
         gitshas.Sort();
         List <string> shas = LocalData.LoadFileToList("SHAs");
         if (shas == null)
         {
             LocalData.SaveFile(gitshas, "SHAs");
             shas = LocalData.LoadFileToList("SHas");
         }
         shas?.Sort();
         if (!shas.SequenceEqual(gitshas))
         {
             LocalData.SaveFile(gitshas, "SHAs");
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("Can't check for new updates!\n" + e.ToString());
     }
     return(false);
 }
Beispiel #3
0
 private void CheckForNewVersionOfPatcher(string version)
 {
     try
     {
         Release release = GitAccess.GetNewestYgoProPatcherRelease();
         if (release.TagName != null && release.TagName != version && MessageBox.Show("New version of YgoProPatcher detected!\nDo You want to download it?", "New Version detected!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             string dir;
             FolderBrowserDialog fbd = new FolderBrowserDialog
             {
                 ShowNewFolderButton = true,
                 SelectedPath        = System.Windows.Forms.Application.StartupPath,
                 Description         = "Select where you want to download YgoProPatcher ZIP File:"
             };
             DialogResult result = fbd.ShowDialog();
             if (result == DialogResult.OK)
             {
                 dir = fbd.SelectedPath;
             }
             else
             {
                 return;
             }
             string fileName = Path.Combine(dir, "YgoProPatcher" + release.TagName + ".zip");
             using (WebClient client = new WebClient())
             {
                 client.DownloadFile(new System.Uri(release.Assets[0].BrowserDownloadUrl), fileName);
             }
             if (new FileInfo(fileName).Exists)
             {
                 MessageBox.Show("New YgoProPatcher" + release.TagName + ".zip was succesfully\ndownloaded to the target location.\nPlease extract the newest release and use it!\n\nThis app will now close.", "Download completed!");
                 try
                 {
                     System.Diagnostics.Process.Start(fileName);
                 }
                 catch
                 {
                 }
                 finally
                 {
                     Environment.Exit(0);
                 }
             }
         }
     }
     catch (Exception e)
     {
         if (!(e is AggregateException))
         {
             MessageBox.Show("Couldn't check for new version of YgoProPatcher.\nMake sure You are connected to the internet or no program blocks the patcher!\n\n");
         }
     }
 }
Beispiel #4
0
        private async Task GitDownloadFacesAsync()
        {
            List <string> Faces = GitAccess.GetAllFilesWithExtensionFromRepo("Szefo09", "face", "/", "png");

            foreach (string face in Faces)
            {
                if (threadRunning)
                {
                    string filePath = Path.Combine(YgoPro2Path.Text, @"texture\face");
                    await FileDownload(face, filePath, Data.GetFacesWebsite(), true);
                }
            }
        }
Beispiel #5
0
        static public List <string> GetAllFilesWithExtensionFromRepo(string owner, string repo, string path, string extension)
        {
            List <RepositoryContent> result    = GitAccess.GetRepositoryContent(owner, repo, path);
            List <string>            fileNames = new List <string>();

            foreach (var c in result)
            {
                if (c.Name.Contains(extension))
                {
                    fileNames.Add(c.Name);
                }
            }
            return(fileNames);
        }
Beispiel #6
0
        static public List <string> GetAllFilesWithExtensionFromYGOPRO(string path, string extension)
        {
            List <RepositoryContent> result    = GitAccess.GetRepositoryContent("Ygoproco", "Live2017Links", path);
            List <string>            fileNames = new List <string>();

            foreach (var c in result)
            {
                if (c.Name.Contains(extension))
                {
                    fileNames.Add(c.Name);
                }
            }
            return(fileNames);
        }
Beispiel #7
0
        static public void Download(string path)
        {
            string        tempFolder = Path.Combine(path, "temp");
            DirectoryInfo directory  = new DirectoryInfo(tempFolder);

            try
            {
                if (!directory.Exists)
                {
                    directory.Create();
                    directory.Attributes = FileAttributes.Directory | FileAttributes.Hidden;
                }
                else
                {
                    foreach (var info in directory.GetFileSystemInfos("*", SearchOption.AllDirectories))
                    {
                        info.Attributes = FileAttributes.Normal;
                    }
                    directory.Delete(true);
                }

                Repository.Clone(GitAccess.GetURLofRepo(Data.YgoPro2Owner, "ygopro2"), directory.FullName);
                DirectoryInfo gitFolder = new DirectoryInfo(Path.Combine(tempFolder, ".git"));
                if (gitFolder.Exists)
                {
                    foreach (var info in gitFolder.GetFileSystemInfos("*", SearchOption.AllDirectories))
                    {
                        info.Attributes = FileAttributes.Normal;
                    }
                    gitFolder.Delete(true);
                }

                Copy(tempFolder, path);
                return;
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show("There was an error during the download of the new client. Please try launching this program as an Administrator.\n\nError Code:\n" + e.ToString());
            }
            finally
            {
                foreach (var info in directory.GetFileSystemInfos("*", SearchOption.AllDirectories))
                {
                    info.Attributes = FileAttributes.Normal;
                }
                directory.Delete(true);
            }
        }