11using System ;
22using System . IO ;
33using System . IO . Compression ;
4+ using System . Linq ;
5+ using System . Text . RegularExpressions ;
46
57namespace SolderPackager
68{
79 class Program
810 {
911 static void Main ( string [ ] args )
1012 {
11-
1213 WriteCenter ( "Solder Packager app" ) ;
1314 WriteCenter ( "by StormMC team" ) ;
1415 WriteCenter ( "It is recommended that you maximize your console window." , 1 ) ;
1516 WriteCenter ( "Please, specify the path to your mods folder." , 2 ) ;
1617 Console . Write ( "\n Path to mods folder> " ) ;
17- var path = Console . ReadLine ( ) ;
18-
18+ var path = Console . ReadLine ( ) ;
19+
1920 try
20- {
21- DirectoryInfo d = new DirectoryInfo ( path ) ;
21+ {
22+ DirectoryInfo d = new DirectoryInfo ( path ) ;
2223 if ( d . GetFiles ( "*.jar" ) . Length == 0 )
23- {
24- WriteCenter ( "There are no jar files in that directory!!" ) ;
25- }
24+ WriteCenter ( "There are no jar files in that directory!!" ) ;
25+
2626 else
2727 {
2828 WriteCenter ( $ "All jar files in directory { path } : ", 1 ) ;
2929
3030 foreach ( var item in d . GetFiles ( "*.jar" ) )
31- {
3231 WriteCenter ( $ "{ Path . GetFileNameWithoutExtension ( item . Name ) } - { item . CreationTime . ToShortDateString ( ) } { item . CreationTime . ToShortTimeString ( ) } ") ;
33- }
3432
3533 Console . BackgroundColor = ConsoleColor . Red ;
3634 Console . ForegroundColor = ConsoleColor . Black ;
@@ -48,32 +46,64 @@ static void Main(string[] args)
4846 Console . BackgroundColor = ConsoleColor . Yellow ;
4947 Console . ForegroundColor = ConsoleColor . Black ;
5048 WriteCenter ( "OK, working on that..." , 2 ) ;
49+
5150 Console . ResetColor ( ) ;
5251 var zipPath = path + "/solderzips/" ;
5352 Directory . CreateDirectory ( zipPath ) ;
54- foreach ( var item in d . GetFiles ( "*.jar" ) )
53+
54+ var basehtml = "<!DOCTYPE html><html><head> <title>Solder Packager Information</title> <meta charset=\" utf-8\" > <meta name=\" viewport\" content=\" width=device-width, initial-scale=1\" > <link rel=\" stylesheet\" href=\" https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\" > <script src=\" https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js\" ></script> <script src=\" https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\" ></script></head><body> <div class=\" container\" > <div class=\" row text-center\" style=\" \" > <h1>Solder Packager report<p> </p></h1> <table id=\" tablePreview\" class=\" table\" > <thead> <tr> <th>No</th> <th style=\" text-align: center;\" >Mod Name</th> <th style=\" text-align: center;\" >Mod Version</th> </tr></thead> <tbody>" ;
55+ var endhtml = @"</tr></tbody><!--Table body--></table><!--Table--></div></div></body></html>" ;
56+
57+ int modNumber = 0 ;
58+
59+ var files = d . GetFiles ( "*.jar" ) . OrderBy ( fi => fi . Name ) . ToArray ( ) ;
60+ foreach ( var item in files )
5561 {
56- var ms = new MemoryStream ( ) ;
57- var archive = new ZipArchive ( ms , ZipArchiveMode . Create , true ) ;
58- archive . CreateEntryFromFile ( item . FullName , $ "mods/{ item . Name } ") ;
59- ms . Seek ( 0 , SeekOrigin . Begin ) ;
60- File . WriteAllBytes ( $ "{ zipPath } { Path . GetFileNameWithoutExtension ( item . Name ) } .zip", ms . ToArray ( ) ) ;
61- }
62+ var content = Path . GetFileNameWithoutExtension ( item . Name ) ;
63+ var replaced = ( content . Replace ( '+' , '-' ) ) . Replace ( '_' , '-' ) . Replace ( "'" , "" ) ;
64+ Regex regexDash = new Regex ( @"(?<=-).*$" ) ;
65+ Match matchDash = regexDash . Match ( replaced ) ;
66+ modNumber ++ ;
67+ try
68+ {
69+ var foldername = replaced . Trim ( new char [ ] { '+' , '-' , '_' , '\' ' } ) . Replace ( matchDash . Value , "" ) . Trim ( new char [ ] { '+' , '-' , '_' , '\' ' } ) ;
70+ Directory . CreateDirectory ( zipPath + foldername . ToLower ( ) ) ;
71+ var ms = new MemoryStream ( ) ;
72+ var archive = new ZipArchive ( ms , ZipArchiveMode . Create , true ) ;
73+ archive . CreateEntryFromFile ( item . FullName , $ "mods/{ item . Name } ") ;
74+ ms . Seek ( 0 , SeekOrigin . Begin ) ;
75+ File . WriteAllBytes ( $ "{ zipPath } { foldername . ToLower ( ) } /{ replaced . ToLower ( ) } .zip", ms . ToArray ( ) ) ;
76+ basehtml += $ "<tr> <th scope=\" row\" >{ modNumber } </th> <td>{ foldername } </td><td>{ matchDash . Value } </td></tr>";
77+ }
78+ catch
79+ {
80+ basehtml += $ "<tr> <th scope=\" row\" >{ modNumber } </th> <td>{ Path . GetFileNameWithoutExtension ( item . Name ) } </td><td>(no more info available)</td></tr>";
81+ WriteCenter ( $ "Couldn't figure out a folder to the mod { item . Name } ", 2 ) ;
82+ WriteCenter ( "so it's in the root folder of your solderzips." ) ;
83+ var ms = new MemoryStream ( ) ;
84+ var archive = new ZipArchive ( ms , ZipArchiveMode . Create , true ) ;
85+ archive . CreateEntryFromFile ( item . FullName , $ "mods/{ item . Name } ") ;
86+ ms . Seek ( 0 , SeekOrigin . Begin ) ;
87+ File . WriteAllBytes ( $ "{ zipPath } { Path . GetFileNameWithoutExtension ( item . Name ) . ToLower ( ) } .zip", ms . ToArray ( ) ) ;
88+ }
89+ }
6290
91+ basehtml += endhtml ;
92+ File . WriteAllText ( zipPath + "report.html" , basehtml ) ;
6393 Console . BackgroundColor = ConsoleColor . DarkGreen ;
6494 Console . ForegroundColor = ConsoleColor . Black ;
6595 WriteCenter ( "Success!" , 2 ) ;
6696 Console . BackgroundColor = ConsoleColor . Green ;
67- WriteCenter ( "Keep in mind that file names are the same from the" ) ;
68- WriteCenter ( "jar files, but with the zip extension. You might" ) ;
97+ WriteCenter ( "Keep in mind that file names are the same from the" , 1 ) ;
98+ WriteCenter ( "jar files, but with the zip extension. You might" ) ;
6999 WriteCenter ( "need to change the file names." ) ;
70- }
71- }
100+ WriteCenter ( "A HTML file has been created with information." , 1 ) ;
101+ }
102+ }
72103 catch
73- {
74- WriteCenter ( "There is no directory by that path!" ) ;
75- }
76-
104+ {
105+ WriteCenter ( "There is no directory by that path!" ) ;
106+ }
77107 }
78108
79109 internal static void WriteCenter ( string value , int skipline = 0 )
0 commit comments