Пример #1
0
        private void Filesearch()
        {
            var matches = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Euro Truck Simulator 2/profiles", "ccpoints.txt", SearchOption.AllDirectories);
            var ccdir   = matches.Take(1);

            foreach (var myscore in ccdir)
            {
                string myresult = myscore.ToString();
                ccpath = myresult;
            }
            if (matches.Length == 0)
            {
                string createpath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "/Euro Truck Simulator 2/profiles";

                string filename = Path.Combine(createpath, "ccpoints.txt");
                if (!File.Exists(filename))
                {
                    File.WriteAllText(filename, Properties.Resources.ccpoints);
                }
                Filesearch();
            }
            else if (matches.Length == 1)
            {
                Loadtext();
            }
            else if (matches.Length > 1)
            {
                string error = "You have more than 1 ccpoints.txt in the profiles folder. \n Remove one from your files folder in the ETS2 folder in Documents!";
                Loghandling.Logerror(error);
                this.Close();
            }
        }
Пример #2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.agreed == false)
            {
                tc tc = new tc();
                tc.ShowDialog();
            }

            Tmppdate.IntegrityCheck();

            Properties.Settings.Default.ccpanelcheck = false;
            Properties.Settings.Default.Save();

            //checks for updater.exe, needed to be a seperate program for performance reasons
            string updaterFile = (new Uri(Assembly.GetEntryAssembly().CodeBase)).AbsolutePath;
            string updaterDir  = Path.GetDirectoryName(updaterFile);
            string fullPath    = Path.Combine(updaterDir, "updater.exe");

            if (!File.Exists(fullPath))
            {
                string error = "Updater.exe not located, re-install program!";
                Loghandling.Logerror(error);
                Errorsound();
            }
            else if (File.Exists(Path.Combine(updaterDir, "updater.exe")) && fullPath != null)
            {
                Process.Start(@"updater.exe");
            }
            else
            {
                string error = "Error reading paths!!";
                Loghandling.Logerror(error);
                Errorsound();
            }
        }
Пример #3
0
        private void Vtn_ccp_edit_Click(object sender, EventArgs e)
        {
            string path = (Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));

            if (path != "")
            {
                ccpath = path + "\\Euro Truck Simulator 2\\profiles";
                Process.Start("explorer.exe", ccpath);
                this.Close();
            }
            if (path == "")
            {
                string error = "Error locating documents folder, try and re-install!";
                Loghandling.Logerror(error);
            }
        }
        public static void Read()
        {
            try
            {
                using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
                    using (var key = hklm.OpenSubKey(@"SOFTWARE\TruckersMP"))
                    {
                        if (key != null)
                        {
                            Properties.Settings.Default.ETS2Location = (string)key.GetValue("InstallLocationETS2");
                            Properties.Settings.Default.launcherpath = (string)key.GetValue("InstallDir");
                            Properties.Settings.Default.Save();

                            if (Properties.Settings.Default.ETS2Location != null && Properties.Settings.Default.launcherpath != null)
                            {
                                GameHandle.Launch();
                            }
                            else if (Properties.Settings.Default.ETS2Location == null)
                            {
                                string error = "Euro Truck Simulator 2 is not installed on this system";
                                Loghandling.Logerror(error);
                                Environment.Exit(1);
                            }
                        }
                        else if (Properties.Settings.Default.launcherpath == null)
                        {
                            DialogResult dialogResult = MessageBox.Show("TruckersMP has not been installed!\n\nPlease run the TruckersMP installer once.\n\nWant to do it now? ", "TruckersMP gamecheck", 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);
                            }
                        }
                    }
            }
            catch (Exception e)
            {
                string error = e.ToString();
                Loghandling.Logerror(error);
            }
        }
Пример #5
0
        //resets the program to default... no checks so there can't be any errors coming back when resetting to defaults
        private void Btn_reset_Click(object sender, EventArgs e)
        {
            cb_tb.Checked        = false;
            cb_etssingle.Checked = false;

            Properties.Settings.Default.tbchk        = false;
            Properties.Settings.Default.singleplayer = false;
            Properties.Settings.Default.agreed       = false;
            Properties.Settings.Default.launcherpath = "";
            Properties.Settings.Default.message      = "";
            Properties.Settings.Default.replacegui   = false;
            Properties.Settings.Default.Save();

            MessageBox.Show("All settings have been set to their Default setting.");

            string error = "Application settings have been restored to default";

            Loghandling.Logerror(error);
        }
Пример #6
0
        private static void Update(List <string> mismatchedFiles)
        {
            try
            {
                System.Threading.ThreadPool.QueueUserWorkItem(async delegate
                {
                    foreach (var file in mismatchedFiles)
                    {
                        string downloadFile = (file.Replace("_backup", "")).Replace("\\", "/");
                        string[] s          = file.Split('\\');
                        string fileName     = s[(s.Length - 1)];

                        if (!Directory.Exists(Properties.Settings.Default.launcherpath))
                        {
                            Directory.CreateDirectory(Properties.Settings.Default.launcherpath);
                        }

                        if (s.Length == 3)
                        {
                            if (!Directory.Exists(Properties.Settings.Default.launcherpath + "\\" + s[1]))
                            {
                                Directory.CreateDirectory(Properties.Settings.Default.launcherpath + "\\" + s[1]);
                            }
                        }

                        if (s.Length == 4)
                        {
                            if (!Directory.Exists(Properties.Settings.Default.launcherpath + "\\" + s[1] + "\\" + s[2]))
                            {
                                Directory.CreateDirectory(Properties.Settings.Default.launcherpath + "\\" + s[1] + "\\" + s[2]);
                            }
                        }

                        if (s.Length == 5)
                        {
                            if (!Directory.Exists(Properties.Settings.Default.launcherpath + "\\" + s[1] + "\\" + s[2] + "\\" + s[3]))
                            {
                                Directory.CreateDirectory(Properties.Settings.Default.launcherpath + "\\" + s[1] + "\\" + s[2] + "\\" + s[3]);
                            }
                        }

                        if (s.Length == 6)
                        {
                            if (!Directory.Exists(Properties.Settings.Default.launcherpath + "\\" + s[1] + "\\" + s[2] + "\\" + s[3] + "\\" + s[4]))
                            {
                                Directory.CreateDirectory(Properties.Settings.Default.launcherpath + "\\" + s[1] + "\\" + s[2] + "\\" + s[3] + "\\" + s[4]);
                            }
                        }

                        using (WebClient downloadClient = new WebClient())
                        {
                            downloadClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(delegate(object sender, DownloadProgressChangedEventArgs e)
                            {
                            });

                            await downloadClient.DownloadFileTaskAsync(new Uri("http://download.ets2mp.com/files" + downloadFile), Properties.Settings.Default.launcherpath + file);
                        }
                    }
                });
            }
            catch (Exception a)
            {
                string error = a.ToString();
                Loghandling.Logerror(error);
            }
        }
        public static bool Launch()
        {
            if (Process.GetProcessesByName("Steam").Length == 0)
            {
                using (var hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64))
                    using (var steamkey = hklm.OpenSubKey(@"SOFTWARE\Valve\Steam"))
                        if (steamkey != null)
                        {
                            string SteamExe = (string)steamkey.GetValue("SteamExe");
                            if (SteamExe != null)
                            {
                                Process.Start(SteamExe);
                                Thread.Sleep(2000); //wait is needed to allow steam to update and connect
                            }
                        }
                        else
                        {
                            DialogResult dialogResult = MessageBox.Show("Steam is not installed!\n\nPlease install Steam to continue!.\n\nWant to do it now? ", "Steam Vailidation", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                            if (dialogResult == DialogResult.Yes)
                            {
                                Process.Start("http://store.steampowered.com/about/");
                                Environment.Exit(1);
                            }
                            else
                            {
                                Environment.Exit(1);
                            }
                        }
            }

            String gamelocation = Properties.Settings.Default.ETS2Location;

            //allows a user who has trucksbook installed, run it before launching the game and connecting to MP
            if (Properties.Settings.Default.tbchk == true)
            {
                if (!File.Exists(Path.Combine(Properties.Settings.Default.tbpath, "TB Client.exe")))
                {
                    string error = "TrucksBook is not installed";
                    Loghandling.Logerror(error);
                    Form1.Errorsound();
                }
                var processes = Process.GetProcessesByName("TB Client");

                if (processes.Length == 0 && File.Exists(Path.Combine(Properties.Settings.Default.tbpath, "TB Client.exe")))
                {
                    Process.Start(Path.Combine(Properties.Settings.Default.tbpath, "TB Client.exe"));
                    Thread.Sleep(1500);     //allows trucksbook to launch without the 'game running' error
                }
            }

            if (Properties.Settings.Default.singleplayer == true)
            {
                Process.Start(gamelocation + "\\bin\\win_x64\\eurotrucks2.exe");
                Environment.Exit(0);
            }

            String binPath;
            String exe;
            String dll;
            String arguments  = "";
            String mplocation = Properties.Settings.Default.launcherpath;

            //Lets get our games straight
            if (Properties.Settings.Default.ETS2Location != null)
            {
                Environment.SetEnvironmentVariable("SteamGameId", "227300");
                Environment.SetEnvironmentVariable("SteamAppID", "227300");

                binPath    = gamelocation + "\\bin\\win_x64";
                exe        = "\\eurotrucks2.exe";
                dll        = "\\core_ets2mp.dll";
                arguments += " -64bit";
            }
            else
            {
                return(false); //Invalid game, lets not do this
            }

            //Intialize variables 'n stuff
            ProcessInformation processInformation  = default(ProcessInformation);
            Startupinfo        startupinfo         = default(Startupinfo);
            SecurityAttributes securityAttributes  = default(SecurityAttributes);
            SecurityAttributes securityAttributes2 = default(SecurityAttributes);

            startupinfo.cb              = Marshal.SizeOf(startupinfo);
            securityAttributes.nLength  = Marshal.SizeOf(securityAttributes);
            securityAttributes2.nLength = Marshal.SizeOf(securityAttributes2);

            //Lets run the game!
            if (!CreateProcess(binPath + exe, arguments, ref securityAttributes, ref securityAttributes2, false, 4u, IntPtr.Zero, binPath, ref startupinfo, out processInformation))
            {
                string error = "Failed to start game";
                Loghandling.Logerror(error);
                return(false);
            }

            if (!Inject(processInformation.hProcess, "C:\\ProgramData\\TruckersMP" + dll))
            {
                string error = "DLL injection failed";
                Loghandling.Logerror(error);
                return(false);
            }

            ResumeThread(processInformation.hThread);
            return(true);
        }