@@ -17,16 +17,18 @@ class Program
1717 public static Window Window ;
1818 public static string baseDir ;
1919
20- // todo: check json is buildplate
2120 static void Main ( string [ ] args )
2221 {
2322 // Get base path (.exe location)
2423 string myExecutable = Assembly . GetEntryAssembly ( ) . Location ;
2524
2625 if ( args != null && args . Length > 0 && args [ 0 ] == "setJsonDefault" ) {
2726 Util . SetAssociationWithExtension ( ".json" , "Json" , myExecutable , "BuildPlate" ) ;
27+ Util . SetAssociationWithExtension ( ".plate" , "Plate" , myExecutable , "BuildPlate" ) ;
28+ Util . SetAssociationWithExtension ( ".plate64" , "Plate64" , myExecutable , "BuildPlate" ) ;
2829 Console . WriteLine ( "Set .json as default, To Apply: Select .json file, click \" Open with\" , \" Choose another app\" , " +
2930 "Select BuildPlate_Editor, Check \" Always use this app...\" " ) ;
31+ Console . WriteLine ( "You can also do this for .plate and .plate64" ) ;
3032 Console . WriteLine ( "Press any key to continue..." ) ;
3133 Console . ReadKey ( true ) ;
3234 return ;
@@ -91,20 +93,41 @@ static void Main(string[] args)
9193 World . targetFilePath = @"C:\Users\Tomas\Desktop\Project Earth\Api\data\buildplates\00d1fa99-7acf-449d-bb4f-8d11127bd6e3.json" ;
9294#else
9395 Console . Write ( "Build plate to edit (.json): " ) ;
94- if ( args != null && args . Length > 0 && File . Exists ( args [ 0 ] ) ) {
95- World . targetFilePath = args [ 0 ] ;
96- Console . WriteLine ( args [ 0 ] ) ;
97- }
98- else {
99- string buildPlate = Console . ReadLine ( ) ;
100- if ( ! File . Exists ( buildPlate ) ) {
101- Console . WriteLine ( $ "build plate \" { buildPlate } \" doesn't exist") ;
102- Console . ReadKey ( true ) ;
103- return ;
96+ // json - api, plate - data only, plate64 - base64 encoded data
97+ if ( args != null && args . Length > 0 && File . Exists ( string . Join ( " " , args ) ) && string . Join ( " " , args ) . Split ( '.' ) . Length > 1 ) {
98+ string truePath = new FileInfo ( string . Join ( " " , args ) ) . FullName ;
99+ Console . WriteLine ( truePath ) ;
100+ string extension = truePath . Split ( '.' ) . Last ( ) ;
101+ if ( extension == "json" || extension == "plate" || extension == "plate64" ) {
102+ World . targetFilePath = truePath ;
103+ goto check ;
104104 }
105- World . targetFilePath = buildPlate ;
106105 }
106+
107+ string buildPlate = Console . ReadLine ( ) ;
108+ if ( ! File . Exists ( buildPlate ) ) {
109+ Console . WriteLine ( $ "build plate \" { buildPlate } \" doesn't exist") ;
110+ Console . ReadKey ( true ) ;
111+ return ;
112+ } else if ( Path . GetExtension ( buildPlate ) == ".json" || Path . GetExtension ( buildPlate ) == ".plate"
113+ || Path . GetExtension ( buildPlate ) == ".plate64" ) {
114+ Console . WriteLine ( $ "\" { Path . GetExtension ( buildPlate ) } \" isn't valid buildplate extension, valid: .json, .plate, .plate64") ;
115+ Console . ReadKey ( true ) ;
116+ return ;
117+ }
118+ World . targetFilePath = buildPlate ;
107119#endif
120+ check :
121+ // check json is buildplate
122+ try {
123+ BuildPlate . Load ( World . targetFilePath ) ;
124+ } catch {
125+ Console . WriteLine ( $ "Couldn't parse \" { World . targetFilePath } \" , Make sure it's valid build plate file.") ;
126+ Console . WriteLine ( "Press any key to exit..." ) ;
127+ Console . ReadKey ( true ) ;
128+ return ;
129+ }
130+
108131 Window = new Window ( ) ;
109132 string version ;
110133 try { version = OpenGLHelper . GetVersion ( ) ; } catch { version = "Failed to get version" ; }
0 commit comments