Example #1
0
        public override void Start()
        {
            // Our own timer with a higher frequency than OverlayPlugin since we want to see
            // the effect of log messages quickly.
            fast_update_timer_          = new System.Timers.Timer();
            fast_update_timer_.Elapsed += (o, args) => {
                int timer_interval = kSlowTimerMilli;
                try {
                    timer_interval = SendFastRateEvents();
                } catch (Exception e) {
                    // SendFastRateEvents holds this semaphore until it exits.
                    LogError("Exception in SendFastRateEvents: " + e.Message);
                    LogError("Stack: " + e.StackTrace);
                    LogError("Source: " + e.Source);
                }
                fast_update_timer_.Interval = timer_interval;
            };
            fast_update_timer_.AutoReset = false;

            FFXIVPlugin plugin_helper = new FFXIVPlugin(this);

            language_ = plugin_helper.GetLocaleString();

            var     versions = new VersionChecker(this);
            Version local    = versions.GetCactbotVersion();

            Version overlay = versions.GetOverlayPluginVersion();
            Version ffxiv   = versions.GetFFXIVPluginVersion();
            Version act     = versions.GetACTVersion();

            // Print out version strings and locations to help users debug.
            LogInfo("cactbot: {0} {1} (dir: {2})", local.ToString(), versions.GetCactbotPluginLocation(), versions.GetCactbotDirectory());
            LogInfo("OverlayPlugin: {0} {1}", overlay.ToString(), versions.GetOverlayPluginLocation());
            LogInfo("FFXIV Plugin: {0} {1}", ffxiv.ToString(), versions.GetFFXIVPluginLocation());
            LogInfo("ACT: {0} {1}", act.ToString(), versions.GetACTLocation());
            if (language_ == null)
            {
                LogInfo("Language: {0}", "(unknown)");
            }
            else
            {
                LogInfo("Language: {0}", language_);
            }

            // Temporarily target cn if plugin is old v2.0.4.0
            if (language_ == "cn" || ffxiv.ToString() == "2.0.4.0")
            {
                ffxiv_ = new FFXIVProcessCn(this);
                LogInfo("Version: cn");
            }
            else if (language_ == "ko")
            {
                ffxiv_ = new FFXIVProcessKo(this);
                LogInfo("Version: ko");
            }
            else
            {
                ffxiv_ = new FFXIVProcessIntl(this);
                LogInfo("Version: intl");
            }
            wipe_detector_ = new WipeDetector(this);
            fate_watcher_  = new FateWatcher(this, language_);

            // Incoming events.
            Advanced_Combat_Tracker.ActGlobals.oFormActMain.OnLogLineRead += OnLogLineRead;

            // Outgoing JS events.
            OnForceReload       += (e) => DispatchToJS(e);
            OnGameExists        += (e) => DispatchToJS(e);
            OnGameActiveChanged += (e) => DispatchToJS(e);
            OnZoneChanged       += (e) => DispatchToJS(e);
            OnLogsChanged       += (e) => DispatchToJS(e);
            OnImportLogsChanged += (e) => DispatchToJS(e);
            OnPlayerChanged     += (e) => DispatchToJS(e);
            OnTargetChanged     += (e) => DispatchToJS(e);
            OnFocusChanged      += (e) => DispatchToJS(e);
            OnInCombatChanged   += (e) => DispatchToJS(e);
            OnPlayerDied        += (e) => DispatchToJS(e);
            OnPartyWipe         += (e) => DispatchToJS(e);
            OnFateEvent         += (e) => DispatchToJS(e);

            fast_update_timer_.Interval = kFastTimerMilli;
            fast_update_timer_.Start();
            fate_watcher_.Start();

            string net_version_str = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(int).Assembly.Location).ProductVersion;

            string[] net_version = net_version_str.Split('.');
            if (int.Parse(net_version[0]) < kRequiredNETVersionMajor || int.Parse(net_version[1]) < kRequiredNETVersionMinor)
            {
                LogError("Requires .NET 4.6 or above. Using " + net_version_str);
            }

            versions.DoUpdateCheck(Config);
        }
        public override void Start()
        {
            // Our own timer with a higher frequency than OverlayPlugin since we want to see
            // the effect of log messages quickly.
            fast_update_timer_          = new System.Timers.Timer();
            fast_update_timer_.Elapsed += (o, args) => {
                int timer_interval = kSlowTimerMilli;
                try {
                    timer_interval = SendFastRateEvents();
                } catch (Exception e) {
                    // SendFastRateEvents holds this semaphore until it exits.
                    LogError(Strings.SendFastRateEventsException, e.Message);
                    LogError(Strings.Stack, e.StackTrace);
                    LogError(Strings.Source, e.Source);
                }
                fast_update_timer_.Interval = timer_interval;
            };
            fast_update_timer_.AutoReset = false;

            FFXIVPlugin plugin_helper = new FFXIVPlugin(this);

            language_  = plugin_helper.GetLocaleString();
            pc_locale_ = System.Globalization.CultureInfo.CurrentUICulture.Name;

            var ui_lang = Config.DisplayLanguage;

            if (ui_lang == "default")
            {
                ui_lang = language_;
            }
            if (ui_lang == "cn")
            {
                ui_lang = "zh";
            }
            try {
                CultureInfo culture = new CultureInfo(ui_lang, false);
                CultureInfo.CurrentUICulture = culture;
            } catch {
                // CultureInfo's constructor throws on nulls.
                // TODO: remove this try/catch and verify a null check is sufficient?
            }

            var     versions = new VersionChecker(this);
            Version local    = versions.GetCactbotVersion();

            Version overlay = versions.GetOverlayPluginVersion();
            Version ffxiv   = versions.GetFFXIVPluginVersion();
            Version act     = versions.GetACTVersion();

            // Print out version strings and locations to help users debug.
            LogInfo(Strings.CactbotBaseInfo, local.ToString(), versions.GetCactbotPluginLocation(), versions.GetCactbotDirectory());
            LogInfo(Strings.OverlayPluginBaseInfo, overlay.ToString(), versions.GetOverlayPluginLocation());
            LogInfo(Strings.FFXIVPluginBaseInfo, ffxiv.ToString(), versions.GetFFXIVPluginLocation());
            LogInfo(Strings.ACTBaseInfo, act.ToString(), versions.GetACTLocation());
            if (language_ == null)
            {
                LogInfo(Strings.ParsingPluginLanguage, "(unknown)");
            }
            else
            {
                LogInfo(Strings.ParsingPluginLanguage, language_);
            }
            if (pc_locale_ == null)
            {
                LogInfo(Strings.SystemLocale, "(unknown)");
            }
            else
            {
                LogInfo(Strings.SystemLocale, pc_locale_);
            }

            // This will be set explicitly, so if it's not set now, it will be set after reloading ACT.
            // Log this for now as there will likely be a lot of questions, re: user directories.
            if (Config.UserConfigFile != null)
            {
                LogInfo(Strings.CactbotUserDirectory, Config.UserConfigFile);
            }

            // Temporarily target cn if plugin is old v2.0.4.0
            if (language_ == "cn" || ffxiv.ToString() == "2.0.4.0")
            {
                ffxiv_ = new FFXIVProcessCn(this);
                LogInfo(Strings.Version, "cn");
            }
            else if (language_ == "ko")
            {
                ffxiv_ = new FFXIVProcessKo(this);
                LogInfo(Strings.Version, "ko");
            }
            else
            {
                ffxiv_ = new FFXIVProcessIntl(this);
                LogInfo(Strings.Version, "intl");
            }
            plugin_helper.RegisterProcessChangedHandler(ffxiv_.OnProcessChanged);
            wipe_detector_ = new WipeDetector(this);
            fate_watcher_  = new FateWatcher(this, language_);

            // Incoming events.
            Advanced_Combat_Tracker.ActGlobals.oFormActMain.OnLogLineRead += OnLogLineRead;

            // Outgoing JS events.
            OnForceReload       += (e) => DispatchToJS(e);
            OnGameExists        += (e) => DispatchToJS(e);
            OnGameActiveChanged += (e) => DispatchToJS(e);
            OnZoneChanged       += (e) => DispatchToJS(e);
            OnLogsChanged       += (e) => DispatchToJS(e);
            OnImportLogsChanged += (e) => DispatchToJS(e);
            OnPlayerChanged     += (e) => DispatchToJS(e);
            OnInCombatChanged   += (e) => DispatchToJS(e);
            OnPlayerDied        += (e) => DispatchToJS(e);
            OnPartyWipe         += (e) => DispatchToJS(e);
            OnFateEvent         += (e) => DispatchToJS(e);
            OnCEEvent           += (e) => DispatchToJS(e);

            fast_update_timer_.Interval = kFastTimerMilli;
            fast_update_timer_.Start();
            fate_watcher_.Start();

            string net_version_str = System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(int).Assembly.Location).ProductVersion;

            string[] net_version = net_version_str.Split('.');
            if (int.Parse(net_version[0]) < kRequiredNETVersionMajor || int.Parse(net_version[1]) < kRequiredNETVersionMinor)
            {
                LogError(Strings.RequireDotNetVersion, net_version_str);
            }

            versions.DoUpdateCheck(Config);
        }