diff --git a/ModStatistics.cs b/ModStatistics.cs index 3c3c604..8e2b92d 100644 --- a/ModStatistics.cs +++ b/ModStatistics.cs @@ -53,16 +53,32 @@ public void Start() if (node == null) { - promptUpdatePref(); + promptPref(); + writeConfig(); } else { var disabledString = node.GetValue("disabled"); - if (disabledString != null && bool.TryParse(disabledString, out disabled) && disabled) + var updateString = node.GetValue("update"); + + // Pop up the dialog if a setting can't be read + if ( (String.IsNullOrEmpty(disabledString) || !bool.TryParse(disabledString, out disabled)) || + (String.IsNullOrEmpty(updateString)) ) + { + promptPref(); + writeConfig(); + } + + + if (disabled) { Debug.Log("[ModStatistics] Disabled in configuration file"); return; } + if (update) + { + checkUpdates(); + } var idString = node.GetValue("id"); try @@ -74,16 +90,6 @@ public void Start() Debug.LogWarning("[ModStatistics] Could not parse ID"); } - var str = node.GetValue("update"); - if (str != null && bool.TryParse(str, out update)) - { - writeConfig(); - checkUpdates(); - } - else - { - promptUpdatePref(); - } } running = true; @@ -98,12 +104,16 @@ public void Start() install(); } - private void promptUpdatePref() + + private void promptPref() { PopupDialog.SpawnPopupDialog( new MultiOptionDialog( "You recently installed a mod which uses ModStatistics to report anonymous usage information. Would you like ModStatistics to automatically update when new versions are available?", - new Callback(() => { update = GUILayout.Toggle(update, "Automatically install ModStatistics updates"); }), + new Callback(() => { + disabled = !GUILayout.Toggle(disabled, "Enable statistics collection"); + update = GUILayout.Toggle(update, "Automatically install ModStatistics updates"); + }), "ModStatistics", HighLogic.Skin, new DialogOption("OK", () => { writeConfig(); checkUpdates(); }, true), @@ -116,7 +126,16 @@ private void promptUpdatePref() private void writeConfig() { - var text = String.Format("// To disable ModStatistics, change the line below to \"disabled = true\"" + Environment.NewLine + "// Do NOT delete the ModStatistics folder. It could be reinstated by another mod." + Environment.NewLine + "disabled = {2}" + Environment.NewLine + "update = {1}" + Environment.NewLine + "id = {0:N}" + Environment.NewLine, id, update.ToString().ToLower(), disabled.ToString().ToLower()); + var text = String.Format("// To disable ModStatistics, change the line below to \"disabled = true\"" + + Environment.NewLine + + "// Do NOT delete the ModStatistics folder. It could be reinstated by another mod." + + Environment.NewLine + "disabled = {2}" + + Environment.NewLine + "update = {1}" + + Environment.NewLine + "id = {0:N}" + + Environment.NewLine, id, + update.ToString().ToLower(), + disabled.ToString().ToLower()); + File.WriteAllText(configpath, text); }