Exemplo n.º 1
0
        public void StartTransfer(MainUI mainUI)
        {
            Stopwatch stopwatch = new Stopwatch();

            mainUI.ChangeProgressBarState(ProgressBarStyle.Marquee, progressBar);

            installedProvinceFiles.Sort(new CompareFiles());
            provinceNumbers.Sort();

            mainUI.SetMaxNumber(installedProvinceFiles.Count, progressBar);

            if (!Directory.Exists(copyTo))
            {
                Directory.CreateDirectory(copyTo);
            }

            log.WriteLine(copyTo);

            mainUI.ChangeProgressBarState(ProgressBarStyle.Continuous, progressBar);
            stopwatch.Start();
            for (int i = 0; i < installedProvinceFiles.Count; i++)
            {
                Application.DoEvents();
                int installedProvinceFileNumber = CompareFiles.IsolateFileNumber(installedProvinceFiles[i]);

                for (int j = 0; j < provinceNumbers.Count; j++)
                {
                    Application.DoEvents();
                    log.WriteLine("Comparing " + provinceNumbers[j] + " with " + installedProvinceFileNumber + " and it's " + (installedProvinceFileNumber == provinceNumbers[j]));
                    if (installedProvinceFileNumber == provinceNumbers[j])
                    {
                        string newFile = Path.Combine(copyTo, installedProvinceFiles[i].Substring(installedProvinceFiles[i].LastIndexOf('\\') + 1));
                        log.WriteLine(newFile);
                        if (File.Exists(newFile))
                        {
                            File.Delete(newFile);
                        }

                        Application.DoEvents();

                        File.Copy(installedProvinceFiles[i], newFile);

                        installedProvinceFiles.Remove(installedProvinceFiles[i]);

                        int tempHold = provinceNumbers[j];
                        for (int k = 0; k < provinceNumbers.Count; k++)
                        {
                            Application.DoEvents();
                            if (provinceNumbers[k] == tempHold)
                            {
                                provinceNumbers.RemoveAt(k);
                            }
                        }
                        i--;
                        break;
                    }
                    else if (provinceNumbers[j] > installedProvinceFileNumber)
                    {
                        break;
                    }
                }

                mainUI.IncrementPercentDone(1, progressBar);
            }

            if (provinceNumbers.Count != 0)
            {
                StringBuilder builder = new StringBuilder("Hello User, there was a problem, this file does not appear to be in the install path you provided.\n" +
                                                          "Please launch Steam, right click on Europea Universallies IV and click properties, then go to Local Files, and then click \"Virify" +
                                                          " integraty of game files...\".\nIf it comes back with nothing/1 file missing, then please have a look for yourself.\nIf you cannot" +
                                                          " figure it out, please submit a bug report.\nThe following provinces were not found at all:\n");
                foreach (int provinceNumber in provinceNumbers)
                {
                    builder.Append(provinceNumber + " ");
                }

                builder.Append("\nPlease note, check to see if their aren't any duplicant numbers in the list," +
                               " if not and the province does exist in their then please contact the developer.");

                StreamWriter writer = File.CreateText(Path.Combine(copyTo, "1.)IMPORTANT! README.txt"));
                writer.Write(builder.ToString());
                writer.Flush();
                writer.Close();

                MessageBox.Show("A problem has occured. Please read 1.)IMPORTANT! README.txt located at \"" + copyTo + "\".");
            }

            stopwatch.Stop();
            log.WriteLine(stopwatch.ElapsedMilliseconds + " milliseconds or " + stopwatch.ElapsedMilliseconds / 1000f + " seconds.");
        }
Exemplo n.º 2
0
        public void StartComparing()
        {
            mainUI.ChangeProgressBarState(ProgressBarStyle.Marquee, progressBar);

            //ArrayList are used to store all the lines later on.
            ArrayList TextList1 = new ArrayList(), TextList2 = new ArrayList();

            //This method splits the text in the files and puts them into the ArrayList.
            AddStringToList(File.ReadAllText(File1Loc), TextList1);
            AddStringToList(File.ReadAllText(File2Loc), TextList2);

            mainUI.ChangeProgressBarState(ProgressBarStyle.Continuous, progressBar);

            //StringBuilder is used for it's .Append method.
            StringBuilder ForOutputBox = new StringBuilder($"Differences in {File1Name} and {File2Name}:");

            //To see which file is the shorted aand to use it as the length.
            int progressLength = TextList1.Count < TextList2.Count ? TextList1.Count : TextList2.Count;

            mainUI.SetMaxNumber(progressLength, progressBar);

            //To keep track of the line it's on.
            int line = 1;

            //While loop used since a for loop would have to be constantly reset to 0.
            while (TextList1.Count != 0 && TextList2.Count != 0)
            {
                //Read MSDev for this line.
                Application.DoEvents();

                //In order to use string comparison, they have to be converted from object to string.
                string string1 = ( string )TextList1[0];
                string string2 = ( string )TextList2[0];

                //Just logs which lines it's comparing.
                Log.GetInstence().WriteLine($"Comparing \"{string1}\" and \"{string2}\" together, line is at {line}");

                //Testing to see if the lines are different and if they are, output it to the output box.
                if (string1.CompareTo(string2) != 0)
                {
                    ForOutputBox.Append($"\nDifferent line {( line++ )}\n\t{File1Name}: {string1}\n\t{File2Name}: {string2}");
                }
                //Removes the strings from the ArrayList and increments the progress done.
                TextList1.Remove(string1);
                TextList2.Remove(string2);
                mainUI.IncrementPercentDone(1, progressBar);
            }

            //Checks to see if either ArrayList is empty, and if not, output their remaining set to the output.
            if (TextList1.Count != 0)
            {
                ForOutputBox.AppendLine($"Extra lines from {File1Name}");
                foreach (string str in TextList1)
                {
                    ForOutputBox.Append($"\n{str}");
                }
            }
            else if (TextList2.Count != 0)
            {
                ForOutputBox.AppendLine($"Extra lines from {File2Name}");
                foreach (string str in TextList2)
                {
                    ForOutputBox.Append($"\n{str}");
                }
            }

            //Changes the text in the output.
            Output.Text = ForOutputBox.ToString();
        }