2024-05-21 16:55:15 +02:00
|
|
|
|
#include "pch.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
2024-06-12 19:31:43 +02:00
|
|
|
|
#include <projects-common/Data.h>
|
2024-05-21 16:55:15 +02:00
|
|
|
|
|
2024-06-12 19:31:43 +02:00
|
|
|
|
#include <AppLauncher.h>
|
2024-05-21 16:55:15 +02:00
|
|
|
|
|
2024-06-12 21:45:39 +02:00
|
|
|
|
#include <common/utils/logger_helper.h>
|
|
|
|
|
|
#include <common/utils/UnhandledExceptionHandler.h>
|
|
|
|
|
|
|
|
|
|
|
|
const std::wstring moduleName = L"Projects\\ProjectsLauncher";
|
|
|
|
|
|
const std::wstring internalPath = L"";
|
|
|
|
|
|
|
|
|
|
|
|
int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hInstPrev, LPSTR cmdline, int cmdshow)
|
2024-05-21 16:55:15 +02:00
|
|
|
|
{
|
2024-06-12 21:45:39 +02:00
|
|
|
|
LoggerHelpers::init_logger(moduleName, internalPath, LogSettings::projectsLauncherLoggerName);
|
|
|
|
|
|
InitUnhandledExceptionHandler();
|
|
|
|
|
|
|
2024-05-21 16:55:15 +02:00
|
|
|
|
// read projects
|
|
|
|
|
|
std::vector<Project> projects;
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
auto savedProjectsJson = json::from_file(JsonUtils::ProjectsFile());
|
|
|
|
|
|
if (savedProjectsJson.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
auto savedProjects = JsonUtils::ProjectsListJSON::FromJson(savedProjectsJson.value());
|
|
|
|
|
|
if (savedProjects.has_value())
|
|
|
|
|
|
{
|
|
|
|
|
|
projects = savedProjects.value();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-06-12 21:45:39 +02:00
|
|
|
|
catch (std::exception ex)
|
2024-05-21 16:55:15 +02:00
|
|
|
|
{
|
2024-06-12 21:45:39 +02:00
|
|
|
|
Logger::error("Exception on reading projects: {}", ex.what());
|
2024-05-21 16:55:15 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (projects.empty())
|
|
|
|
|
|
{
|
2024-06-12 21:45:39 +02:00
|
|
|
|
Logger::warn("Projects file is empty");
|
2024-05-21 16:55:15 +02:00
|
|
|
|
return 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Project projectToLaunch = projects[0];
|
|
|
|
|
|
|
2024-06-12 21:45:39 +02:00
|
|
|
|
std::string idStr(cmdline);
|
|
|
|
|
|
std::wstring id(idStr.begin(), idStr.end());
|
|
|
|
|
|
Logger::info(L"command line: {}", id);
|
|
|
|
|
|
if (!id.empty())
|
2024-05-21 16:55:15 +02:00
|
|
|
|
{
|
|
|
|
|
|
for (const auto& proj : projects)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (proj.id == id)
|
|
|
|
|
|
{
|
|
|
|
|
|
projectToLaunch = proj;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-06-12 21:45:39 +02:00
|
|
|
|
Logger::info(L"Launch Project {} : {}", projectToLaunch.name, projectToLaunch.id);
|
|
|
|
|
|
|
2024-05-21 16:55:15 +02:00
|
|
|
|
// launch apps
|
2024-06-11 15:43:42 +02:00
|
|
|
|
Launch(projectToLaunch);
|
|
|
|
|
|
|
2024-05-21 16:55:15 +02:00
|
|
|
|
// update last-launched time
|
|
|
|
|
|
time_t launchedTime = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
|
|
|
|
|
projectToLaunch.lastLaunchedTime = launchedTime;
|
|
|
|
|
|
for (int i = 0; i < projects.size(); i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (projects[i].id == projectToLaunch.id)
|
|
|
|
|
|
{
|
|
|
|
|
|
projects[i] = projectToLaunch;
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
json::to_file(JsonUtils::ProjectsFile(), JsonUtils::ProjectsListJSON::ToJson(projects));
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
}
|