Skip to content

Commit 5809418

Browse files
committed
update
1 parent 0b22db4 commit 5809418

5 files changed

Lines changed: 35 additions & 32 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,3 +231,4 @@ $RECYCLE.BIN/
231231
*.lnk
232232
/.vs/CodeStats/v15/Server/sqlite3
233233
/.vs/CodeStats/v16/Server/sqlite3
234+
/.vs/slnx.sqlite

CodeStats/CodeStats.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@
115115
</Compile>
116116
<Compile Include="PluginInfrastructure\UnmanagedExports.cs" />
117117
<Compile Include="RunProcess.cs" />
118-
<Compile Include="Updater.cs" />
119118
</ItemGroup>
120119
<ItemGroup>
121120
<EmbeddedResource Include="Forms\ApiKeyForm.resx">
122121
<DependentUpon>ApiKeyForm.cs</DependentUpon>
122+
<SubType>Designer</SubType>
123123
</EmbeddedResource>
124124
<EmbeddedResource Include="Forms\SettingsForm.resx">
125125
<DependentUpon>SettingsForm.cs</DependentUpon>

CodeStats/CodeStatsPackage.cs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,6 @@ private static void InitializeAsync()
9595
}
9696
//System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType)0; // SystemDefault, we don't use this since it's supported only since .NET 4.7
9797

