@@ -14,10 +14,10 @@ namespace commands {
1414EngineInitCmd::EngineInitCmd (std::string engineName, std::string version)
1515 : engineName_(std::move(engineName)), version_(std::move(version)) {}
1616
17- void EngineInitCmd::Exec () const {
17+ bool EngineInitCmd::Exec () const {
1818 if (engineName_.empty ()) {
1919 LOG_ERROR << " Engine name is required" ;
20- return ;
20+ return false ;
2121 }
2222
2323 // Check if the architecture and OS are supported
@@ -26,15 +26,15 @@ void EngineInitCmd::Exec() const {
2626 system_info.os == system_info_utils::kUnsupported ) {
2727 LOG_ERROR << " Unsupported OS or architecture: " << system_info.os << " , "
2828 << system_info.arch ;
29- return ;
29+ return false ;
3030 }
3131 LOG_INFO << " OS: " << system_info.os << " , Arch: " << system_info.arch ;
3232
3333 // check if engine is supported
3434 if (std::find (supportedEngines_.begin (), supportedEngines_.end (),
3535 engineName_) == supportedEngines_.end ()) {
3636 LOG_ERROR << " Engine not supported" ;
37- return ;
37+ return false ;
3838 }
3939
4040 constexpr auto gitHubHost = " https://api.github.com" ;
@@ -78,7 +78,7 @@ void EngineInitCmd::Exec() const {
7878 LOG_INFO << " Matched variant: " << matched_variant;
7979 if (matched_variant.empty ()) {
8080 LOG_ERROR << " No variant found for " << os_arch;
81- return ;
81+ return false ;
8282 }
8383
8484 for (auto & asset : assets) {
@@ -103,36 +103,45 @@ void EngineInitCmd::Exec() const {
103103 .path = path,
104104 }}};
105105
106- DownloadService ().AddDownloadTask (
107- downloadTask, [](const std::string& absolute_path) {
108- // try to unzip the downloaded file
109- std::filesystem::path downloadedEnginePath{absolute_path};
110- LOG_INFO << " Downloaded engine path: "
111- << downloadedEnginePath.string ();
112-
113- archive_utils::ExtractArchive (
114- downloadedEnginePath.string (),
115- downloadedEnginePath.parent_path ()
116- .parent_path ()
117- .string ());
118-
119- // remove the downloaded file
120- std::filesystem::remove (absolute_path);
121- LOG_INFO << " Finished!" ;
122- });
123-
124- return ;
106+ DownloadService ().AddDownloadTask (downloadTask, [](const std::string&
107+ absolute_path,
108+ bool unused) {
109+ // try to unzip the downloaded file
110+ std::filesystem::path downloadedEnginePath{absolute_path};
111+ LOG_INFO << " Downloaded engine path: "
112+ << downloadedEnginePath.string ();
113+
114+ archive_utils::ExtractArchive (
115+ downloadedEnginePath.string (),
116+ downloadedEnginePath.parent_path ().parent_path ().string ());
117+
118+ // remove the downloaded file
119+ // TODO(any) Could not delete file on Windows because it is currently hold by httplib(?)
120+ // Not sure about other platforms
121+ try {
122+ std::filesystem::remove (absolute_path);
123+ } catch (const std::exception& e) {
124+ LOG_ERROR << " Could not delete file: " << e.what ();
125+ }
126+ LOG_INFO << " Finished!" ;
127+ });
128+
129+ return true ;
125130 }
126131 }
127132 } catch (const json::parse_error& e) {
128133 std::cerr << " JSON parse error: " << e.what () << std::endl;
134+ return false ;
129135 }
130136 } else {
131137 LOG_ERROR << " HTTP error: " << res->status ;
138+ return false ;
132139 }
133140 } else {
134141 auto err = res.error ();
135142 LOG_ERROR << " HTTP error: " << httplib::to_string (err);
143+ return false ;
136144 }
145+ return true ;
137146}
138147}; // namespace commands
0 commit comments