Example #1
0
        private async Task RepeatDownloadFile(DriveService service, string url)
        {
            System.Windows.Forms.DialogResult dialog;

            do
            {
                await DownloadFile(service, url);

                if (HashFile.GetMD5(Launcher.Name[number]) == Launcher.Hash[number].ToUpper())
                {
                    this.downloadNumber++;
                    this.downloadSize        += Launcher.Size[number];
                    this.labelTotalValue.Text = String.Format("{0:0.00}/{1:0.00} MB", downloadSize / 1048576.0, downloadTotal / 1048576.0);
                    break;
                }
                this.Hide(); //skrivanje forme radi prikaza poruke
                dialog = MessageErrorDownload(Launcher.Name[number]);
                this.Show(); //pokazivanje forme nakon poruke

                if (dialog == DialogResult.No)
                {
                    this.errorFiles.Add(new ErrorFile(++errorNumber, Launcher.Name[number], Launcher.Size[number], "Neispravan"));
                }
            } while (dialog == DialogResult.Yes);
        }
Example #2
0
        private void DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            int i = number;

            if (HashFile.GetMD5(Launcher.Name[i]) != Launcher.Hash[i].ToUpper())
            {
                errorResult = ErrorResult.Download;
            }
        }
Example #3
0
        public bool Valid()
        {
            if (!this.Check())
            {
                return(false);
            }

            //provjera počinje od 4te datoteke
            for (int i = 1; i < name.Length; i++)
            {
                if (HashFile.GetMD5(this.name[i]) != this.hash[i])
                {
#if TRACE
                    Trace.TraceInformation("Library.Valid(); File: {0}; Hash: {1}; Base: {2}", name[i], HashFile.GetMD5(name[i]), hash[i]);
#endif
                    return(false);
                }
            }

            return(true);
        }
Example #4
0
        private void UpdateForm_Shown(object sender, EventArgs e)
        {
            this.progressOne.Maximum = 100;
            this.progressAll.Maximum = Launcher.Name.Length - 1;

            Thread thread = new Thread(() =>
            {
                Network net   = new Network();
                GoogleApi api = new GoogleApi();

                Thread.Sleep(1000);
                errorResult = ErrorResult.None;

                this.BeginInvoke((MethodInvoker) delegate
                {
                    labelName.Text = "Spajanje na servis za preuzimanje...";
                });

                DriveService service = new GDriveAccount().Authenticate();
                if (service == null)
                {
                    errorResult = ErrorResult.Service;
                }

                for (int i = 0; i < Launcher.Name.Length; i++)
                {
                    if (errorResult != ErrorResult.None)
                    {
                        break;
                    }

                    this.BeginInvoke((MethodInvoker) delegate
                    {
                        progressOne.Value = 0;
                        progressAll.Value = i;
                        labelValue.Text   = String.Empty;

                        if (Launcher.Name[i].Length > 30)
                        {
                            labelName.Text = String.Format("Fajl {0}/{1}: {2}", i + 1, Launcher.Name.Length, String.Format("...{0}", Launcher.Name[i].Substring(Launcher.Name[i].Length - 24)));
                        }
                        else
                        {
                            labelName.Text = String.Format("Fajl {0}/{1}: {2}", i + 1, Launcher.Name.Length, Launcher.Name[i]);
                        }
                    });

                    bool exist = System.IO.File.Exists(Launcher.Name[i]);

                    if (!exist || Launcher.Valid[i] && HashFile.GetMD5(Launcher.Name[i]) != Launcher.Hash[i].ToUpper())
                    {
                        number = i;
                        if (!net.Available())
                        {
                            errorResult = ErrorResult.Network;
                            break;
                        }

                        string path = Path.GetDirectoryName(Launcher.Name[i]);
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }

                        if (Launcher.Size[number] > 1048576)
                        {
                            size = Launcher.Size[number] / 1048576.0;
                        }
                        else
                        {
                            size = Launcher.Size[number] / 1024.0;
                        }

                        //Uri address = new Uri(String.Format("https://drive.google.com/uc?export=download&id={0}", Launcher.Link[i]));
                        //
                        //using (WebClient client = new WebClient())
                        //{
                        //   client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
                        //    //client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);
                        //
                        //    client.DownloadFileAsync(address, Launcher.Name[i]);
                        //    while (client.IsBusy) Thread.Sleep(500);
                        //}
                        //
                        //if (HashFile.GetMD5(Launcher.Name[i]) == Launcher.Hash[i]) continue;


                        //google drive api download
                        var request = service.Files.Get(Launcher.Link[i]);
                        //GoogleFile file = service.Files.Get(Launcher.Link[i]).Execute();

                        if (Launcher.Size[i] > 1048576)
                        {
                            request.MediaDownloader.ChunkSize = 1024 * 512;
                        }
                        else
                        {
                            request.MediaDownloader.ChunkSize = 1024 * 4;
                        }

                        using (FileStream fs = new FileStream(Launcher.Name[i], FileMode.Create, FileAccess.Write))
                        {
                            request.MediaDownloader.ProgressChanged += (IDownloadProgress progress) =>
                            {
                                switch (progress.Status)
                                {
                                case DownloadStatus.Downloading:
                                    {
                                        this.BeginInvoke((MethodInvoker) delegate
                                        {
                                            //double bytesIn = double.Parse(progress.BytesDownloaded.ToString());
                                            //double totalBytes = double.Parse(Launcher.Size[i].ToString());
                                            //double percentage = bytesIn / totalBytes * 100;
                                            //progressOne.Value = int.Parse(Math.Truncate(percentage).ToString());
                                            progressOne.Value = (int)(((double)progress.BytesDownloaded / Launcher.Size[i]) * 100);

                                            if (Launcher.Size[i] > 1048576)
                                            {
                                                labelValue.Text = String.Format("{0:0.00}/{1:0.00} MB", progress.BytesDownloaded / 1048576.0, size);
                                            }
                                            else
                                            {
                                                labelValue.Text = String.Format("{0:0.00}/{1:0.00} KB", progress.BytesDownloaded / 1024.0, size);
                                            }

                                            //if (Launcher.Size[i] < 1048576) //1MB = 1B * 1024 * 1024 = 1038576 B
                                            //    labelValue.Text = String.Format("{0:0.00}/{1:0.00} KB", Math.Truncate((bytesIn / 1024) * 100) / 100, Math.Truncate((totalBytes / 1024) * 100) / 100);
                                            //else
                                            //    labelValue.Text = String.Format("{0:0.00}/{1:0.00} MB", Math.Truncate((bytesIn / 1048576) * 100) / 100, Math.Truncate((totalBytes / 1048576) * 100) / 100);


                                            //////double bytesIn = double.Parse(progress.BytesDownloaded.ToString());
                                            //////double totalBytes = double.Parse(Launcher.Size[number].ToString());
                                            //////double percentage = bytesIn / totalBytes * 100;
                                            ////int value = (int)((progress.BytesDownloaded / Launcher.Size[number]) * 100);
                                            ////progressOne.Value = value;

                                            //if (Launcher.Size[number] < 1048576) //1MB = 1B * 1024 * 1024 = 1038576 B
                                            //    labelValue.Text = String.Format("{0}/{1} KB", (progress.BytesDownloaded / 1024), Launcher.Size[i] / 1024);
                                            //else
                                            //    labelValue.Text = String.Format("{0}/{1} MB", (progress.BytesDownloaded / 1048576), Launcher.Size[i] / 1048576);


                                            //double bytesIn = double.Parse(progress.BytesDownloaded.ToString());
                                            //double totalBytes = double.Parse(Launcher.Size[number].ToString());
                                            //double percentage = bytesIn / totalBytes * 100;
                                            //progressOne.Value = int.Parse(Math.Truncate(percentage).ToString());

                                            ////if (Launcher.Size[number] < 1048576) //1MB = 1B * 1024 * 1024 = 1038576 B
                                            ////    labelValue.Text = String.Format("{0:0.00}/{1:0.00} KB", Math.Truncate((bytesIn / 1024) * 100) / 100, Math.Truncate((totalBytes / 1024) * 100) / 100);
                                            ////else
                                            ////    labelValue.Text = String.Format("{0:0.00}/{1:0.00} MB", Math.Truncate((bytesIn / 1048576) * 100) / 100, Math.Truncate((totalBytes / 1048576) * 100) / 100);
                                        });

                                        if (Launcher.Size[i] > 1048576)
                                        {
                                            request.MediaDownloader.ChunkSize += 1024 * 16;
                                        }
                                        else
                                        {
                                            request.MediaDownloader.ChunkSize += 1024 * 2;
                                        }

                                        break;
                                    }

                                case DownloadStatus.Completed:
                                    {
                                        this.BeginInvoke((MethodInvoker) delegate
                                        {
                                            progressOne.Value = 100;
                                        });
                                        Thread.Sleep(100);
                                        break;
                                    }

                                case DownloadStatus.Failed:
                                    {
                                        if (Launcher.Size[i] > 0)
                                        {
                                            errorResult = ErrorResult.Download;
                                        }
                                        break;
                                    }
                                }
                            };
                            request.Download(fs);
                        }

                        if (HashFile.GetMD5(Launcher.Name[i]) != Launcher.Hash[i].ToUpper())
                        {
                            errorResult = ErrorResult.Download;
                        }



                        //using (WebClient client = new WebClient())
                        //{
                        //    client.if (HashFile.GetMD5(Launcher.Name[i]) != Launcher.Hash[i]) errorResult = ErrorResult.Download; += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
                        //    client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);

                        //    string path = Path.GetDirectoryName(Launcher.Name[i]);
                        //    if (!Directory.Exists(path)) Directory.CreateDirectory(path);

                        //    if (!net.Available())
                        //    {
                        //        errorResult = ErrorResult.Network;
                        //        break;
                        //    }

                        //    client.DownloadFileAsync(address, filename);
                        //    while (client.IsBusy) Thread.Sleep(1000);
                        //}
                        //address = String.Format("https://drive.google.com/uc?export=download&id={0}", Launcher.Link[i]);

                        //using (WebClient client = new WebClient())
                        //{
                        //    client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged);
                        //    client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted);

                        //    string path = Path.GetDirectoryName(Launcher.Name[i]);
                        //    if (!Directory.Exists(path)) Directory.CreateDirectory(path);

                        //    if (!net.Available())
                        //    {
                        //        errorResult = ErrorResult.Network;
                        //        thread.Abort();
                        //        break;
                        //    }

                        //    client.DownloadFileAsync(new Uri(address), Launcher.Name[i]);
                        //    while (client.IsBusy) Thread.Sleep(1000);
                        //}

                        //if (HashFile.GetMD5(Launcher.Name[i]) != Launcher.Hash[i])
                        //{
                        //    errorResult = ErrorResult.Download;
                        //}
                    }
                    else
                    {
                        this.BeginInvoke((MethodInvoker) delegate
                        {
                            progressOne.Value = 100;
                        });
                        Thread.Sleep(100);
                    }
                }

                this.BeginInvoke((MethodInvoker) delegate
                {
                    this.Hide();

                    string text;
                    MessageTitle title = new MessageTitle();

                    if (errorResult == ErrorResult.None)
                    {
                        text = "Ažuriranje moda Columbia State je uspješno završeno.";
                        MessageBoxAdv.Show(text, title.InfoMsg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else if (errorResult == ErrorResult.Network)
                    {
                        text = "Vaša internet konekcija ne radi ili je prekinuta.";
                        MessageBoxAdv.Show(text, title.WarningMsg, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (errorResult == ErrorResult.Service)
                    {
                        text = "Autentifikacija sa fajlovima nije validna, ažuriranje je prekinuto.";
                        MessageBoxAdv.Show(text, title.ErrorMsg, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        this.DialogResult = System.Windows.Forms.DialogResult.Abort;
                    }
                    else if (errorResult == ErrorResult.Download)
                    {
                        text = String.Format("Došlo je do pogreške prilikom ažuriranja na fajlu: {0}", Path.GetFileName(Launcher.Name[number]));
                        MessageBoxAdv.Show(text, title.ErrorMsg, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    //GC.Collect();
                    this.Close();
                });
            });


            thread.Priority     = ThreadPriority.Lowest;
            thread.IsBackground = true;
            thread.Start();
        }
Example #5
0
        static void Main(string[] args)
        {
#if !DEBUG
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Library lib = new Library();
            if (!lib.Valid())
            {
                MessageTitle title   = new MessageTitle();
                string       message = "Biblioteke datoteka od Columbia State Launchera nisu isparavne.\n" +
                                       "Da li želite pokreniti servis ažuriranja i nadomjestiti ispravnim?\n" +
                                       "Napomena, launcher ne može biti pokrenuta ako datoteke nisu validne.";

                if (DialogResult.No == MessageBox.Show(message, title.ErrorMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Stop))
                {
                    return;
                }

                ColumbiaUpdate update = new ColumbiaUpdate();

                if (update.DownloadFile())
                {
                    update.RunFile();
                    Application.Exit();
                    return;
                }
                else
                {
                    message = "Servis Columbia State Launcher Update trenutno ne postoji.\n" +
                              "Ovaj korak će biti implemnetiran u novijim ažuriranjima launchera.";

                    MessageBox.Show(message, title.ErrorMsg, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                return;
            }

            LauncherBase lan = new LauncherBase();
            if (lan.Read())
            {
                Launcher.SlideShow = lan.SlideNumber;
                if (HashFile.GetMD5("columbia.exe") != lan.HashLauncher)
                {
                    MessageTitle title   = new MessageTitle();
                    string       message = "Vaša verzija Columbia State Launchera nije posljednja.\n" +
                                           "Da li želite sada ažurirati launcher na zadnju verziju?\n" +
                                           "Napomena, za pristpu našem serveru aplikacija treba biti najnovija.";
                    if (DialogResult.Yes == MessageBoxAdv.Show(message, title.ErrorMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Error))
                    {
                        ColumbiaUpdate update = new ColumbiaUpdate();

                        if (update.DownloadFile())
                        {
                            update.RunFile();
                            Application.Exit();
                        }
                        else
                        {
                            message = "Servis Columbia State Launcher Update trenutno ne postoji.\n" +
                                      "Ovaj korak će biti implemnetiran u novijim ažuriranjima launchera.";

                            MessageBoxAdv.Show(message, title.ErrorMsg, MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    return;
                }

                /*else if (HashFile.GetMD5("update-cs.exe") != lan.HashUpdate)
                 * {
                 *  MessageTitle title = new MessageTitle();
                 *  string message = "Vaša verzija Columbia State Update servisa nije posljednja.\n" +
                 *                   "Da li želite sada ažurirati update servis na zadnju verziju?\n" +
                 *                   "Napomena, za pristpu našem serveru servis treba biti najnoviji.";
                 *
                 *  MessageBoxAdv.Show(message, title.ErrorMsg, MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                 *
                 *  message = "Implementacija u novim ažuriranjem Columbia State Launcher-a.";
                 *  MessageBoxAdv.Show(message, title.InfoMsg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                 * }*/
            }
            else
            {
                MessageTitle title   = new MessageTitle();
                string       message = "Nažalost došlo je do greške pri spajanju sa bazom podataka.\n" +
                                       "Provjerite svoju internet konekciju ili kontaktirajte administraciju.";
                MessageBoxAdv.Show(message, title.ErrorMsg, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            lan = null;
            lib = null;

            if (args.Length > 0)
            {
                string       message;
                MessageTitle title = new MessageTitle();
                if (args[0] == "0")
                {
                    message = "Ažuriranje Columbia State Launchera je uspješno urađeno.\n" +
                              "Želimo vam ugodno korištenje, sve primjedbe pišite na forumu.";
                    MessageBoxAdv.Show(message, title.InfoMsg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    message = "Ažuriranje Columbia State Launchera je neuspješno.\n" +
                              "Detaljnije obrađena poruka u novijim nadogradnjama.";
                    MessageBoxAdv.Show(message, title.InfoMsg, MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
#endif

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(new LoadForm());
            //Application.Run(new DownloadForm());
        }
Example #6
0
        private void workerFile_DoWork(object sender, DoWorkEventArgs e)
        {
            this.number        = 0;
            this.fileMissed    = 0;
            this.fileUnknown   = 0;
            this.fileIncorrect = 0;
            files    = new List <CheckFile>();
            e.Result = ErrorResult.None;
            // Get the BackgroundWorker that raised this event.
            BackgroundWorker worker = sender as BackgroundWorker;

            Library  lib = new Library();
            DataFile df  = new DataFile();

            //provjera nedostajucih fajlova
            if (df.CheckMissed(Launcher.Name))
            {
                errorResult = true;
                //e.Result = ErrorResult.Missed;
                df.ReadMissed(Launcher.Name);
                foreach (int id in df.MissedFiles)
                {
                    fileMissed++;
                    files.Add(new CheckFile(++number, Launcher.Name[id], Launcher.Size[id], "Nedostaje"));
                }

                //return;
            }
            //provjera da li je pritisnut prekid
            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
            //provjera nepoznatih fajlova
            if (df.CheckUnknown(Launcher.Name, lib.Name))
            {
                errorResult = true;
                //e.Result = ErrorResult.Unknown;
                df.ReadUnknown(Launcher.Name, lib.Name);
                foreach (string file in df.UnknownFiles)
                {
                    fileUnknown++;
                    long length = new System.IO.FileInfo(file).Length;
                    files.Add(new CheckFile(++number, file, length, "Nepoznat"));
                }
                //return;
            }
            //provjera da li je pritisnut prekid
            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            //provjera hash fajlova koji su oznaceni za provjeru (valid)
            for (int i = 0; i < Launcher.Name.Length; i++)
            {
                //provjera da li je pritisnuto za prekid
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                workerFile.ReportProgress(i);
#if DEBUG
                //Thread.Sleep(250);
#endif

                if (Launcher.Valid[i])
                {
                    if (HashFile.GetMD5(Launcher.Name[i]) != Launcher.Hash[i].ToUpper())
                    {
                        fileIncorrect++;
                        errorResult = true;
                        files.Add(new CheckFile(++number, Launcher.Name[i], Launcher.Size[i], "Neispravan"));
                        //e.Result = ErrorResult.Validated;
                        //return;
                    }
                }
            }
        }
Example #7
0
        private void WorkerFile_DoWork(object sender, DoWorkEventArgs e)
        {
            this.number        = 0;
            this.fileMissed    = 0;
            this.fileUnknown   = 0;
            this.fileIncorrect = 0;
            Library  lib = new Library();
            DataFile df  = new DataFile();

            this.errorFiles = new List <ErrorFile>();
            this.fileStream = new List <FileStream>();
            BackgroundWorker worker = sender as BackgroundWorker;

            //provjera nepoznatih fajlova
            if (df.CheckUnknown(Launcher.Name, lib.Name))
            {
                df.ReadUnknown(Launcher.Name, lib.Name);
                foreach (string file in df.UnknownFiles)
                {
                    //ako fajl u medjuvremenu nestane
                    if (!File.Exists(file))
                    {
                        continue;
                    }
                    this.fileUnknown++; //brojac nepoznatih fajlova
                    long length = new System.IO.FileInfo(file).Length;
                    this.errorFiles.Add(new ErrorFile(++number, file, length, "Nepoznat"));
                }
            }
            //provjera zahtjeva za izlaz
            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            //provjera nedostajucih fajlova
            if (df.CheckMissed(Launcher.Name))
            {
                df.ReadMissed(Launcher.Name);
                foreach (int id in df.MissedFiles)
                {
                    this.id.Add(id);   //fajl koji nedotaje takodje se dodaje na listu za skidanje (download);
                    this.fileMissed++; //brojac nedostajucih fajlova
                    this.errorFiles.Add(new ErrorFile(++number, Launcher.Name[id], Launcher.Size[id], "Nedostaje"));
                }
            }
            //provjera zahtjeva za izlaz
            if (worker.CancellationPending)
            {
                e.Cancel = true;
                return;
            }

            //provjera za sve fajlove;
            for (int i = 0; i < Launcher.Name.Length; i++)
            {
                workerFile.ReportProgress(i);
                //provjera zahtjeva za izlaz
                if (worker.CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }

                if (File.Exists(Launcher.Name[i]) && Launcher.Valid[i])
                {
                    if (HashFile.GetMD5(Launcher.Name[i]) != Launcher.Hash[i].ToUpper())
                    {
                        this.id.Add(i);
                        this.fileIncorrect++;
                        this.errorFiles.Add(new ErrorFile(++number, Launcher.Name[i], Launcher.Size[i], "Neispravan"));
                    }

                    /*this.fileStream.Clear();
                     * for (int j = 0; j <= i; j++)
                     * {
                     *  if (this.id.Count > 0)
                     *  {
                     *      bool skip = false;
                     *      foreach (int index in this.id)
                     *      {
                     *          if (j == index)
                     *          {
                     *              skip = true;
                     *              break;
                     *          }
                     *      }
                     *      if (skip) continue;
                     *  }
                     *
                     *  this.fileStream.Add(new FileStream(Launcher.Name[j], FileMode.Open, FileAccess.Read, FileShare.Read));
                     * }*/
                }
            }
        }