98-
//Updater.RenameTest();
99-
//Updater.SignatureVerificationTest();
10098
try
10199
{
102100
// Delete existing log file to save space
@@ -130,9 +128,10 @@ private static void InitializeAsync()
130128
try
131129
{
132130
string latest = Constants.LatestPluginVersion();
131+
Logger.Debug("Latest version of the plugin online is: " + latest);
133132
if (Constants.PluginVersion != latest && !String.IsNullOrWhiteSpace(latest))
134133
{
135-
MessageBox.Show("There is Code::Stats plugin update available!\nDownload it from Plugin Admin (if already available there) or GitHub.\nYour version: " + Constants.PluginVersion + "\nLatest: " + latest, "Code::Stats");
134+
MessageBox.Show("There is Code::Stats plugin update available!\nDownload it from Plugins Admin (if already available there) or GitHub.\nYour version: " + Constants.PluginVersion + "\nLatest: " + latest, "Code::Stats");
136135
}
137136
}
138137
catch { }
@@ -172,7 +171,6 @@ private static void LoadExtensionMapping()
172171
{
173172
try
174173
{
175-
//MessageBox.Show("test1");
176174
//Logger.Debug(Assembly.GetExecutingAssembly().GetManifestResourceNames().ToString());
177175
//Logger.Debug(Assembly.GetExecutingAssembly().GetName().Name);
178176

@@ -190,7 +188,6 @@ private static void LoadExtensionMapping()
190188
extensionMapping = serializer.Deserialize<Dictionary<string, string>>(extensionMappingJson);
191189

192190
Logger.Debug("Loaded local precompiled extension mapping");
193-
//MessageBox.Show("test2");
194191

195192
// fetch up-to-date mappings from network asynchronously
196193
Task.Run(() =>
@@ -205,8 +202,8 @@ private static void LoadExtensionMapping()
205202

206203
try
207204
{
208-
extensionMappingJsonNew = client.DownloadString("https://raw.githubusercontent.com/p0358/notepadpp-CodeStats/master/CodeStats/Resources/extension_mapping.json");
209-
if (!extensionMappingJsonNew.Trim().StartsWith("{") || !extensionMappingJson.Trim().EndsWith("}"))
205+
extensionMappingJsonNew = client.DownloadString("https://raw.githubusercontent.com/p0358/notepadpp-CodeStats/master/CodeStats/Resources/extension_mapping.json").Trim();
206+
if (!extensionMappingJsonNew.StartsWith("{") || !extensionMappingJson.EndsWith("}"))
210207
{
211208
extensionMappingJsonNew = string.Empty;
212209
Logger.Error("Invalid response when trying to download latest extension mappings, using local ones instead");
@@ -223,7 +220,6 @@ private static void LoadExtensionMapping()
223220
extensionMappingJson = string.Empty;
224221
} // get webclient, set proxy, update extension mapping JSON
225222

226-
//MessageBox.Show("test3");
227223
if (!String.IsNullOrWhiteSpace(extensionMappingJsonNew) && extensionMappingJsonNew != extensionMappingJson)
228224
{
229225
extensionMapping = serializer2.Deserialize<Dictionary<string, string>>(extensionMappingJson);
@@ -266,8 +262,7 @@ internal static void SetStatusBarDocType(string str)
266262

267263
//IntPtr pStr = Marshal.AllocHGlobal(Marshal.SizeOf(str));
268264
//Marshal.StructureToPtr(str, pStr, false);
269-
string strr = @"" + str;
270-
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SETSTATUSBAR, /*(IntPtr)NppMsg.STATUSBAR_DOC_TYPE*/0, strr);
265+
Win32.SendMessage(PluginBase.nppData._nppHandle, (uint)NppMsg.NPPM_SETSTATUSBAR, (IntPtr)NppMsg.STATUSBAR_DOC_TYPE, str);
271266
//Marshal.FreeHGlobal(pStr);
272267
}
273268

@@ -425,7 +420,7 @@ private static Task ProcessPulses(CancellationTokenSource tokenSource)
425420

426421
if (String.IsNullOrWhiteSpace(ApiKey))
427422
{
428-
Logger.Debug("No API token - cannot pulse!");
423+
Logger.Warning("No API token - cannot pulse!");
429424
return;
430425
}
431426

@@ -483,11 +478,15 @@ private static Task ProcessPulses(CancellationTokenSource tokenSource)
483478
response.EnsureSuccessStatusCode();
484479
string JsonResult = await response.Content.ReadAsStringAsync();
485480
_lastPulse = DateTime.Now;
486-
if (!JsonResult.Contains(@"""ok""") && !JsonResult.Contains(@"success"))
481+
if (!JsonResult.Contains(@"""ok""") || !JsonResult.Contains(@"success"))
487482
{
488483
error = true;
489484
Logger.Error(@"Error pulsing, response does not contain ""ok"" or ""success"": " + JsonResult);
490485
}
486+
else
487+
{
488+
Logger.Debug("Pulsed, response: " + JsonResult);
489+
}
491490
}
492491
catch (TaskCanceledException)
493492
{
@@ -544,8 +543,7 @@ private static Task ProcessPulses(CancellationTokenSource tokenSource)
544543

545544
}
546545

547-
if (tokenSource.Token.IsCancellationRequested)
548-
tokenSource.Token.ThrowIfCancellationRequested();
546+
tokenSource.Token.ThrowIfCancellationRequested();
549547
}
550548
}
551549
}, tokenSource.Token);
@@ -704,7 +702,7 @@ public static string GetCurrentLanguage() // Code::Stats
704702

705703
public static bool EnoughTimePassed(DateTime now)
706704
{
707-
return (_lastActivity < now.AddMilliseconds(-1 * pulseFrequency)) && (_lastPulse < now.AddMilliseconds(-1 * pulseFrequency));
705+
return _lastActivity < now.AddMilliseconds(-1 * pulseFrequency) && _lastPulse < now.AddMilliseconds(-1 * pulseFrequency);
708706
}
709707

710708
private static void SettingsFormOnConfigSaved(object sender, EventArgs eventArgs)
@@ -742,18 +740,21 @@ private static void SettingsPopup()
742740

