Showing
3 changed files
with
36 additions
and
4 deletions
| ... | @@ -38,6 +38,9 @@ | ... | @@ -38,6 +38,9 @@ |
| 38 | <Reference Include="LibGit2Sharp, Version=0.25.0.0, Culture=neutral, PublicKeyToken=7cbde695407f0333, processorArchitecture=MSIL"> | 38 | <Reference Include="LibGit2Sharp, Version=0.25.0.0, Culture=neutral, PublicKeyToken=7cbde695407f0333, processorArchitecture=MSIL"> |
| 39 | <HintPath>..\packages\LibGit2Sharp.0.25.0\lib\netstandard2.0\LibGit2Sharp.dll</HintPath> | 39 | <HintPath>..\packages\LibGit2Sharp.0.25.0\lib\netstandard2.0\LibGit2Sharp.dll</HintPath> |
| 40 | </Reference> | 40 | </Reference> |
| 41 | + <Reference Include="Octokit, Version=0.29.0.0, Culture=neutral, processorArchitecture=MSIL"> | ||
| 42 | + <HintPath>..\packages\Octokit.0.29.0\lib\net45\Octokit.dll</HintPath> | ||
| 43 | + </Reference> | ||
| 41 | <Reference Include="System" /> | 44 | <Reference Include="System" /> |
| 42 | <Reference Include="System.Core" /> | 45 | <Reference Include="System.Core" /> |
| 43 | <Reference Include="System.Xml.Linq" /> | 46 | <Reference Include="System.Xml.Linq" /> | ... | ... |
| ... | @@ -6,19 +6,28 @@ using System.Threading.Tasks; | ... | @@ -6,19 +6,28 @@ using System.Threading.Tasks; |
| 6 | 6 | ||
| 7 | namespace DownloaderGithubClone | 7 | namespace DownloaderGithubClone |
| 8 | { | 8 | { |
| 9 | - using LibGit2Sharp; | 9 | + // using LibGit2Sharp; |
| 10 | + using System.IO; | ||
| 10 | using System.Text.RegularExpressions; | 11 | using System.Text.RegularExpressions; |
| 12 | + using LibGit2Sharp; | ||
| 13 | + | ||
| 11 | 14 | ||
| 12 | class Program | 15 | class Program |
| 13 | { | 16 | { |
| 14 | static void Main(string[] args) { | 17 | static void Main(string[] args) { |
| 15 | 18 | ||
| 19 | + string dir = @"c:\VulnPy"; | ||
| 20 | + if (!Directory.Exists(dir)) { | ||
| 21 | + Directory.CreateDirectory(dir); | ||
| 22 | + Console.WriteLine($"디렉토리 생성 : {dir}"); | ||
| 23 | + } | ||
| 24 | + | ||
| 16 | Console.Write("Git Repository URL을 입력하세요 : "); | 25 | Console.Write("Git Repository URL을 입력하세요 : "); |
| 17 | string url = Console.ReadLine(); | 26 | string url = Console.ReadLine(); |
| 18 | //https://github.com/django/django.git | 27 | //https://github.com/django/django.git |
| 19 | 28 | ||
| 20 | 29 | ||
| 21 | - string pattern = @"https://github.com/(?<ProjectName>\w+)/\w+\.git"; | 30 | + string pattern = @"https://github.com/.+/(?<ProjectName>.+)\.(.+)"; |
| 22 | 31 | ||
| 23 | var match = Regex.Match(url, pattern); | 32 | var match = Regex.Match(url, pattern); |
| 24 | 33 | ||
| ... | @@ -26,11 +35,29 @@ namespace DownloaderGithubClone | ... | @@ -26,11 +35,29 @@ namespace DownloaderGithubClone |
| 26 | Console.WriteLine($"패턴이 맞지 않습니다. Pattern : {pattern}"); | 35 | Console.WriteLine($"패턴이 맞지 않습니다. Pattern : {pattern}"); |
| 27 | return; | 36 | return; |
| 28 | } | 37 | } |
| 38 | + | ||
| 39 | + | ||
| 29 | string prName = match.Groups["ProjectName"].Value; | 40 | string prName = match.Groups["ProjectName"].Value; |
| 30 | Console.WriteLine(prName); | 41 | Console.WriteLine(prName); |
| 31 | 42 | ||
| 43 | + int idx = 1; | ||
| 44 | + string path = Path.Combine(dir, prName); | ||
| 45 | + if (Directory.Exists(path)) { | ||
| 46 | + while (true) { | ||
| 47 | + path = Path.Combine(dir, prName + idx); | ||
| 48 | + if (!Directory.Exists(path)) { | ||
| 49 | + Directory.CreateDirectory(path); | ||
| 50 | + Console.WriteLine($"레파지토리 디렉토리 생성 : {path}"); | ||
| 51 | + break; | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + } | ||
| 32 | 55 | ||
| 33 | - string clone = Repository.Clone(url, $@"c:\VulnPy\{prName}", new CloneOptions { OnTransferProgress = TransferProgress, OnCheckoutProgress = CheckoutProcess }); | 56 | + Console.WriteLine($"다운로드를 진행합니다. 경로 : {path}"); |
| 57 | + | ||
| 58 | + | ||
| 59 | + string clone = Repository.Clone(url, $@"{path}", new CloneOptions { OnTransferProgress = TransferProgress, OnCheckoutProgress = CheckoutProcess }); | ||
| 60 | + Console.ResetColor(); | ||
| 34 | Console.WriteLine(clone); | 61 | Console.WriteLine(clone); |
| 35 | } | 62 | } |
| 36 | 63 | ||
| ... | @@ -44,13 +71,14 @@ namespace DownloaderGithubClone | ... | @@ -44,13 +71,14 @@ namespace DownloaderGithubClone |
| 44 | int receivedBytes = progress.ReceivedObjects; | 71 | int receivedBytes = progress.ReceivedObjects; |
| 45 | long receivedTotal = progress.ReceivedBytes; | 72 | long receivedTotal = progress.ReceivedBytes; |
| 46 | double received = progress.ReceivedBytes / 1000000; | 73 | double received = progress.ReceivedBytes / 1000000; |
| 47 | - double percent = ((double)receivedBytes / (double)totalBytes) * 10; | 74 | + double percent = ((double)receivedBytes / (double)totalBytes); |
| 48 | 75 | ||
| 49 | Console.WriteLine($"진행률: {percent.ToString("P2")}, 남은 파일: {receivedBytes} of {totalBytes}"); //, 받은 용량: {received.ToString()}MB"); | 76 | Console.WriteLine($"진행률: {percent.ToString("P2")}, 남은 파일: {receivedBytes} of {totalBytes}"); //, 받은 용량: {received.ToString()}MB"); |
| 50 | Console.ForegroundColor = ConsoleColor.DarkGreen; | 77 | Console.ForegroundColor = ConsoleColor.DarkGreen; |
| 51 | return true; | 78 | return true; |
| 52 | } | 79 | } |
| 53 | 80 | ||
| 81 | + | ||
| 54 | public static void CheckoutProcess(string path, int completedSteps, int totalSteps) { | 82 | public static void CheckoutProcess(string path, int completedSteps, int totalSteps) { |
| 55 | Console.WriteLine($"{completedSteps}, {totalSteps}, {path}"); | 83 | Console.WriteLine($"{completedSteps}, {totalSteps}, {path}"); |
| 56 | } | 84 | } | ... | ... |
| ... | @@ -2,4 +2,5 @@ | ... | @@ -2,4 +2,5 @@ |
| 2 | <packages> | 2 | <packages> |
| 3 | <package id="LibGit2Sharp" version="0.25.0" targetFramework="net461" /> | 3 | <package id="LibGit2Sharp" version="0.25.0" targetFramework="net461" /> |
| 4 | <package id="LibGit2Sharp.NativeBinaries" version="1.0.210" targetFramework="net461" /> | 4 | <package id="LibGit2Sharp.NativeBinaries" version="1.0.210" targetFramework="net461" /> |
| 5 | + <package id="Octokit" version="0.29.0" targetFramework="net461" /> | ||
| 5 | </packages> | 6 | </packages> |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment