Esempio n. 1
0
        public static void InvokeBeforeRun(uint appId, string appName, string userDataPath, bool addDateToLog = false)
        {
            m_appName = appName;

            var logName = new StringBuilder(m_appName);

            if (addDateToLog)
            {
                logName.Append("_");
                logName.Append(new StringBuilder().GetFormatedDateTimeForFilename(DateTime.Now));
            }
            logName.Append(".log");

            var rootPath    = new FileInfo(MyFileSystem.ExePath).Directory.FullName;
            var contentPath = Path.Combine(rootPath, "Content");

            MyFileSystem.Init(contentPath, userDataPath);

            bool isSteamPath     = SteamHelpers.IsSteamPath(rootPath);
            bool manifestPresent = SteamHelpers.IsAppManifestPresent(rootPath, appId);

            MySandboxGame.IsPirated = !isSteamPath && !manifestPresent;

            MySandboxGame.Log.Init(logName.ToString(), MyFinalBuildConstants.APP_VERSION_STRING);
            MySandboxGame.Log.WriteLine("Steam build: Always true");
            MySandboxGame.Log.WriteLine(string.Format("Is official: {0} {1}{2}{3}",
                                                      MyFinalBuildConstants.IS_OFFICIAL,
                                                      (MyObfuscation.Enabled ? "[O]" : "[NO]"),
                                                      (isSteamPath ? "[IS]" : "[NIS]"),
                                                      (manifestPresent ? "[AMP]" : "[NAMP]")));
            MySandboxGame.Log.WriteLine("Environment.ProcessorCount: " + Environment.ProcessorCount);
            MySandboxGame.Log.WriteLine("Environment.OSVersion: " + Environment.OSVersion);
            MySandboxGame.Log.WriteLine("Environment.CommandLine: " + Environment.CommandLine);
            MySandboxGame.Log.WriteLine("Environment.Is64BitProcess: " + Environment.Is64BitProcess);
            MySandboxGame.Log.WriteLine("Environment.Is64BitOperatingSystem: " + Environment.Is64BitOperatingSystem);
            MySandboxGame.Log.WriteLine("Environment.Version: " + Environment.Version);
            MySandboxGame.Log.WriteLine("Environment.CurrentDirectory: " + Environment.CurrentDirectory);
            MySandboxGame.Log.WriteLine("MainAssembly.ProcessorArchitecture: " + Assembly.GetExecutingAssembly().GetArchitecture());
            MySandboxGame.Log.WriteLine("ExecutingAssembly.ProcessorArchitecture: " + MyFileSystem.MainAssembly.GetArchitecture());
            MySandboxGame.Log.WriteLine("IntPtr.Size: " + IntPtr.Size.ToString());
            MySandboxGame.Log.WriteLine("Default Culture: " + CultureInfo.CurrentCulture.Name);
            MySandboxGame.Log.WriteLine("Default UI Culture: " + CultureInfo.CurrentUICulture.Name);
            MySandboxGame.Log.WriteLine("IsAdmin: " + new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator));

            MyLog.Default = MySandboxGame.Log;
            MyTrace.InitWinTrace();

            MyEnumDuplicitiesTester.CheckEnumNotDuplicitiesInRunningApplication(); // About 300 ms

            Debug.WriteLine(string.Format("{0}: Started", m_appName));

            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionHandler);
            Thread.CurrentThread.Name = "Main thread";

            //Because we want exceptions from users to be in english
            Thread.CurrentThread.CurrentCulture   = CultureInfo.InvariantCulture;
            Thread.CurrentThread.CurrentUICulture = CultureInfo.InvariantCulture;

            MySandboxGame.Config = new MyConfig(appName + ".cfg");
            MySandboxGame.Config.Load();
            //MySandboxGame.ConfigDedicated = new MyConfigDedicated("MedievalEngineers-Dedicated.cfg");
        }