743741
public static void ReportStats()
744742
{
745-
try
743+
Task.Run(() =>
746744
{
747-
var client = new WebClient { Proxy = CodeStatsPackage.GetProxy() };
748-
client.Headers[HttpRequestHeader.UserAgent] = Constants.PluginUserAgent;
749-
string HtmlResult = client.DownloadString("https://p0358.net/codestats/report.php?pluginver=" + Constants.PluginVersion
750-
+ "&cid=" + CodeStatsPackage.Guid + "&editorname=" + Constants.EditorName + "&editorver=" + Constants.EditorVersion
751-
+ "&is64process=" + ProcessorArchitectureHelper.Is64BitProcess.ToString().ToLowerInvariant() + "&is64sys=" + ProcessorArchitectureHelper.Is64BitOperatingSystem.ToString().ToLowerInvariant()
752-
+ "&osverstr" + Constants.OSVersionString + "&osbuild" + Constants.OSVersionBuild
753-
); // expected response: ok
754-
if (HtmlResult.Contains("ok")) _reportedStats = true;
755-
}
756-
finally { }
745+
try
746+
{
747+
var client = new WebClient { Proxy = CodeStatsPackage.GetProxy() };
748+
client.Headers[HttpRequestHeader.UserAgent] = Constants.PluginUserAgent;
749+
string result = client.DownloadString("https://p0358.net/codestats/report.php?pluginver=" + Constants.PluginVersion
750+
+ "&cid=" + CodeStatsPackage.Guid + "&editorname=" + Constants.EditorName + "&editorver=" + Constants.EditorVersion
751+
+ "&is64process=" + ProcessorArchitectureHelper.Is64BitProcess.ToString().ToLowerInvariant() + "&is64sys=" + ProcessorArchitectureHelper.Is64BitOperatingSystem.ToString().ToLowerInvariant()
752+
+ "&osverstr=" + Constants.OSVersionString + "&osbuild=" + Constants.OSVersionBuild
753+
); // expected response: ok
754+
if (result.Contains("ok")) _reportedStats = true;
755+
}
756+
finally { }
757+
});
757758
}
758759

759760
private static string ToUnixEpoch(DateTime date)

CodeStats/Resources/extension_mapping.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"perl": "Perl",
5454
"perl6": "Perl 6",
5555
"php": "PHP",
56+
"phtml": "PHP",
5657
"powershell": "PowerShell",
5758
"qsharp": "Q#",
5859
"jade": "Pug",

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ Code::Stats - Write code, level up, show off! A free stats tracking service for
99
Installation
1010
------------
1111

12-
1. Inside Notepad++ open the Plugin Manager (`Plugins``Plugin Manager``Show Plugin Manager`).
12+
1. Inside Notepad++ open the Plugins Admin (`Plugins``Plugins Admin...`).
1313

1414
2. Check the box next to `Code::Stats` in the list of plugins.
1515

1616
3. Click the `Install` button.
1717

18-
4. Restart Notepad++.
18+
4. Confirm the restart of Notepad++.
1919

20-
3. Enter your [API token](https://codestats.net/my/machines), then press `enter`.
20+
3. Enter your [API token](https://codestats.net/my/machines) in the window that pops up, then press `OK`.
2121

2222
4. Use Notepad++ like you normally do and your amount of programming will be tracked for you automatically.
2323

@@ -27,11 +27,11 @@ OR
2727

2828
1. Go to [releases](https://github.com/p0358/notepadpp-CodeStats/releases) and download zip file for correct architecture.
2929

30-
2. Put it in Notepad++ plugin dir, for example (for x86): `C:\Program Files (x86)\Notepad++\plugins`.
30+
2. Put it in Notepad++ plugin dir, for example (for x86): `C:\Program Files (x86)\Notepad++\plugins`, or (for x64): `C:\Program Files\Notepad++\plugins`.
3131

3232
3. Start/restart Notepad++.
3333

34-
4. Enter your [API token](https://codestats.net/my/machines), then press `enter`.
34+
4. Enter your [API token](https://codestats.net/my/machines) in the window that pops up, then press `OK`.
3535

3636
5. Use Notepad++ like you normally do and your amount of programming will be tracked for you automatically.
3737

0 commit comments

Comments
 (0)