From 7bdab0f54c168df9976fc27062c20eb7bbc5df55 Mon Sep 17 00:00:00 2001 From: Ippo343 Date: Sun, 20 Jul 2014 13:51:52 +0200 Subject: [PATCH 1/2] Opt-out option in dialog Adds a radio button to the first time popup asking the user if he wants to enable the statistics collection. I tested it on my install and it seems to work as intended. --- ModStatistics.cs | 49 ++++++++++++++++++++++++++++++-------------- ModStatistics.csproj | 12 ++++++++--- ModStatistics.sln | 18 ++++++++++++++++ 3 files changed, 61 insertions(+), 18 deletions(-) create mode 100644 ModStatistics.sln 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); } diff --git a/ModStatistics.csproj b/ModStatistics.csproj index 2db2d42..ada223f 100644 --- a/ModStatistics.csproj +++ b/ModStatistics.csproj @@ -31,12 +31,18 @@ 4 - - + + D:\KSPModCopy\KSP_Data\Managed\Assembly-CSharp.dll + + + D:\KSPModCopy\GameData\ModStatistics\JsonFx.dll + - + + D:\KSPModCopy\KSP_Data\Managed\UnityEngine.dll + diff --git a/ModStatistics.sln b/ModStatistics.sln new file mode 100644 index 0000000..19b20c7 --- /dev/null +++ b/ModStatistics.sln @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +# SharpDevelop 4.4 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModStatistics", "ModStatistics.csproj", "{67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}.Release|Any CPU.Build.0 = Release|Any CPU + {67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal From 8157f57f02aa2f9ea8fbc96b60fc7747e7bb2301 Mon Sep 17 00:00:00 2001 From: Ippo343 Date: Sun, 20 Jul 2014 16:26:40 +0200 Subject: [PATCH 2/2] Fixing the solution files Reverted the cdproj and delete the sln --- ModStatistics.csproj | 12 +++--------- ModStatistics.sln | 18 ------------------ 2 files changed, 3 insertions(+), 27 deletions(-) delete mode 100644 ModStatistics.sln diff --git a/ModStatistics.csproj b/ModStatistics.csproj index ada223f..2db2d42 100644 --- a/ModStatistics.csproj +++ b/ModStatistics.csproj @@ -31,18 +31,12 @@ 4 - - D:\KSPModCopy\KSP_Data\Managed\Assembly-CSharp.dll - - - D:\KSPModCopy\GameData\ModStatistics\JsonFx.dll - + + - - D:\KSPModCopy\KSP_Data\Managed\UnityEngine.dll - + diff --git a/ModStatistics.sln b/ModStatistics.sln deleted file mode 100644 index 19b20c7..0000000 --- a/ModStatistics.sln +++ /dev/null @@ -1,18 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -# SharpDevelop 4.4 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ModStatistics", "ModStatistics.csproj", "{67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}.Release|Any CPU.Build.0 = Release|Any CPU - {67BCC59A-CC92-4F04-A3B1-55C2BFA9602D}.Release|Any CPU.ActiveCfg = Release|Any CPU - EndGlobalSection -EndGlobal