Ejemplo n.º 1
0
        private async void ValidateFiles_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.currentFileText("");
            this.progressBarFileValue(0);
            this.progressBarAllValue(0);

            Properties.Settings.Default.LastRepoFileHash = repoReader.CalculateFileHash(repoReader.GetRepoFile());
            Properties.Settings.Default.Save();

            if (this.isInstall)
            {
                this.installFiles.RunWorkerAsync();
            }
            else
            {
                this.progressBarFileStyle(ProgressBarStyle.Continuous);
                this.progressStatusText("Waiting for orders");
                await this.taskDelay(1500);

                this.mainForm.HideDownloadPanel();
                mainForm.ReadRepo(true, true);
            }
        }
Ejemplo n.º 2
0
        private void Builder_DoWork(object sender, DoWorkEventArgs e)
        {
            if (File.Exists(repoPath + "repoList.a3l"))
            {
                File.Delete(repoPath + "repoList.a3l");
            }

            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            long filesCount    = Directory.GetFiles(repoPath, "*", SearchOption.AllDirectories).LongLength;
            int  filesSelected = 0;
            int  filesDone     = 0;

            string[] items = new string[filesCount];

            items = Directory.GetFiles(repoPath, "*", SearchOption.AllDirectories);

            try
            {
                foreach (string item in items)
                {
                    for (int i = 0; i < addonsList.CheckedItems.Count; i++)
                    {
                        if (addonsList.CheckedItems[i].ToString() == item.Remove(0, repoPath.Length).Split('\\')[0])
                        {
                            filesSelected++;
                        }
                    }
                }

                using (FileStream fs = File.Create(repoPath + "repoList.a3l"))
                {
                    foreach (string item in items)
                    {
                        bool addIt = false;

                        for (int i = 0; i < addonsList.CheckedItems.Count; i++)
                        {
                            if (addonsList.CheckedItems[i].ToString() == item.Remove(0, repoPath.Length).Split('\\')[0])
                            {
                                addIt = true;
                            }
                        }


                        if (addIt)
                        {
                            int splitCount = item.Split('\\').Length;
                            this.buildLogText(Environment.NewLine + "Adding: " + item.Split('\\')[splitCount - 1]);

                            byte[] file = new UTF8Encoding(true).GetBytes(
                                repoReader.CalculateFileHash(item) + "*" +
                                string.Format("{2:0000}{1:00}{0:00}{3:00}{4:00}{5:00}", File.GetLastWriteTime(item).Day, File.GetLastWriteTime(item).Month, File.GetLastWriteTime(item).Year, File.GetLastWriteTime(item).Hour, File.GetLastWriteTime(item).Minute, File.GetLastWriteTime(item).Second) + "*" +
                                item.Remove(0, repoPath.Length)
                                );
                            fs.Write(file, 0, file.Length);

                            byte[] newline = Encoding.ASCII.GetBytes(Environment.NewLine);
                            fs.Write(newline, 0, newline.Length);

                            filesDone++;
                        }

                        this.progressBarFileValue(Convert.ToInt32(((double)filesDone / filesSelected) * 100));

                        if (this.builder.CancellationPending)
                        {
                            e.Cancel = true; break;
                        }
                    }
                }
            }
            catch (Exception ex) { new Windows.MessageBox().Show(ex.Message, "Error while building repository", MessageBoxButtons.OK, MessageIcon.Error); }
            finally
            {
                // Get the elapsed time as a TimeSpan value.
                TimeSpan ts = stopWatch.Elapsed;

                // Format and display the TimeSpan value.
                string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                   ts.Hours, ts.Minutes, ts.Seconds,
                                                   ts.Milliseconds / 10);

                stopWatch.Stop();

                this.buildLogText(Environment.NewLine);
                this.buildLogText(Environment.NewLine + "Files in repository folder: " + filesCount);
                this.buildLogText(Environment.NewLine + "Files added to catalog: " + filesDone + " of " + filesSelected);
                this.buildLogText(Environment.NewLine + "Catalog built in: " + elapsedTime);
            }
        }