Kiok Ahn

DownloaderGithub

...@@ -6,11 +6,54 @@ using System.Threading.Tasks; ...@@ -6,11 +6,54 @@ using System.Threading.Tasks;
6 6
7 namespace DownloaderGithubClone 7 namespace DownloaderGithubClone
8 { 8 {
9 + using LibGit2Sharp;
10 + using System.Text.RegularExpressions;
11 +
9 class Program 12 class Program
10 { 13 {
11 static void Main(string[] args) { 14 static void Main(string[] args) {
12 15
13 - Console.WriteLine("A"); 16 + Console.Write("Git Repository URL을 입력하세요 : ");
17 + string url = Console.ReadLine();
18 + //https://github.com/django/django.git
19 +
20 + string pattern = @"https://github.com/(?<ProjectName>\w+)/\w+\.git";
21 +
22 + var match = Regex.Match(url, pattern);
23 +
24 + if (!match.Success) {
25 + Console.WriteLine($"패턴이 맞지 않습니다. Pattern : {pattern}");
26 + return;
27 + }
28 + string prName = match.Groups["ProjectName"].Value;
29 + Console.WriteLine(prName);
30 +
31 +
32 + string clone = Repository.Clone(url, $@"c:\VulnPy\{prName}", new CloneOptions { OnTransferProgress = TransferProgress, OnCheckoutProgress = CheckoutProcess });
33 + Console.WriteLine(clone);
14 } 34 }
35 +
36 + /// <summary>
37 + /// Clone 콜백 함수
38 + /// </summary>
39 + /// <param name="progress"></param>
40 + /// <returns></returns>
41 + public static bool TransferProgress(TransferProgress progress) {
42 + int totalBytes = progress.TotalObjects;
43 + int receivedBytes = progress.ReceivedObjects;
44 + long receivedTotal = progress.ReceivedBytes;
45 + double received = progress.ReceivedBytes / 1000000;
46 + double percent = ((double)receivedBytes / (double)totalBytes) * 10;
47 +
48 + Console.WriteLine($"진행률: {percent.ToString("P2")}, 남은 파일: {receivedBytes} of {totalBytes}"); //, 받은 용량: {received.ToString()}MB");
49 + Console.ForegroundColor = ConsoleColor.DarkGreen;
50 + return true;
51 + }
52 +
53 + public static void CheckoutProcess(string path, int completedSteps, int totalSteps) {
54 + Console.WriteLine($"{completedSteps}, {totalSteps}, {path}");
55 + }
56 +
57 +
15 } 58 }
16 } 59 }
......