Exemple #1
0
        private static void Init()
        {
            if (config_ != null)
            {
                return;                  // already initialized.
            }
            LogCalled();
            config_ =
                LoadOrderConfig.Deserialize(LocalLoadOrderPath)
                ?? new LoadOrderConfig();

            int n = Math.Max(PlatformService.workshop.GetSubscribedItemCount(), config_.Assets.Length);

            assetsTable_ = new Hashtable(n * 10);
            foreach (var assetInfo in config_.Assets)
            {
                assetsTable_[assetInfo.Path] = assetInfo;
            }

            SaveThread.Init();
        }
Exemple #2
0
 public static void Terminate()
 {
     LogCalled();
     SaveThread.Terminate();
     config_ = null;
 }
Exemple #3
0
        static DataLocation()
        {
            var    sw = System.Diagnostics.Stopwatch.StartNew();
            string m  = "Delayed messages: "; // delayed message;

            try {
                var data = CSCache.Deserialize(LocalLOMData);
                if (data == null)
                {
                    data = new CSCache();
                    // backward compatibility.
                    var data2 = LoadOrderConfig.Deserialize(LocalLOMData);
                    if (data2 != null)
                    {
                        data.WorkShopContentPath = data2.WorkShopContentPath;
                        data.GamePath            = data2.GamePath;
                        data.SteamPath           = data2.SteamPath;
                    }
                }

                sw.Stop();

                try {
                    m += "\ndata is " + (data is null ? "null" : "not null");
                    m += $"\ndata?.GamePath={data?.GamePath ?? "<null>"}";
                    if (Util.IsGamePath(data?.GamePath))
                    {
                        m       += "\ngame path found: " + data.GamePath;
                        GamePath = RealPath(data.GamePath);
                        m       += "\nreal game path is: " + GamePath;
                    }
                    else if (!Util.IsGamePath(GamePath))
                    {
                        m += "\ngetting game path from registry ...";
                        using (RegistryKey key = Registry.LocalMachine.OpenSubKey(installLocationSubKey_)) {
                            GamePath = key?.GetValue(installLocationKey_) as string;
                            GamePath = RealPath(GamePath);
                            m       += "\ngame path from registry: " + GamePath;
                        }
                    }
                    m += "\n[P1] game path so far is:" + GamePath;
                } catch (Exception ex) {
                    Log.Exception(ex);
                }

                try {
                    m += $"\ndata?.SteamPath={data?.SteamPath ?? "<null>"}";
                    if (Util.IsSteamPath(data?.SteamPath))
                    {
                        m        += "\nSteamPath found: " + data.SteamPath;
                        SteamPath = RealPath(data.SteamPath);
                        m        += "\nreal SteamPath is: " + SteamPath;
                    }
                    else if (!Util.IsSteamPath(SteamPath))
                    {
                        m += "\ngetting SteamPath from registry ...";
                        using (RegistryKey key = Registry.CurrentUser.OpenSubKey(SteamPathSubKey_)) {
                            SteamPath = key?.GetValue(SteamPathKey_) as string;
                            SteamPath = RealPath(SteamPath);
                            m        += "\nSteamPath from registry: " + SteamPath;
                        }
                    }
                    m += "\n[P2] SteamPath so far is:" + SteamPath;
                } catch (Exception ex) {
                    Log.Exception(ex);
                }

                m += $"\ndata?.WorkShopContentPath={data?.WorkShopContentPath ?? "<null>"}";
                if (Util.IsWSPath(data?.WorkShopContentPath))
                {
                    WorkshopContentPath = RealPath(data.WorkShopContentPath);
                    m += "\nWorkshopContentPath found: " + WorkshopContentPath;
                }
                m += "\n[P3]WorkshopContentPath so far is: " + WorkshopContentPath;

                CalculatePaths();
                m += "\n[P4] AfterCalucaltePaths";
                m += "\nGamePath=" + (GamePath ?? "<null>");
                m += "\nSteamPath=" + (SteamPath ?? "<null>");
                m += "\nWorkshopContentPath=" + (WorkshopContentPath ?? "<null>");
                bool bGame  = !string.IsNullOrEmpty(GamePath);
                bool bSteam = !string.IsNullOrEmpty(SteamPath);
                if (bGame && bSteam)
                {
                    return;
                }

                m += "\n[P5] Creating select path dialog";
                using (var spd = new LoadOrderTool.UI.SelectPathsDialog()) {
                    if (bGame)
                    {
                        spd.CitiesPath = GamePath;
                    }
                    if (bSteam)
                    {
                        spd.SteamPath = SteamPath;
                    }
                    if (spd.ShowDialog() == DialogResult.OK)
                    {
                        GamePath  = Path.GetDirectoryName(spd.CitiesPath);
                        SteamPath = Path.GetDirectoryName(spd.SteamPath);
                        CalculatePaths();
                        m += "\n[P5] AfterCalucaltePaths";
                        m += "\nGamePath=" + (GamePath ?? "<null>");
                        m += "\nSteamPath=" + (SteamPath ?? "<null>");
                        m += "\nWorkshopContentPath=" + (WorkshopContentPath ?? "<null>");

                        data ??= new CSCache();
                        data.GamePath            = GamePath;
                        data.SteamPath           = SteamPath;
                        data.WorkShopContentPath = WorkshopContentPath;
                        data.Serialize(LocalLOMData);
                    }
                    else
                    {
                        Log.Info(m);
                        Process.GetCurrentProcess().Kill();
                    }
                }

                m += "\n[P6] at the end:";
                m += "\nGamePath=" + (GamePath ?? "<null>");
                m += "\nSteamPath=" + (SteamPath ?? "<null>");
                m += "\nWorkshopContentPath=" + (WorkshopContentPath ?? "<null>");

                if (!Directory.Exists(GamePath))
                {
                    throw new Exception("failed to get GamePath : " + GamePath);
                }
                if (!Directory.Exists(WorkshopContentPath))
                {
                    throw new Exception("failed to get SteamContentPath : " + WorkshopContentPath);
                }
            } catch (Exception ex) {
                Log.Exception(ex);
            } finally {
                Log.Info(m);
                VerifyPaths();
                Log.Debug($"LoadOrderConfig.Deserialize took {sw.ElapsedMilliseconds}ms");
                DataLocation.DisplayStatus();
            }
        }