-
-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
794 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.IO; | ||
using System.Drawing; | ||
using System.ComponentModel; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
|
||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace CKAN | ||
{ | ||
[JsonObject(MemberSerialization.OptIn)] | ||
public class TimeLog | ||
{ | ||
[JsonProperty("time", NullValueHandling = NullValueHandling.Ignore)] | ||
public TimeSpan Time; | ||
|
||
public static string GetPath(string dir) | ||
{ | ||
return Path.Combine(dir, filename); | ||
} | ||
|
||
public static TimeLog Load(string path) | ||
{ | ||
try | ||
{ | ||
return JsonConvert.DeserializeObject<TimeLog>(File.ReadAllText(path)); | ||
} | ||
catch (FileNotFoundException) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public void Save(string path) | ||
{ | ||
File.WriteAllText(path, JsonConvert.SerializeObject(this, Formatting.Indented)); | ||
} | ||
|
||
public override String ToString() | ||
{ | ||
return Time.TotalHours.ToString("N1"); | ||
} | ||
|
||
private Stopwatch playTime = new Stopwatch(); | ||
|
||
public void Start() | ||
{ | ||
playTime.Restart(); | ||
} | ||
|
||
public void Stop(string dir) | ||
{ | ||
if (playTime.IsRunning) | ||
{ | ||
playTime.Stop(); | ||
Time += playTime.Elapsed; | ||
Save(GetPath(dir)); | ||
} | ||
} | ||
|
||
private const string filename = "playtime.json"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.