Navigation Menu

Skip to content

Commit

Permalink
Added ability for user to opt-out of sending telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler Hughes committed Sep 18, 2016
1 parent 49f675d commit 0696def
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 5 deletions.
1 change: 1 addition & 0 deletions LigerShark.Templates/GoogleAnalyticsWizard.cs
Expand Up @@ -73,6 +73,7 @@ private void TrackTemplate(string templateID, string templateName, string templa
// Get the file path where the settings are being stored.
var rootDir = Environment.ExpandEnvironmentVariables(@"%localappdata%\LigerShark\SideWaffle\");
var filePath = Path.Combine(rootDir, "SideWaffle-Settings.json");

bool telemetry = SettingsStore.ReadJsonFile(filePath).SendTelemetry;

if (telemetry)
Expand Down
7 changes: 7 additions & 0 deletions LigerShark.Templates/LigerShark.Templates.csproj
Expand Up @@ -107,7 +107,14 @@
<Reference Include="Microsoft.VisualStudio.TemplateWizardInterface, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
<ItemGroup>
<Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<Compile Include="DynamicBuilder\SettingsStore.cs" />
<Page Include="App.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="DownloadZipWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
2 changes: 1 addition & 1 deletion Project Templates/xUnitTestProject/UnitTestProject.xproj
Expand Up @@ -9,7 +9,7 @@
<ProjectGuid>650a5a85-5956-491e-9312-5e25a27d1108</ProjectGuid>
<RootNamespace>UnitTestProject</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
Expand Down
48 changes: 44 additions & 4 deletions TemplatePack/SettingsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 55 additions & 0 deletions TemplatePack/SettingsForm.cs
Expand Up @@ -3,8 +3,10 @@
using LigerShark.Templates.DynamicBuilder;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows.Forms;
Expand All @@ -20,6 +22,8 @@ public partial class SettingsForm : Form
private bool buildingTemplates = false;
private bool newSourceAdded = false;
private int _numSources;
private string swRootDir;
private string swFilePath;

public SettingsForm()
{
Expand All @@ -43,6 +47,46 @@ public SettingsForm()
onceAWeekRadioBtn.Tag = UpdateFrequency.OnceAWeek;
onceAMonthRadioBtn.Tag = UpdateFrequency.OnceAMonth;
neverRadioBtn.Tag = UpdateFrequency.Never;

// Load the Google Analytics settings from it's JSON source
// telemetryCheckBox
swRootDir = Environment.ExpandEnvironmentVariables(@"%localappdata%\LigerShark\SideWaffle\");
swFilePath = Path.Combine(swRootDir, "SideWaffle-Settings.json");

if (!File.Exists(swFilePath))
{
try
{
var telemetryDefaults = new SettingsStore { SendTelemetry = true };
var json = JsonConvert.SerializeObject(telemetryDefaults, Formatting.Indented);
File.WriteAllText(swFilePath, json);

telemetryCheckBox.Checked = true;
}
catch (IOException ioe)
{
MessageBox.Show(ioe.Message, "Error Trying to Create Default Telemetry JSON File");
}
}
else
{
try
{
var telemetry = SettingsStore.ReadJsonFile(swFilePath).SendTelemetry;

if (telemetry)
{
telemetryCheckBox.Checked = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Trying to Read From Telemetry JSON File");
}

}


}

private void editBtn_click(object sender, EventArgs e)
Expand Down Expand Up @@ -247,6 +291,17 @@ private async void OkBtn_Click(object sender, EventArgs e)
// Here is where the .json file needs to be saved before calling ProcessTemplates
templateBuilder.WriteJsonTemplateSettings(templateSettings);

// Update the JSON file on the Google Analytics setting.
var telemetry = telemetryCheckBox.Checked;
var data = new SettingsStore { SendTelemetry = telemetry };
var json = JsonConvert.SerializeObject(data, Formatting.Indented);
if (!Directory.Exists(swRootDir))
{
Directory.CreateDirectory(swRootDir);
}
File.WriteAllText(swFilePath, json);


// Rebuild all templates before notifying the user
await startRebuildingTemplates();

Expand Down

0 comments on commit 0696def

Please sign in to comment.