示例#1
0
        public Form1()
        {
            form1 = this;
            InitializeComponent();
            Log.logBox = logBox;
            if (File.Exists("Assembly-CSharp.dll") || File.Exists("UnityEngine.dll") || File.Exists("mysummercar.exe") || File.Exists("mainData") || File.Exists("mono.dll") || File.Exists("CSteamworks.dll")) //check if idiot unpacked this to game folder.
            {
                if (MessageBox.Show("Did you read the instructions? (Readme.txt)", "Question for you!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    MessageBox.Show(string.Format("Why are you lying?{0}Or maybe you can't read?{0}If you could read, you would know what you did wrong.", Environment.NewLine), "You are a liar", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(string.Format("Yes I see.{0}Go back to readme and you will know what you did wrong.", Environment.NewLine), "You are a liar", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                Environment.Exit(0);
            }
            if (File.Exists("MSCFolder.txt"))
            {
                mscPath = File.ReadAllText("MSCFolder.txt");
                if (!Directory.Exists(mscPath))
                {
                    Log.Write(string.Format("Saved MSC Folder, doesn't exists: {0}", mscPath));
                    mscPath = "(unknown)";
                    try
                    {
                        File.Delete("MSCFolder.txt");
                    }
                    catch (Exception e)
                    {
                        Log.Write(e.Message);
                    }
                }
                else
                {
                    Log.Write(string.Format("Loaded saved MSC Folder: {0}", mscPath));
                }
            }
            mscPathLabel.Text = mscPath;
            MDlabel.Text      = mdPath;
            if (Directory.Exists(mdPath))
            {
                Log.Write(string.Format("Found mods folder in: {0}", mdPath));
                MDlabel.ForeColor = Color.Green;
                MDradio.Checked   = true;
                modPath           = mdPath;
            }
            ADlabel.Text = adPath;
            if (Directory.Exists(adPath))
            {
                Log.Write(string.Format("Found mods folder in: {0}", adPath));
                ADlabel.ForeColor = Color.Green;
                ADradio.Checked   = true;
                modPath           = adPath;
            }
            try
            {
                mscLoaderVersion = FileVersionInfo.GetVersionInfo("MSCLoader.dll");
                string currentVersion;
                if (mscLoaderVersion.FileBuildPart != 0)
                {
                    currentVersion = string.Format("{0}.{1}.{2}", mscLoaderVersion.FileMajorPart, mscLoaderVersion.FileMinorPart, mscLoaderVersion.FileBuildPart);
                }
                else
                {
                    currentVersion = string.Format("{0}.{1}", mscLoaderVersion.FileMajorPart, mscLoaderVersion.FileMinorPart);
                }

                string version;
                string res;
                using (WebClient client = new WebClient())
                {
                    client.QueryString.Add("core", "stable");
                    res = client.DownloadString("http://my-summer-car.ml/ver.php");
                }
                string[] result = res.Split('|');
                if (result[0] == "error")
                {
                    switch (result[1])
                    {
                    case "0":
                        throw new Exception("Unknown branch");

                    case "1":
                        throw new Exception("Database connection error");

                    default:
                        throw new Exception("Unknown error");
                    }
                }
                else if (result[0] == "ok")
                {
                    if (result[1].Trim().Length > 8)
                    {
                        throw new Exception("Parse Error, please report that problem!");
                    }
                    version = result[1].Trim();
                }
                else
                {
                    throw new Exception("Unknown server response.");
                }
                int i = currentVersion.CompareTo(version.Trim());
                if (i != 0)
                {
                    Log.Write(string.Format("{2}MCSLoader v{0}, New version available: v{1}", currentVersion, version.Trim(), Environment.NewLine));
                    if (MessageBox.Show(string.Format("New version is available: v{0}, wanna check it out?", version.Trim()), "MCSLoader v" + currentVersion, MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes)
                    {
                        try
                        {
                            if (File.Exists("MSCLoader_Launcher.exe"))
                            {
                                Process.Start("MSCLoader_Launcher.exe");
                            }
                            else
                            {
                                Process.Start("https://github.com/piotrulos/MSCModLoader/releases");
                            }
                            Environment.Exit(0);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(string.Format("Failed to open update info!{1}{1}Error details:{1}{0}", ex.Message, Environment.NewLine), "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    statusBarLabel.Text = string.Format("New version available: v{0}", version.Trim());
                }
                else if (i == 0)
                {
                    Log.Write(string.Format("{1}MCSLoader v{0} is up to date, no new version found.", currentVersion, Environment.NewLine));
                    statusBarLabel.Text = "MSCPatcher Ready!";
                }
            }
            catch (Exception e)
            {
                Log.Write(string.Format("Check for new version failed with error: {0}", e.Message));
                statusBarLabel.Text = "MSCPatcher Ready!";
            }

            if (!Directory.Exists("Debug"))
            {
                groupBox5.Visible      = false;
                basicDebugInfo.Visible = true;
            }
            Log.Write("MSCPatcher ready!", true, true);

            if (mscPath != "(unknown)")
            {
                mscPathLabel.Text = mscPath;
                AssemblyFullPath  = Path.Combine(mscPath, AssemblyPath);
                gfPath            = Path.Combine(mscPath, @"Mods");
                GFlabel.Text      = gfPath;
                if (Directory.Exists(gfPath))
                {
                    Log.Write(string.Format("Found mods folder in: {0}", gfPath));
                    GFlabel.ForeColor = Color.Green;
                    GFradio.Checked   = true;
                    modPath           = gfPath;
                }
                Log.Write(string.Format("Game folder set to: {0}{1}", mscPath, Environment.NewLine));

                MainData.LoadMainData(OutputlogLabel, resDialogLabel, resDialogCheck);

                DebugStatusInfo();
                CheckPatchStatus();
            }
        }