1-
21import 'dart:convert' ;
32import 'dart:io' ;
43import 'dart:ui' ;
@@ -12,29 +11,59 @@ import 'modules_manager.dart';
1211class CCSolution {
1312 final String name, desc, author, identifier, slnPath, slnFolderPath;
1413 DateTime dateModified;
15- Widget ? get image{
14+ List <RunConfiguration > runConfig;
15+ int currentRunConfig = 0 ;
16+
17+ Widget ? get image {
1618 var module = ModulesManager .getModuleByIdentifier (identifier);
17- if (module != null ) {
19+ if (module != null ) {
1820 return module.icon;
1921 }
2022 }
23+
2124 Map <String , String > folders = {};
2225 List <CCProject > projects = [];
2326
2427 static const decoder = JsonDecoder ();
2528
2629 CCSolution (this .name, this .desc, this .author, this .identifier, this .slnPath,
27- this .slnFolderPath, this .dateModified);
30+ this .slnFolderPath, this .dateModified, this .runConfig );
2831
29- static Future <CCSolution ?> loadFromFile (String filepath) async {
32+ void run () async {
33+
34+ if (Platform .isWindows) {
35+ debugPrint (
36+ "[CC Debug] starting project on windows config `${runConfig [currentRunConfig ].executable }` on $slnFolderPath " );
37+ if (runConfig[currentRunConfig].type == "process" ) {
38+ var result = await Process .run (
39+ runConfig[currentRunConfig].executable, runConfig[currentRunConfig].arguments,
40+ workingDirectory: slnFolderPath);
41+ debugPrint ("[STDOUT] ${result .stdout }" );
42+ debugPrint ("[STDERR] ${result .stderr }" );
43+ }
44+ }
45+ }
46+
47+ static Future <CCSolution ?> loadFromFile (String filepath) async {
3048 var file = File (filepath);
3149 if (await file.exists ()) {
3250 var stat = await file.stat ();
3351 String input = await file.readAsString ();
3452 try {
3553 var obj = decoder.convert (input);
36- var result = CCSolution (obj["name" ], obj["description" ] ?? "" ,
37- obj["author" ], obj["identifier" ], filepath, file.parent.path, stat.modified);
54+ List <RunConfiguration > runConfigs = [];
55+ if (obj["run_config" ] is Map ) {
56+ runConfigs = RunConfiguration .loadFromJSON (obj["run_config" ]);
57+ }
58+ var result = CCSolution (
59+ obj["name" ],
60+ obj["description" ] ?? "" ,
61+ obj["author" ],
62+ obj["identifier" ],
63+ filepath,
64+ file.parent.path,
65+ stat.modified,
66+ runConfigs);
3867
3968 /// Add the solution project folders
4069 var folders = (obj["folders" ] as Map );
@@ -55,6 +84,38 @@ class CCSolution {
5584
5685class CCProject {
5786 final String name, desc, author, identifier, slnPath, slnFolderPath, projPath;
87+
5888 CCProject (this .name, this .desc, this .author, this .identifier, this .slnPath,
5989 this .slnFolderPath, this .projPath);
60- }
90+ }
91+
92+ class RunConfiguration {
93+ String name, type, executable;
94+ List <String > arguments;
95+
96+ RunConfiguration (this .name, this .type, this .executable, this .arguments);
97+
98+ static List <RunConfiguration > loadFromJSON (Map json) {
99+ var result = < RunConfiguration > [];
100+ if (json.containsKey ("windows" ) && Platform .isWindows) {
101+ try {
102+ for (var obj in json["windows" ] as List ) {
103+ var name = obj["name" ] ?? "runConfig.name" ;
104+ var type = obj["type" ] ?? "unknown" ;
105+ var executable = obj["executable" ] ?? "runConfig.executable" ;
106+ var _args = (obj["args" ] ?? []) as List ;
107+ var args = < String > [];
108+ for (var arg in _args){
109+ args.add (arg);
110+ }
111+ result.add (RunConfiguration (name, type, executable, args));
112+ }
113+ } catch (err) {
114+ debugPrint (err.toString ());
115+ }
116+ }
117+
118+ //TODO: implement android run config
119+ return result;
120+ }
121+ }
0 commit comments