88using  System . Threading . Tasks ; 
99using  wtf . cluster . FDSPacker . JsonTypes ; 
1010using  System . Text . RegularExpressions ; 
11+ using  Newtonsoft . Json ; 
12+ using  Newtonsoft . Json . Serialization ; 
1113
1214namespace  wtf . cluster . FDSPacker 
1315{ 
1416 static   class  FdsPackUnpack 
1517 { 
1618 const  string  DISK_INFO_FILE  =  "diskinfo.json" ; 
1719
20+  static   JsonSerializerSettings  jsonOptions  =  new  JsonSerializerSettings 
21+  { 
22+  NullValueHandling  =  NullValueHandling . Include , 
23+  ContractResolver  =  new  DefaultContractResolver 
24+  { 
25+  NamingStrategy  =  new  SnakeCaseNamingStrategy ( ) 
26+  } , 
27+  Formatting  =  Formatting . Indented 
28+  } ; 
29+ 
1830 // Unpack a .fds file 
1931 public  static   void  Unpack ( UnpackOptions  options ) 
2032 { 
@@ -23,10 +35,12 @@ public static void Unpack(UnpackOptions options)
2335
2436 // Copy data to a JSON object 
2537 var  root  =  new  FdsJsonRoot ( ) ; 
38+  var  invalidCharsPattern  =  $ "[{ Regex . Escape ( new  string ( Path . GetInvalidFileNameChars ( ) ) ) } ]"; 
2639 for  ( var  sideId  =  0 ;  sideId  <  fds . Sides . Count ;  sideId ++ ) 
2740 { 
2841 var  side  =  fds . Sides [ sideId ] ; 
2942 var  outSide  =  new  FdsJsonSide ( ) ; 
43+  outSide . WriteUnknown  =  ! options . NoUnknown ; 
3044 var  sideDirName  =  $ "side_{ sideId  +  1 } "; 
3145 var  sideFullPath  =  Path . Combine ( options . OutputDir ,  sideDirName ) ; 
3246 Directory . CreateDirectory ( sideFullPath ) ; 
@@ -39,8 +53,8 @@ public static void Unpack(UnpackOptions options)
3953 var  outFile  =  new  FdsJsonFile ( ) ; 
4054 CopyProperties ( file ,  outFile ) ; 
4155 // Avoid filename duplication 
42-  var  name  =  file . FileName ; 
43-  var  altName  =  name . ToLower ( ) ; 
56+  var  name  =  Regex . Replace ( file . FileName . ToLower ( ) ,   invalidCharsPattern ,   "_" ) ; 
57+  var  altName  =  name ; 
4458 int  id  =  1 ; 
4559 while  ( usedFiles . Contains ( altName ! ) ) 
4660 { 
@@ -72,14 +86,7 @@ public static void Unpack(UnpackOptions options)
7286
7387 // Save JSON 
7488 var  targetFile  =  Path . Combine ( options . OutputDir ,  DISK_INFO_FILE ) ; 
75-  var  jsonOptions  =  new  JsonSerializerOptions 
76-  { 
77-  WriteIndented  =  true , 
78-  DefaultIgnoreCondition  =  JsonIgnoreCondition . Never , 
79-  ReadCommentHandling  =  JsonCommentHandling . Skip , 
80-  PropertyNamingPolicy  =  new  SnakeCaseNamingPolicy ( ) 
81-  } ; 
82-  var  json  =  JsonSerializer . Serialize ( root ,  jsonOptions ) ; 
89+  var  json  =  JsonConvert . SerializeObject ( root ,  jsonOptions ) ; 
8390 File . WriteAllText ( targetFile ,  json ) ; 
8491 } 
8592
@@ -89,14 +96,8 @@ public static void Pack(PackOptions options)
8996 var  inputFile  =  options . InputFile ; 
9097 if  ( Directory . Exists ( inputFile ) ) 
9198 inputFile  =  Path . Combine ( inputFile ,  DISK_INFO_FILE ) ;  ; 
92-  var  jsonOptions  =  new  JsonSerializerOptions 
93-  { 
94-  DefaultIgnoreCondition  =  JsonIgnoreCondition . Never , 
95-  ReadCommentHandling  =  JsonCommentHandling . Skip , 
96-  PropertyNamingPolicy  =  new  SnakeCaseNamingPolicy ( ) 
97-  } ; 
9899 var  jsonData  =  File . ReadAllText ( inputFile ) ; 
99-  var  root  =  JsonSerializer . Deserialize < FdsJsonRoot > ( jsonData ,  jsonOptions ) ; 
100+  var  root  =  JsonConvert . DeserializeObject < FdsJsonRoot > ( jsonData ,  jsonOptions ) ; 
100101 if  ( root  ==  null )  throw  new  InvalidDataException ( "Invalid input JSON file" ) ; 
101102
102103 // Copy data from a JSON object 
0 commit comments