Beispiel #1
0
        private void launchGame(object sender, EventArgs e)
        {
            if (Launcher.working)
            {
                return;
            }

            var game = ((PictureBox)sender).Name;

            if (game.Contains("mp") && !Environment.Is64BitOperatingSystem)
            {
                MessageBox.Show("The TruckersMP Mod does not support 32-Bit operating systems.\nPlease upgrade your system to 64-Bit.", "TruckersMP Launcher - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (game.Contains("mp"))
            {
                System.Threading.ThreadPool.QueueUserWorkItem(delegate
                {
                    TruckersMP.integrityCheck(TruckersMPUpdateProgress, TruckersMPUpdateProgressLabel, true, game);
                });
                return;
            }

            if (game.Equals("play_ets2_btn"))
            {
                Game.runETS2();
            }
            else if (game.Equals("play_ats_btn"))
            {
                Game.runATS();
            }
        }
Beispiel #2
0
        public static void runATSMP()
        {
            if (Process.GetProcessesByName("amtrucks").Length == 0)
            {
                if (Properties.Settings.Default.ATSNoIntro)
                {
                    TruckersMP.launch("ATS", Properties.Settings.Default.ATSLaunchArguments + " -nointro");
                }
                else
                {
                    TruckersMP.launch("ATS", Properties.Settings.Default.ATSLaunchArguments);
                }

                if (Properties.Settings.Default.closeLauncher && !Launcher.TFMRadioPlaying)
                {
                    System.Threading.ThreadPool.QueueUserWorkItem(delegate
                    {
                        System.Threading.Thread.Sleep((int)Properties.Settings.Default.closeDelay * 1000);
                        Application.Exit();
                    });
                }
            }
            else
            {
                MessageBox.Show("American Truck Simulator (Multiplayer) is already running!", "TruckersMP Launcher - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Beispiel #3
0
        public static void initialize(CProgressBar TruckersMPUpdateProgress, Label TruckersMPUpdateProgressLabel)
        {
            if (Properties.Settings.Default.StartSteam)
            {
                if (Process.GetProcessesByName("Steam").Length == 0)
                {
                    Microsoft.Win32.RegistryKey steamKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Valve\\Steam");
                    if (steamKey != null)
                    {
                        string SteamExe = (string)steamKey.GetValue("SteamExe");
                        if (SteamExe != null)
                        {
                            Process.Start(SteamExe);
                        }
                    }
                }
            }

            Launcher.ETS2Installed = false;
            Launcher.ATSInstalled  = false;
            Microsoft.Win32.RegistryKey readKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\TruckersMP");
            if (readKey != null)
            {
                Launcher.TruckersMPLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\TruckersMP";
                Launcher.ETS2Location       = (string)readKey.GetValue("InstallLocationETS2");
                Launcher.ATSLocation        = (string)readKey.GetValue("InstallLocationATS");

                if (System.IO.Directory.Exists(Launcher.ETS2Location))
                {
                    Launcher.ETS2Installed = true;
                }

                if (System.IO.Directory.Exists(Launcher.ATSLocation))
                {
                    Launcher.ATSInstalled = true;
                }

                if (!System.IO.Directory.Exists(Launcher.TruckersMPLocation))
                {
                    DialogResult dialogResult = MessageBox.Show("Unable to locate TruckersMP.\n\nDo you want to install it now?\n(required)", "TruckersMP Launcher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (dialogResult == DialogResult.Yes)
                    {
                        System.Threading.ThreadPool.QueueUserWorkItem(delegate
                        {
                            TruckersMP.install(TruckersMPUpdateProgress, TruckersMPUpdateProgressLabel);
                        });
                    }
                    else
                    {
                        Environment.Exit(1);
                    }
                }
                else
                {
                    if (!(Launcher.ETS2Installed || Launcher.ATSInstalled))
                    {
                        DialogResult dialogResult = MessageBox.Show("There seems to be a problem with your TruckersMP install.\n\nDo you want to reinstall TruckersMP?\n(required)", "TruckersMP Launcher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                        if (dialogResult == DialogResult.Yes)
                        {
                            System.Threading.ThreadPool.QueueUserWorkItem(delegate
                            {
                                TruckersMP.install(TruckersMPUpdateProgress, TruckersMPUpdateProgressLabel, true);
                            });
                        }
                        else
                        {
                            Environment.Exit(1);
                        }
                    }
                    else
                    {
                        System.Threading.ThreadPool.QueueUserWorkItem(delegate
                        {
                            TruckersMP.integrityCheck(TruckersMPUpdateProgress, TruckersMPUpdateProgressLabel);
                        });
                    }
                }
            }
            else
            {
                DialogResult dialogResult = MessageBox.Show("TruckersMP has not been installed!\n\nPlease run the TruckersMP installer once.\n\nWant to do it now? ", "TruckersMP Launcher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    System.Diagnostics.Process.Start("http://truckersmp.com/en_US/download");
                    Environment.Exit(1);
                }
                else
                {
                    Environment.Exit(1);
                }
            }
        }
        public static void integrityCheck(CProgressBar TruckersMPUpdateProgress, Label TruckersMPUpdateProgressLabel, bool runGame = false, String game = "")
        {
            JArray liveFiles = new JArray();
            Dictionary <string, string> localFiles = new Dictionary <string, string>();
            List <string> mismatchedFiles          = new List <string>();

            Launcher.working = true;

            //Get files from TMP

            using (WebClient client = new WebClient())
            {
                try
                {
                    JObject requestData = JObject.Parse(client.DownloadString("http://update.ets2mp.com/files.json"));
                    liveFiles = (JArray)requestData["Files"];
                }
                catch (WebException)
                {
                    Console.WriteLine("Unable to connect to TruckersMP Update API. Cannot check TMP integrity!");
                    if (runGame)
                    {
                        if (game == "ETS2MP" || game.Equals("play_ets2mp_btn"))
                        {
                            Game.runETS2MP();
                        }
                        else if (game == "ATSMP" || game.Equals("play_atsmp_btn"))
                        {
                            Game.runATSMP();
                        }
                    }
                    return;
                }
            }

            int step = 0;

            TruckersMPUpdateProgress.Invoke((MethodInvoker)(() => TruckersMPUpdateProgress.Visible = true));
            TruckersMPUpdateProgressLabel.Invoke((MethodInvoker)(() => TruckersMPUpdateProgressLabel.Visible = true));
            TruckersMPUpdateProgressLabel.Invoke((MethodInvoker)(() => TruckersMPUpdateProgressLabel.Text = "Checking mod integrity..."));

            //Get local files

            try
            {
                var files = System.IO.Directory.GetFiles(Launcher.TruckersMPLocation, "*.*", System.IO.SearchOption.AllDirectories);
                TruckersMPUpdateProgress.Invoke((MethodInvoker)(() => TruckersMPUpdateProgress.Maximum = (files.Length)));
                foreach (var file in files)
                {
                    FileInfo info = new FileInfo(file);

                    string key      = info.FullName;
                    var    checksum = MD5(key);
                    key = key.Replace(Launcher.TruckersMPLocation, "");

                    localFiles.Add(key, checksum);
                    step = step + 1;
                    TruckersMPUpdateProgress.Invoke((MethodInvoker)(() => TruckersMPUpdateProgress.Value = step));
                }
            }
            catch
            {
                Console.WriteLine("Unable to load local files. Cannot check TMP integrity!");
                if (runGame)
                {
                    if (game == "ETS2MP" || game.Equals("play_ets2mp_btn"))
                    {
                        Game.runETS2MP();
                    }
                    else if (game == "ATSMP" || game.Equals("play_atsmp_btn"))
                    {
                        Game.runATSMP();
                    }
                }
                return;
            }

            //Compare results

            try
            {
                foreach (var file in liveFiles)
                {
                    string filePath = ((string)file["FilePath"]).Replace("/", "\\");

                    if (!localFiles.ContainsKey(filePath))
                    {
                        mismatchedFiles.Add(filePath);
                        continue;
                    }

                    string localHash = localFiles[filePath];

                    if (!(filePath.Contains("ui") || filePath.Contains("fonts")))
                    {
                        if ((string)file["Md5"] != localHash)
                        {
                            mismatchedFiles.Add(filePath);
                        }

                        continue;
                    }
                    else
                    {
                        string[] s          = filePath.Split('.');
                        string   backupFile = s[0] + "_backup." + s[1];

                        if (File.Exists(Launcher.TruckersMPLocation + backupFile))
                        {
                            string backupHash = MD5(Launcher.TruckersMPLocation + backupFile);

                            if ((string)file["Md5"] != backupHash)
                            {
                                mismatchedFiles.Add(backupFile);
                            }

                            continue;
                        }
                        else
                        {
                            if ((string)file["Md5"] != localHash)
                            {
                                mismatchedFiles.Add(filePath);
                            }

                            continue;
                        }
                    }
                }
            }
            catch
            {
                Console.WriteLine("An error occured comparing files. Cannot check TMP integrity!");
                if (runGame)
                {
                    if (game == "ETS2MP" || game.Equals("play_ets2mp_btn"))
                    {
                        Game.runETS2MP();
                    }
                    else if (game == "ATSMP" || game.Equals("play_atsmp_btn"))
                    {
                        Game.runATSMP();
                    }
                }
                return;
            }

            if (mismatchedFiles.Count != 0)
            {
                DialogResult dialogResult = MessageBox.Show("Your install of TruckersMP is outdated, has modified files or is missing files.\n\nDo you want to update/redownload them?\n(Required to start multiplayer)", "TruckersMP Launcher", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (dialogResult == DialogResult.Yes)
                {
                    TruckersMP.update(TruckersMPUpdateProgress, TruckersMPUpdateProgressLabel, mismatchedFiles, runGame, game);
                    return;
                }
            }
            else
            {
                if (runGame)
                {
                    if (game == "ETS2MP" || game.Equals("play_ets2mp_btn"))
                    {
                        Game.runETS2MP();
                    }
                    else if (game == "ATSMP" || game.Equals("play_atsmp_btn"))
                    {
                        Game.runATSMP();
                    }
                }
            }

            Launcher.working = false;
            TruckersMPUpdateProgress.Invoke((MethodInvoker)(() => TruckersMPUpdateProgress.Visible = false));
            TruckersMPUpdateProgressLabel.Invoke((MethodInvoker)(() => TruckersMPUpdateProgressLabel.Text = "Integrity check done!"));
            System.Threading.Thread.Sleep(6000);
            if (!Launcher.working)
            {
                TruckersMPUpdateProgressLabel.Invoke((MethodInvoker)(() => TruckersMPUpdateProgressLabel.Visible = false));
            }
        }