From 3448f30a93044a549f78beb0126170ef82194559 Mon Sep 17 00:00:00 2001 From: Dan Rosser Date: Thu, 20 Mar 2025 15:58:53 +1100 Subject: [PATCH 1/3] V0.98.0 - Android Studio exec open all platforms - Visual Studio determine target SLN and open version 2022 if target or 2019 if target. Fixes VS2019 installed opening by default --- commandLine/src/defines.h | 2 +- frontend/index.js | 98 +++++++++++++++++++++++++++++++++++---- 2 files changed, 90 insertions(+), 10 deletions(-) diff --git a/commandLine/src/defines.h b/commandLine/src/defines.h index 49aede68..f2b9731b 100644 --- a/commandLine/src/defines.h +++ b/commandLine/src/defines.h @@ -1,5 +1,5 @@ #define OFPROJECTGENERATOR_MAJOR_VERSION "0" -#define OFPROJECTGENERATOR_MINOR_VERSION "97" +#define OFPROJECTGENERATOR_MINOR_VERSION "98" #define OFPROJECTGENERATOR_PATCH_VERSION "0" #define PG_VERSION (OFPROJECTGENERATOR_MAJOR_VERSION "." OFPROJECTGENERATOR_MINOR_VERSION "." OFPROJECTGENERATOR_PATCH_VERSION) diff --git a/frontend/index.js b/frontend/index.js index d1dade5d..8e912cc5 100644 --- a/frontend/index.js +++ b/frontend/index.js @@ -1198,6 +1198,74 @@ ipcMain.on('checkMultiUpdatePath', (event, arg) => { } }); +function getVisualStudioPath(version) { + return new Promise((resolve, reject) => { + exec(`"C:\\Program Files (x86)\\Microsoft Visual Studio\\Installer\\vswhere.exe" -latest -prerelease -format json`, (error, stdout, stderr) => { + if (error) { + reject("vswhere.exe not found. Ensure Visual Studio is installed."); + return; + } + + try { + const installations = JSON.parse(stdout); + const vsInstall = installations.find(install => + install.displayName.includes("Visual Studio") && install.catalog.productDisplayVersion.startsWith(version) + ); + + if (vsInstall) { + resolve(path.join(vsInstall.installationPath, "Common7", "IDE", "devenv.exe")); + } else { + reject(`No Visual Studio ${version} installation found.`); + } + } catch (parseError) { + reject("Error parsing vswhere output."); + } + }); + }); +} + +async function openVisualStudio(windowsPath) { + console.log(`Opening project: ${windowsPath} in ${platform}`); + + if (platform === 'vscode') { + console.log("Opening in VS Code..."); + exec(`code "${windowsPath}"`, (error, stdout, stderr) => { + if (error) { + console.error("Could not open VS Code:", stderr); + console.log("Falling back to system handler..."); + exec(`start "" "${windowsPath}"`); + } + }); + return; + } + + let isVS2019Project = false; + const solutionFile = path.join(path.dirname(windowsPath), path.basename(windowsPath)); + + if (fs.existsSync(solutionFile)) { + const fileContent = fs.readFileSync(solutionFile, 'utf8'); + if (fileContent.includes("VisualStudioVersion = 16.0")) { + isVS2019Project = true; + } + } + + try { + if (isVS2019Project) { + console.log("Detected VS2019 project, searching for VS2019 installation..."); + const vs2019Path = await getVisualStudioPath("16"); + exec(`"${vs2019Path}" "${windowsPath}"`); + } else { + console.log("Opening in VS2022 by default..."); + const vs2022Path = await getVisualStudioPath("17"); + exec(`"${vs2022Path}" "${windowsPath}"`); + } + } catch (error) { + console.error("Could not open Visual Studio:", error); + console.log("Falling back to default system handler..."); + exec(`start "" "${windowsPath}"`); + } +} + ipcMain.on('launchProjectinIDE', (event, arg) => { const { projectPath, @@ -1243,12 +1311,27 @@ ipcMain.on('launchProjectinIDE', (event, arg) => { } } else if( arg.platform == 'android'){ console.log("Launching ", fullPath) - exec('studio ' + fullPath, (error, stdout, stderr) => { - if(error){ + console.log("Launching Android Studio at", fullPath); + let command; + + if (os.platform() === 'darwin') { // macOS + command = `open -a "Android Studio" "${fullPath}"`; + } else if (os.platform() === 'linux') { // Linux + command = `studio "${fullPath}" || xdg-open "${fullPath}"`; + } else if (os.platform() === 'win32') { // Windows + command = `start "" "studio64.exe" "${fullPath}"`; + } else { + console.error("Unsupported OS for launching Android Studio"); + return; + } + + exec(command, (error, stdout, stderr) => { + if (error) { + console.error("Could not launch Android Studio:", stderr); event.sender.send('sendUIMessage', - 'Error!
' + - 'Could not launch Android Studio. Make sure the command-line launcher is installed by running Tools -> Create Command-line Launcher... inside Android Studio and try again' - ); + 'Error!
' + + 'Could not launch Android Studio. Make sure the command-line launcher is installed by running Tools -> Create Command-line Launcher... inside Android Studio and try again.' + ); } }); } else if( hostplatform == 'windows'){ @@ -1257,12 +1340,9 @@ ipcMain.on('launchProjectinIDE', (event, arg) => { if(arg.platform == 'vscode' ){ windowsPath = path.join(fullPath, projectName + '.code-workspace'); } - console.log( windowsPath ); windowsPath = "\"" + windowsPath + "\""; - exec('start ' + "\"\"" + " " + windowsPath, (error, stdout, stderr) => { - return; - }); + openVisualStudio(windowsPath); } }); From 5a98d9589d15a843f7196502f3475166956c3157 Mon Sep 17 00:00:00 2001 From: Dan Rosser Date: Thu, 20 Mar 2025 20:25:47 +1100 Subject: [PATCH 2/3] Visual Studio Fixes for opening correct Version --- commandLine/src/defines.h | 2 +- commandLine/src/main.cpp | 26 +++++----- commandLine/src/projects/baseProject.cpp | 64 ++++++++++-------------- commandLine/src/projects/baseProject.h | 2 +- commandLine/src/utils/Utils.cpp | 2 +- frontend/index.js | 48 +++++++++++++----- 6 files changed, 79 insertions(+), 65 deletions(-) diff --git a/commandLine/src/defines.h b/commandLine/src/defines.h index f2b9731b..3b22c6f4 100644 --- a/commandLine/src/defines.h +++ b/commandLine/src/defines.h @@ -1,5 +1,5 @@ #define OFPROJECTGENERATOR_MAJOR_VERSION "0" -#define OFPROJECTGENERATOR_MINOR_VERSION "98" +#define OFPROJECTGENERATOR_MINOR_VERSION "99" #define OFPROJECTGENERATOR_PATCH_VERSION "0" #define PG_VERSION (OFPROJECTGENERATOR_MAJOR_VERSION "." OFPROJECTGENERATOR_MINOR_VERSION "." OFPROJECTGENERATOR_PATCH_VERSION) diff --git a/commandLine/src/main.cpp b/commandLine/src/main.cpp index c264bb5b..2b520366 100644 --- a/commandLine/src/main.cpp +++ b/commandLine/src/main.cpp @@ -513,6 +513,7 @@ int main(int argc, char ** argv) { if (options[TEMPLATE].arg != NULL) { string templateString(options[TEMPLATE].arg); templateName = templateString; + ofLogNotice() << "{ \"Template\": \"" << templateName << "\" }"; } } @@ -520,6 +521,7 @@ int main(int argc, char ** argv) { if (options[PLATFORMS].arg != NULL) { string platformString(options[PLATFORMS].arg); addPlatforms(platformString); + ofLogNotice() << "{ \"Platform\": \"" << platformString << "\" }"; } } @@ -581,9 +583,9 @@ int main(int argc, char ** argv) { // try to get the OF_PATH as an environt variable - if (bVerbose) { + //if (bVerbose) { ofSetLogLevel(OF_LOG_VERBOSE); - } + //} if (projectName == "") { printHelp(); @@ -678,25 +680,22 @@ int main(int argc, char ** argv) { } } else { if (mode == PG_MODE_UPDATE && !isGoodProjectPath(projectPath)) { - ofLogError() << "there is no src folder in this project path to update, maybe use create instead? (or use force to force updating)"; + messageError("there is no src folder in this project path to update, maybe use create instead? (or use force to force updating"); } else { - nProjectsCreated += 1; - + ofLogNotice() << "setting OF path to: [" << ofPath << "]"; if (busingEnvVar) { ofLogNotice() << "from PG_OF_PATH environment variable"; } else { ofLogNotice() << "from -o option"; } - - for (auto & t : targets) { consoleSpace(); ofLogNotice() << "-----------------------------------------------"; ofLogNotice() << "target platform is: [" << t << "]"; // ofLogNotice() << "project path is: [" << projectPath << "]"; if (templateName != "") { - ofLogNotice() << "using additional template " << templateName; + ofLogNotice() << "using additional template [" << templateName << "]"; } ofLogVerbose() << "setting up new project " << projectPath; @@ -706,7 +705,7 @@ int main(int argc, char ** argv) { ofLogNotice() << "project updated! "; } else { if (!bDryRun) { -// ofLogNotice() << "project path is: [" << projectPath << "]"; + ofLogNotice() << "project path is: [" << projectPath << "]"; auto project = getTargetProject(t); project->create(projectPath, templateName); if(bAddonsPassedIn){ @@ -726,6 +725,7 @@ int main(int argc, char ** argv) { project->save(); } ofLogNotice() << "project created! "; + nProjectsCreated += 1; } ofLogNotice() << "-----------------------------------------------"; } @@ -734,12 +734,14 @@ int main(int argc, char ** argv) { consoleSpace(); float elapsedTime = ofGetElapsedTimef() - startTime; - if (nProjectsCreated > 0) std::cout << nProjectsCreated << " project created "; - if (nProjectsUpdated == 1) std::cout << nProjectsUpdated << " project updated "; + if (nProjectsCreated > 0) std::cout << nProjectsCreated << " project created at " << projectPath; + if (nProjectsUpdated == 1) std::cout << nProjectsUpdated << " project updated at " << projectPath; if (nProjectsUpdated > 1) std::cout << nProjectsUpdated << " projects updated "; ofLogNotice() << "in " << elapsedTime << " seconds" << std::endl; consoleSpace(); - + std::cout << "{ \"inSeconds\": \"" << elapsedTime << "\" }" << std::endl; + std::cout << "{ \"status\": \"" << "EXIT_OK" << "\" }"; messageReturn("status", "EXIT_OK"); + return EXIT_OK; } diff --git a/commandLine/src/projects/baseProject.cpp b/commandLine/src/projects/baseProject.cpp index dc4eee0b..5ef81c66 100644 --- a/commandLine/src/projects/baseProject.cpp +++ b/commandLine/src/projects/baseProject.cpp @@ -22,7 +22,7 @@ baseProject::baseProject(const string & _target) : target(_target) { bLoaded = false; } -fs::path baseProject::getPlatformTemplateDir() { +fs::path baseProject::getPlatformTemplateDir(std::string templateDir) { string folder { target }; if ( target == "msys2" || target == "linux" @@ -33,12 +33,10 @@ fs::path baseProject::getPlatformTemplateDir() { ) { folder = "vscode"; } - -// if ( target == "qtcreator" ) { -// return getOFRoot() -// } - - return getOFRoot() / templatesFolder / folder; + if (templateDir != "") { + folder = templateDir; + } + return fs::weakly_canonical(getOFRoot() / templatesFolder / folder); } @@ -139,26 +137,25 @@ bool baseProject::create(const fs::path & _path, string templateName){ addons.clear(); extSrcPaths.clear(); - - templatePath = normalizePath(getPlatformTemplateDir()); + auto pathTemplate = getPlatformTemplateDir(templateName); + if (fs::exists(pathTemplate)) { + templatePath = normalizePath(pathTemplate); + } else { + ofLogError() << "templatePath does not exist: [" << templatePath << "]"; + } + if (fs::exists(templatePath)) { + templatePath = normalizePath(pathTemplate); + } else { + ofLogError() << "templatePath does not exist: [" << templatePath << "]"; + } ofLogNotice() << "templatePath: [" << templatePath << "]"; auto projectPath = fs::canonical(fs::current_path() / path); - projectDir = path; projectPath = normalizePath(projectPath); ofLogNotice() << "projectPath: [" << projectPath << "]"; - projectName = projectPath.filename().string(); - - // we had this in some projects. if we decide to keep this is the place - // if (!fs::exists(projectDir)) { - // fs::create_directory(projectDir); - // } bool bDoesSrcDirExist = false; - - // it can be only "src" fs::path projectSrc { projectDir / "src" }; - if (fs::exists(projectSrc) && fs::is_directory(projectSrc)) { bDoesSrcDirExist = true; } else { @@ -175,18 +172,14 @@ bool baseProject::create(const fs::path & _path, string templateName){ } } bool ret = createProjectFile(); - if(!ret) return false; - -// cout << "after return : " << templateName << endl; - if(!empty(templateName)){ -// cout << "templateName not empty " << templateName << endl; -// return getOFRoot() / templatesFolder / target; - + if (!ret) { + ofLogError() << "{ \"errorMessage\": \"" << "baseProject::create createProjectFile failed" << "\", \"status:\" \"EXIT_FAILURE\" }"; + return false; + } + if (templateName != "" && !empty(templateName)) { fs::path templateDir = getOFRoot() / templatesFolder / templateName; - ofLogNotice() << "templateDir: [" << templateDir << "]"; templateDir = normalizePath(templateDir); -// alert("templateDir " + templateDir.string()); - + ofLogNotice() << "templateDir: [" << templateDir << "]"; auto templateConfig = parseTemplate(templateDir); if(templateConfig){ recursiveTemplateCopy(templateDir, projectDir); @@ -208,13 +201,13 @@ bool baseProject::create(const fs::path & _path, string templateName){ ofLogWarning() << "Cannot find " << templateName << " using platform template only"; } } - ret = loadProjectFile(); - - if(!ret) return false; + if (!ret) { + ofLogError() << "{ \"errorMessage\": \"" << "baseProject::create loadProjectFile failed" << "\", \"status:\" \"EXIT_FAILURE\" }"; + return false; + } parseConfigMake(); - if (bDoesSrcDirExist){ vector fileNames; @@ -548,7 +541,6 @@ void baseProject::addAddon(ofAddon & addon){ unless there is one addon added which needs another, and it needs another. */ -// alert("---> dependencies"); for (auto & d : addon.dependencies) { bool found = false; for (auto & a : addons) { @@ -564,12 +556,8 @@ void baseProject::addAddon(ofAddon & addon){ ofLogVerbose() << "trying to add duplicated addon dependency! skipping: " << d; } } -// alert("---> dependencies"); addons.emplace_back(addon); - - //ofLogVerbose("baseProject") << "libs in addAddon " << addon.libs.size(); - addAddonBegin(addon); addAddonDllsToCopy(addon); diff --git a/commandLine/src/projects/baseProject.h b/commandLine/src/projects/baseProject.h index 4f4cd18a..83c0c963 100644 --- a/commandLine/src/projects/baseProject.h +++ b/commandLine/src/projects/baseProject.h @@ -82,7 +82,7 @@ class baseProject { std::vector