Skip to content

Commit

Permalink
Default settings populating
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenmc committed Jul 19, 2024
1 parent eae2e0c commit d7f1be1
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/LaunchTree/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ namespace LaunchTree
void App::OnSettingsCommand()
{
OutputDebugStringW(L"Settings invoked");
ShellExecuteW(nullptr, L"explore",
m_settingsManager.GetSettingsFilePath().parent_path().wstring().data(),
nullptr, nullptr, SW_SHOWNORMAL);
}

void App::OnExitCommand()
Expand Down
1 change: 0 additions & 1 deletion src/LaunchTree/Models/ShellExecuteTreeNode.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <pch.h>
#include "ShellExecuteTreeNode.h"
#include <shellapi.h>

namespace LaunchTree::Models
{
Expand Down
47 changes: 45 additions & 2 deletions src/LaunchTree/Settings/SettingsManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@
namespace
{
constexpr std::string_view c_settingsFileName{ "settings.json" };
constexpr std::string_view c_defaultSettingsFileContents{ R"({
"commandTree": [
{
"name": "Tools",
"key": "T",
"children": [
{
"name": "Calculator",
"key": "C",
"type": "shellExecute",
"executeFile": "calc.exe",
"executeParameters": ""
},
{
"name": "Notepad",
"key": "N",
"type": "shellExecute",
"executeFile": "notepad.exe",
"executeParameters": ""
}
]
},
{
"name": "Edge",
"key": "E",
"type": "shellExecute",
"executeFile": "msedge.exe",
"executeParameters": ""
}
]
})" };

std::filesystem::path GetSettingsFilePath()
{
Expand Down Expand Up @@ -68,8 +99,20 @@ namespace

namespace LaunchTree::Settings
{
SettingsManager::SettingsManager() : m_settingsFilePath{ GetSettingsFilePath() }
{ }
SettingsManager::SettingsManager() : m_settingsFilePath{ ::GetSettingsFilePath() }
{
if (!std::filesystem::exists(m_settingsFilePath))
{
std::ofstream defaultSettingsFile{ m_settingsFilePath };
defaultSettingsFile << c_defaultSettingsFileContents;
defaultSettingsFile.close();
}
}

std::filesystem::path SettingsManager::GetSettingsFilePath()
{
return m_settingsFilePath;
}

std::unique_ptr<Models::TreeNode> SettingsManager::GetTree()
{
Expand Down
1 change: 1 addition & 0 deletions src/LaunchTree/Settings/SettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace LaunchTree::Settings
struct SettingsManager
{
SettingsManager();
std::filesystem::path GetSettingsFilePath();
std::unique_ptr<Models::TreeNode> GetTree();

private:
Expand Down
1 change: 0 additions & 1 deletion src/LaunchTree/View/TrayIcon.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <pch.h>
#include "TrayIcon.h"
#include <shellapi.h>

namespace
{
Expand Down
1 change: 1 addition & 0 deletions src/LaunchTree/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Windows API
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include <shellapi.h>

// C++/WinRT
#include <Unknwn.h>
Expand Down

0 comments on commit d7f1be1

Please sign in to comment.