Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit b548733

Browse files
First attempt to get windows disk usage
1 parent 4e7bcac commit b548733

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,38 @@ private void CaptureRepoSize()
297297
}
298298
})
299299
.Start();
300+
301+
var gitLfsDataPath = Environment.RepositoryPath.Combine(".git", "lfs");
302+
if (gitLfsDataPath.Exists())
303+
{
304+
if (Environment.IsWindows)
305+
{
306+
new WindowsDiskUsageTask(gitLfsDataPath, TaskManager.Token).Configure(ProcessManager).Then(
307+
(b, list) => {
308+
if (b)
309+
{
310+
try
311+
{
312+
var output = list[list.Count - 2];
313+
var proc = new LineParser(output);
314+
proc.SkipWhitespace();
315+
proc.ReadUntilWhitespace();
316+
proc.ReadUntilWhitespace();
317+
proc.SkipWhitespace();
318+
319+
var sizeInBytes = int.Parse(proc.ReadUntilWhitespace().Replace(",", string.Empty));
320+
var sizeInKilobytes = sizeInBytes / 1024;
321+
322+
UsageTracker.UpdateLfsDiskUsage(sizeInKilobytes);
323+
}
324+
catch (Exception e)
325+
{
326+
Logger.Error(e, "Error Calculating LFS Disk Usage");
327+
}
328+
}
329+
}).Start();
330+
}
331+
}
300332
}
301333

302334
public void RestartRepository()

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
<Compile Include="Git\IGitObjectFactory.cs" />
136136
<Compile Include="Git\Tasks\GitRevertTask.cs" />
137137
<Compile Include="Application\IApplicationManager.cs" />
138+
<Compile Include="Platform\WindowsDiskUsageTask.cs" />
138139
<Compile Include="Primitives\Package.cs" />
139140
<Compile Include="Primitives\TheVersion.cs" />
140141
<Compile Include="Tasks\ActionTask.cs" />

src/GitHub.Api/Metrics/IUsageTracker.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ public interface IUsageTracker
2020
void IncrementPublishViewButtonPublish();
2121
void IncrementApplicationMenuMenuItemCommandLine();
2222
void UpdateRepoSize(int kilobytes);
23+
void UpdateLfsDiskUsage(int kilobytes);
2324
}
2425
}

src/GitHub.Api/Metrics/UsageModel.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public class Measures
4343
public int PublishViewButtonPublish { get; set; }
4444
public int ApplicationMenuMenuItemCommandLine { get; set; }
4545
public int GitRepoSize { get; set; }
46+
public int LfsDiskUsage { get; set; }
4647
}
4748

4849
class UsageModel

src/GitHub.Api/Metrics/UsageTracker.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,13 @@ public void UpdateRepoSize(int kilobytes)
243243
usageLoader.Save(usage);
244244
}
245245

246+
public void UpdateLfsDiskUsage(int kilobytes)
247+
{
248+
var usage = usageLoader.Load(userId);
249+
usage.GetCurrentMeasures(appVersion, unityVersion, instanceId).LfsDiskUsage = kilobytes;
250+
usageLoader.Save(usage);
251+
}
252+
246253
public bool Enabled
247254
{
248255
get
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.Collections.Generic;
2+
using System.Threading;
3+
4+
namespace GitHub.Unity
5+
{
6+
class WindowsDiskUsageTask : ProcessTask<List<string>>
7+
{
8+
private readonly string arguments;
9+
10+
public WindowsDiskUsageTask(NPath directory, CancellationToken token)
11+
: base(token, new SimpleListOutputProcessor())
12+
{
13+
Name = "cmd";
14+
arguments = "/c dir /a/s \"" + directory + "\"";
15+
}
16+
17+
public override string ProcessName { get { return Name; } }
18+
public override string ProcessArguments { get { return arguments; } }
19+
public override TaskAffinity Affinity { get { return TaskAffinity.Concurrent; } }
20+
public override string Message { get; set; } = "Getting directory size...";
21+
}
22+
}

0 commit comments

Comments
 (0)