Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 34 additions & 15 deletions ModStatistics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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),
Expand All @@ -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);
}

Expand Down