Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions ModStatistics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp" />
<Reference Include="JsonFx" />
<Reference Include="Assembly-CSharp">
<HintPath>D:\KSPModCopy\KSP_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="JsonFx">
<HintPath>D:\KSPModCopy\GameData\ModStatistics\JsonFx.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine" />
<Reference Include="UnityEngine">
<HintPath>D:\KSPModCopy\KSP_Data\Managed\UnityEngine.dll</HintPath>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These HintPaths would make the solution unbuildable by anyone without the same folder structure to find the references in.

I'd recommend putting a Dependencies folder at the solution root and referencing the assemblies from there, that way a relative path would be used for the HintPath and people can just be told to place the appropriate assemblies there.

An even better solution would be to include JsonFx.dll in the source tree as its license (MIT) allows, probably with its own license next to it to make it clear Majiir's ARR license does not apply to it. UnityEngine.dll may also be included which is allowed here. Unfortunately KSP's own Assembly-CSharp.dll would not be redistributable and have to be likely placed in a .gitignore so no one commits it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm dumb and cannot into github. I mean to commit only the main file and also commited the solution files.

Can I edit a pull request to remove those 2 files?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git checkout ef16415525 ./ModStatistics.csproj
git rm ./ModStatistics.sln
git commit -m "Reverting changes to project and solution"

Would create a commit which effectively backs out those changes, which you can then push and this pull request will be automatically updated.

(ef16415 being the commit that's currently the head of master in Majiir's repo).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still prefer to have the deps in source control (or better yet NuGet), but alas. 😃

</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="ModStatistics.cs" />
Expand Down
18 changes: 18 additions & 0 deletions ModStatistics.sln
Original file line number Diff line number Diff line change
@@ -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