@@ -9,6 +9,7 @@ using System.IO.Compression;
9
9
using System . Collections . Generic ;
10
10
using System . Linq ;
11
11
using System . Text . RegularExpressions ;
12
+ using GitignoreParserNet ;
12
13
13
14
// Define source and destination paths
14
15
string srcStandalone = @".\src\ReadieFur.SourceAnalyzer.Standalone\bin\Debug\net472" ;
@@ -70,31 +71,28 @@ void CopyFiles(string sourceDir, string destDir)
70
71
71
72
void ArchiveFiles ( )
72
73
{
73
- // Ignore.Ignore ignore = new();
74
-
75
- // IEnumerable<string> gitignoreContents = File.ReadAllText(".gitignore")
76
- // .Split('\n')
77
- // .Where(line => !string.IsNullOrWhiteSpace(line) && !line.StartsWith("#") && line != "[Bb]in/"); //Force inclusion of build output files for this use case.
78
-
79
- // //Perfect that this isn't working :3.
80
- // ignore.Add(gitignoreContents);
81
-
82
- // IEnumerable<string> files = Directory.EnumerateFiles(srcDir, "*", SearchOption.AllDirectories)
83
- // // .Select(file => (Environment.CurrentDirectory + file.Substring(1)).Replace('\\', '/'));
84
- // .Select(file => file.Substring(2).Replace('\\', '/'));
85
- // IEnumerable<string> filesToArchive = ignore.Filter(files);
86
-
87
- // using (ZipArchive archive = ZipFile.Open(srcZipPath, ZipArchiveMode.Create))
88
- // {
89
- // foreach (string file in filesToArchive)
90
- // {
91
- // string relativePath = Path.GetRelativePath(srcDir, file);
92
- // archive.CreateEntryFromFile(file, relativePath);
93
- // }
94
- // }
74
+ string [ ] excludeOverrides = { "[Bb]in/" , "[Rr]elease/" , "[Dd]ebug/" } ;
75
+ string [ ] additionalExcludes = { "TestResults/" } ;
95
76
96
77
IEnumerable < string > gitignoreContents = File . ReadAllText ( ".gitignore" )
97
78
. Split ( '\n ' )
98
- . Where ( line => ! string . IsNullOrWhiteSpace ( line ) && ! line . StartsWith ( "#" ) && line != "[Bb]in/" ) ; //Force inclusion of build output files for this use case.
99
- GitignoreParser . Parse ( string . Join ( '\n ' , gitignoreContents ) , srcDir , srcZipPath ) ;
79
+ . Where ( line =>
80
+ ( ! string . IsNullOrWhiteSpace ( line )
81
+ && ! line . StartsWith ( "#" )
82
+ && ! excludeOverrides . Any ( line . Contains ) )
83
+ || additionalExcludes . Any ( line . Contains ) ) ;
84
+
85
+ GitignoreParser parser = new ( string . Join ( '\n ' , gitignoreContents ) ) ;
86
+
87
+ IEnumerable < string > archiveFiles = Directory . EnumerateFiles ( srcDir , "*" , SearchOption . AllDirectories )
88
+ . Where ( file => parser . Accepts ( file ) ) ;
89
+
90
+ using ( ZipArchive archive = ZipFile . Open ( srcZipPath , ZipArchiveMode . Create ) )
91
+ {
92
+ foreach ( string file in archiveFiles )
93
+ {
94
+ string relativePath = Path . GetRelativePath ( srcDir , file ) ;
95
+ archive . CreateEntryFromFile ( file , relativePath ) ;
96
+ }
97
+ }
100
98
}
0 commit comments