CopyFile() public static method

public static CopyFile ( string from, string to ) : bool
from string
to string
return bool
Exemplo n.º 1
0
        public bool Setup()
        {
            _logWriter.WriteLine("-------------- Session at: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "\n");

            /** SEED PARSING AND RNG SETUP **/
            _friskMode = false;
            byte power = 0;

            _random = new Random();
            int timeSeed = (int)DateTime.Now.Subtract(_unixTimeZero).TotalSeconds;

            if (!byte.TryParse(txtPower.Text, out power) && _corrupt)
            {
                MessageBox.Show("Please set Power to a number between 0 and 255 and try again.");
                return(false);
            }
            _truePower = (float)power / 255;

            if (txtSeed.Text.ToUpper() == "FRISK" && !File.Exists("DELTARUNE.exe"))
            {
                _friskMode = true;
            }

            if (_showSeed)
            {
                txtSeed.Text = $"#{timeSeed}";
            }
            else
            {
                txtSeed.Text = "";
            }

            _logWriter.WriteLine($"Time seed - {timeSeed}");
            _logWriter.WriteLine($"Power - {power}");
            _logWriter.WriteLine($"TruePower - {_truePower}");

            /** ENVIRONMENTAL CHECKS **/
            if (File.Exists("UNDERTALE.exe") && !File.Exists("./mus_barrier.ogg"))
            {
                MessageBox.Show("ERROR:\nIt seems you've either placed HATE.exe in the wrong location or are using an old version of Undertale. Solutions to both problems are given in the README.txt file included in the download.");
                return(false);
            }

            if (!File.Exists(_dataWin))
            {
                MessageBox.Show($"You seem to be missing your resource file, {_dataWin}. Make sure you've placed HATE.exe in the proper location.");
                return(false);
            }
            else if (!Directory.Exists("Data"))
            {
                if (!Safe.CreateDirectory("Data"))
                {
                    return(false);
                }
                if (!Safe.CopyFile(_dataWin, $"Data/{_dataWin}"))
                {
                    return(false);
                }
                if (Directory.Exists("./lang"))
                {
                    if (!Safe.CopyFile("./lang/lang_en.json", "./Data/lang_en.json"))
                    {
                        return(false);
                    }
                    ;
                    if (!Safe.CopyFile("./lang/lang_ja.json", "./Data/lang_ja.json"))
                    {
                        return(false);
                    }
                    ;
                }
                _logWriter.WriteLine($"Finished setting up the Data folder.");
            }

            if (!Safe.DeleteFile(_dataWin))
            {
                return(false);
            }
            _logWriter.WriteLine($"Deleted {_dataWin}.");
            if (Directory.Exists("./lang"))
            {
                if (!Safe.DeleteFile("./lang/lang_en.json"))
                {
                    return(false);
                }
                _logWriter.WriteLine($"Deleted ./lang/lang_en.json.");
                if (!Safe.DeleteFile("./lang/lang_ja.json"))
                {
                    return(false);
                }
                _logWriter.WriteLine($"Deleted ./lang/lang_ja.json.");
            }

            if (!Safe.CopyFile($"Data/{_dataWin}", _dataWin))
            {
                return(false);
            }
            _logWriter.WriteLine($"Copied {_dataWin}.");
            if (Directory.Exists("./lang"))
            {
                if (!Safe.CopyFile("./Data/lang_en.json", "./lang/lang_en.json"))
                {
                    return(false);
                }
                _logWriter.WriteLine($"Copied ./lang/lang_en.json.");
                if (!Safe.CopyFile("./Data/lang_ja.json", "./lang/lang_ja.json"))
                {
                    return(false);
                }
                _logWriter.WriteLine($"Copied ./lang/lang_ja.json.");
            }

            return(true);
        }
Exemplo n.º 2
0
        private bool Setup()
        {
            _logWriter.WriteLine("-------------- Session at: " + DateTime.Now.ToLongDateString() + " " +
                                 DateTime.Now.ToLongTimeString() + "\n");

            /** SEED PARSING AND RNG SETUP **/
            Main.FriskMode = false;
            _random        = new Random();
            int timeSeed = (int)DateTime.Now.Subtract(_unixTimeZero).TotalSeconds;

            if (!byte.TryParse(txtPower.Text, out byte power) && string.IsNullOrEmpty(txtPower.Text) && _corrupt)
            {
                Logger.Log(MessageType.Warning, "Please set Power to a number between 0 and 255 and try again.", true);
                return(false);
            }

            _truePower = (float)power / 255;

            if (!string.IsNullOrWhiteSpace(txtSeed.Text) && txtSeed.Text.ToUpper() == "FRISK" &&
                (!File.Exists("DELTARUNE.exe") ||
                 !Directory.Exists("SURVEY_PROGRAM.app")))
            {
                Main.FriskMode = true;
            }

            txtSeed.Text = _showSeed ? $"#{timeSeed}" : "";

            _logWriter.WriteLine($"Time seed - {timeSeed}");
            _logWriter.WriteLine($"Power - {power}");
            _logWriter.WriteLine($"TruePower - {_truePower}");

            /** ENVIRONMENTAL CHECKS **/
            if (File.Exists("UNDERTALE.exe") || Directory.Exists("UNDERTALE.app") &&
                !File.Exists(Main.GetFileLocation("mus_barrier.ogg")))
            {
                Logger.Log(MessageType.Error,
                           "ERROR:\nIt seems you've either placed HATE.exe in the wrong location or are using an old version of Undertale. Solutions to both problems are given in the README.txt file included in the download.");
                return(false);
            }

            if (!File.Exists(Main.GetFileLocation(Main.DataFile)))
            {
                Logger.Log(MessageType.Error,
                           $"You seem to be missing your resource file ({Main.DataFile}). Make sure you've placed HATE.exe in the proper location.");
                return(false);
            }
            else if (!Directory.Exists("Data"))
            {
                if (!Safe.CreateDirectory("Data"))
                {
                    return(false);
                }

                if (!Safe.CopyFile(Main.GetFileLocation(Main.DataFile),
                                   Path.Combine(Directory.GetCurrentDirectory(), "Data", Main.DataFile)))
                {
                    return(false);
                }

                if (labGameName.Text == "Deltarune")
                {
                    if (!Safe.CreateDirectory(Path.Combine("Data", "lang")))
                    {
                        return(false);
                    }

                    if (!Safe.CopyFile(Main.GetFileLocation(Path.Combine("lang", "lang_en.json")),
                                       Path.Combine(Directory.GetCurrentDirectory(), "Data", "lang", "lang_en.json")))
                    {
                        return(false);
                    }

                    if (!Safe.CopyFile(Main.GetFileLocation(Path.Combine("lang", "lang_ja.json")),
                                       Path.Combine(Directory.GetCurrentDirectory(), "Data", "lang", "lang_ja.json")))
                    {
                        return(false);
                    }
                }

                _logWriter.WriteLine($"Finished setting up the Data folder.");
            }

            if (!Safe.DeleteFile(Main.GetFileLocation(Main.DataFile)))
            {
                return(false);
            }

            _logWriter.WriteLine($"Deleted {Main.DataFile}.");
            if (labGameName.Text == "Deltarune")
            {
                if (!Safe.DeleteFile(Main.GetFileLocation(Path.Combine("lang", "lang_en.json"))))
                {
                    return(false);
                }

                _logWriter.WriteLine($"Deleted ./lang/lang_en.json.");
                if (!Safe.DeleteFile(Main.GetFileLocation(Path.Combine("lang", "lang_ja.json"))))
                {
                    return(false);
                }

                _logWriter.WriteLine($"Deleted ./lang/lang_ja.json.");
            }

            if (!Safe.CopyFile(Path.Combine(Directory.GetCurrentDirectory(), "Data", Main.DataFile),
                               Main.GetFileLocation(Main.DataFile)))
            {
                return(false);
            }

            _logWriter.WriteLine($"Copied {Main.DataFile}.");
            if (labGameName.Text == "Deltarune")
            {
                if (!Safe.CopyFile(Path.Combine(Directory.GetCurrentDirectory(), "Data", "lang", "lang_en.json"),
                                   Main.GetFileLocation(Path.Combine("lang", "lang_en.json"))))
                {
                    return(false);
                }

                _logWriter.WriteLine($"Copied ./lang/lang_en.json.");
                if (!Safe.CopyFile(Path.Combine(Directory.GetCurrentDirectory(), "Data", "lang", "lang_ja.json"),
                                   Main.GetFileLocation(Path.Combine("lang", "lang_ja.json"))))
                {
                    return(false);
                }

                _logWriter.WriteLine($"Copied ./lang/lang_ja.json.");
            }

            return(true);
        }
Exemplo n.º 3
0
        public bool Setup()
        {
            _logWriter.WriteLine("-------------- Session at: " + DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString() + "\n");

            /** SEED PARSING AND RNG SETUP **/
            _friskMode = false;
            byte power = 0;

            if (!byte.TryParse(txtPower.Text, out power))
            {
                MessageBox.Show("Please set Power to a number between 0 and 255 and try again.");
                return(false);
            }

            _truePower = (float)power / 255;

            int    timeSeed = 0;
            string seed     = txtSeed.Text.Trim();
            bool   textSeed = false;

            if (seed == "")
            {
                timeSeed = (int)DateTime.Now.Subtract(_unixTimeZero).TotalSeconds;

                if (_showSeed)
                {
                    txtSeed.Text = $"#{timeSeed}";
                }
            }
            else if (txtSeed.Text[0] == '#' && int.TryParse(txtSeed.Text.Substring(1), out int tmpSeed))
            {
                timeSeed = tmpSeed;
                _logWriter.WriteLine("# seed - " + tmpSeed);
            }
            else if (txtSeed.Text.ToUpper() == "FRISK")
            {
                _friskMode = true;
            }
            else
            {
                _logWriter.WriteLine("Text seed - " + txtSeed.Text.GetHashCode());
                _random  = new Random(txtSeed.Text.GetHashCode());
                textSeed = true;
            }

            if (!textSeed)
            {
                _random = new Random(timeSeed);
                _logWriter.WriteLine("Time seed - " + timeSeed);
                _logWriter.WriteLine("Power - " + power);
                _logWriter.WriteLine("TruePower - " + _truePower);
            }

            /** ENVIRONMENTAL CHECKS **/

            if (!File.Exists("./mus_barrier.ogg"))
            {
                MessageBox.Show("ERROR:\nIt seems you've either placed HATE.exe in the wrong location or are using an old version of the game. Solutions to both problems are given in the README.txt file included in the download.");
                return(false);
            }

            if (!File.Exists("./" + _dataWin))
            {
                MessageBox.Show($"You seem to be missing your resource file, {_dataWin}. Make sure you've placed HATE.exe in the proper location.");
                return(false);
            }

            else if (!Directory.Exists("./Data"))
            {
                if (!Safe.CreateDirectory("./Data"))
                {
                    return(false);
                }
                if (!Safe.CopyFile("./" + _dataWin, "./Data/" + _dataWin))
                {
                    return(false);
                }
            }

            if (!Safe.DeleteFile("./" + _dataWin))
            {
                return(false);
            }
            _logWriter.WriteLine("Deleted " + _dataWin + ".");
            if (!Safe.CopyFile("./Data/" + _dataWin, "./" + _dataWin))
            {
                return(false);
            }
            _logWriter.WriteLine("Copied " + _dataWin + ".");
            return(true);
        }