Skip to content

Commit bffb05f

Browse files
refactor: Adopt WPF reading data logic
1 parent 0c0218f commit bffb05f

File tree

5 files changed

+20
-32
lines changed

5 files changed

+20
-32
lines changed

DigitalWellbeingService.NET4.6/ActivityLogger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private void UpdateTimeEntry(Process proc)
6565
// Update Time Entry
6666
for (int i = 0; i < lines.Count; i++)
6767
{
68-
if (lines[i] == string.Empty) continue;
68+
if (lines[i].Trim() == string.Empty) continue;
6969

7070
string[] cells = lines[i].Split('\t');
7171

DigitalWellbeingWPF/Helpers/StringParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static string TimeSpanToString(TimeSpan duration)
1919
}
2020

2121
private static readonly TextInfo txtInfo = new CultureInfo("en-US", false).TextInfo;
22-
public static string FormatProcessName(string processName)
22+
public static string TitleCaseWhenLower(string processName)
2323
{
2424
return processName.Any(char.IsUpper) ? processName : txtInfo.ToTitleCase(processName);
2525
}

DigitalWellbeingWPF/Models/AppUsage.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using DigitalWellbeingWPF.Helpers;
2+
using System;
23
using System.Collections.Generic;
34
using System.ComponentModel;
45
using System.Linq;
@@ -17,7 +18,7 @@ public class AppUsage : INotifyPropertyChanged
1718
public AppUsage(string processName, string programName, TimeSpan duration)
1819
{
1920
this.ProcessName = processName;
20-
this.ProgramName = programName;
21+
this.ProgramName = programName != string.Empty ? programName : StringParser.TitleCaseWhenLower(processName);
2122
this.Duration = duration;
2223
}
2324

DigitalWellbeingWPF/ViewModels/AppUsageViewModel.cs

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -501,41 +501,28 @@ public static async Task<List<AppUsage>> GetData(DateTime date)
501501
{
502502
try
503503
{
504-
if (i + 1 >= lines.Length) break;
504+
// Skip empty rows
505+
if (lines[i].Trim() == string.Empty) continue;
505506

506-
string line = lines[i];
507+
string[] cells = lines[i].Split('\t');
507508

508-
if (line == "") continue;
509+
string processName = cells[0];
510+
int seconds = 0;
511+
string programName = cells.Length > 2 ? cells[2] : "";
509512

510-
string[] data = line.Split('\t');
513+
// Try get seconds
514+
int.TryParse(cells[1], out seconds);
511515

512-
string processName = data[1];
513-
string programName = data[2] != "" ? data[2] : StringParser.FormatProcessName(processName);
514-
515-
DateTime startTime = DateTime.Parse(data[0]);
516-
DateTime endTime = DateTime.Parse(lines[i + 1].Split('\t')[0]);
517-
518-
if (endTime < startTime) continue; // Prevents negative values
519-
520-
TimeSpan duration = endTime - startTime;
521-
522-
AppUsage existingRecord = appUsageList.Find(a => a.ProcessName == processName);
523-
if (existingRecord == null)
524-
{
525-
appUsageList.Add(new AppUsage(processName, programName, duration));
526-
}
527-
else
528-
{
529-
existingRecord.Duration = existingRecord.Duration.Add(duration);
530-
}
516+
appUsageList.Add(
517+
new AppUsage(processName, programName, TimeSpan.FromSeconds(seconds))
518+
);
531519
}
532-
catch (FormatException ex)
520+
catch (Exception ex)
533521
{
534-
Console.WriteLine("Data parsing error. SKIP ROW... " + ex.Message);
522+
Console.WriteLine("SKIP READING ROW: " + ex);
535523
}
536524
}
537525

538-
539526
return appUsageList;
540527
}
541528
catch (FileNotFoundException)

Setup/Setup.aip

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929
<ROW Property="ARPCOMMENTS" Value="This installer database contains the logic and data required to install [|ProductName]." ValueLocId="*"/>
3030
<ROW Property="ARPPRODUCTICON" Value="applogo.exe" Type="8"/>
3131
<ROW Property="Manufacturer" Value="ckcdev"/>
32-
<ROW Property="ProductCode" Value="1033:{06568B67-9BC9-4FEA-8591-886302A4CD4E} " Type="16"/>
32+
<ROW Property="ProductCode" Value="1033:{678B77C9-1047-4FA0-962C-D56D4F9F594B} " Type="16"/>
3333
<ROW Property="ProductLanguage" Value="1033"/>
3434
<ROW Property="ProductName" Value="Digital Wellbeing For Windows"/>
35-
<ROW Property="ProductVersion" Value="1.0.5.3" Type="32" TargetFile="DigitalWellbeingWPF.exe"/>
35+
<ROW Property="ProductVersion" Value="2.0.0.0" Type="32" TargetFile="DigitalWellbeingWPF.exe"/>
3636
<ROW Property="REBOOT" MultiBuildValue="DefaultBuild:Force"/>
3737
<ROW Property="SecureCustomProperties" Value="OLDPRODUCTS;AI_NEWERPRODUCTFOUND"/>
3838
<ROW Property="UpgradeCode" Value="{D7DA3A0D-99E1-4FAC-B2CC-FEBB27BCA59A}"/>

0 commit comments

Comments
 (0)