diff --git a/SceneSwitcher.cpp b/SceneSwitcher.cpp index bcf56dde..1269ec57 100644 --- a/SceneSwitcher.cpp +++ b/SceneSwitcher.cpp @@ -1,12 +1,9 @@ -#pragma once - -#include "stdafx.h" #include "switcher.h" #include -#include #include #include #include +#include using namespace std; @@ -22,22 +19,18 @@ obs_data_array_t *optionsHotkeyData; //path to config folder where to save the hotkeybinding (probably later the settings file) string configPath; - +//save settings (the only hotkey for now) void saveKeybinding(string name, obs_data_array_t *hotkeyData) { name.append(".txt"); - //save settings (the only hotkey for now) - wstring stemp = wstring(configPath.begin(), configPath.end()); - LPCWSTR sw = stemp.c_str(); + //check if config dir exists - if (CreateDirectory(sw, NULL) || - ERROR_ALREADY_EXISTS == GetLastError()) - { + if (boost::filesystem::create_directories(configPath)){ //save hotkey data fstream file; file.open(obs_module_config_path(name.c_str()), fstream::out); //doesnt seem to work in obs_module_unload (hotkey data freed already (<- Jim)) //hotkeyData = obs_hotkey_save(pauseHotkeyId); - int num = obs_data_array_count(hotkeyData); + size_t num = obs_data_array_count(hotkeyData); for (int i = 0; i < num; i++) { string temp = obs_data_get_json(obs_data_array_item(hotkeyData, i)); file << temp; diff --git a/settings.cpp b/settings.cpp index 8edebf23..c0f2fa7f 100644 --- a/settings.cpp +++ b/settings.cpp @@ -1,16 +1,9 @@ -#pragma once - -#include "stdafx.h" #include #include #include #include #include #include -#include -#include -#pragma comment(lib,"shlwapi.lib") -#include "shlobj.h" #include "settings.h" diff --git a/settings.h b/settings.h index 19261832..50a76175 100644 --- a/settings.h +++ b/settings.h @@ -1,5 +1,6 @@ #pragma once #include +#include using namespace std; class Settings { @@ -9,6 +10,6 @@ public: map getMap(); string getSettingsFilePath(); private: - string settingsFilePath = "..\\..\\data\\obs-plugins\\SceneSwitcher\\settings.txt"; + string settingsFilePath = "/Users/Till/Desktop/SceneSwitcher/settings.txt"; void addToMap(string, string); }; diff --git a/switcher.cpp b/switcher.cpp index 8cdeabdc..be7c71dd 100644 --- a/switcher.cpp +++ b/switcher.cpp @@ -1,15 +1,17 @@ -#pragma once -#include "stdafx.h" #include "settings.h" #include -#include #include #include #include #include #include #include "switcher.h" - +#ifdef __WINDOWS__ + #include +#endif +#ifdef __APPLE__ + #include +#endif using namespace std; //scene switching is done in here @@ -76,6 +78,7 @@ void Switcher::switcherThreadFunc() { } } +#ifdef __WINDOWS__ void Switcher::firstLoad() { settings.load(); settingsMap = settings.getMap(); @@ -88,6 +91,39 @@ void Switcher::firstLoad() { MessageBoxA(0, message.c_str(), "Scene Switcher", 0); } } +#endif + +#ifdef __APPLE__ +void Switcher::firstLoad() { + settings.load(); + settingsMap = settings.getMap(); + if (settingsMap.find("Disable Start Message") == settingsMap.end() || settingsMap.find("Disable Start Message")->second != "Yes") { + string message = "The following settings were found for Scene Switcher:\n"; + for (auto it = settingsMap.cbegin(); it != settingsMap.cend(); ++it) + { + message += (it->first) + " -> " + it->second + "\n"; + } + SInt32 nRes = 0; + CFUserNotificationRef pDlg = NULL; + const void* keys[] = { kCFUserNotificationAlertHeaderKey, + kCFUserNotificationAlertMessageKey }; + const void* vals[] = { + CFSTR("Test Foundation Message Box"), + CFStringCreateWithCString(kCFAllocatorDefault,message.c_str(),kCFStringEncodingMacRoman) + }; + + CFDictionaryRef dict = CFDictionaryCreate(0, keys, vals, + sizeof(keys)/sizeof(*keys), + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + + pDlg = CFUserNotificationCreate(kCFAllocatorDefault, 0, + kCFUserNotificationPlainAlertLevel, + &nRes, dict); + } +} +#endif + //load the settings needed to start the thread void Switcher::load() { @@ -103,6 +139,7 @@ void Switcher::start() } //checks if active window is in fullscreen +#ifdef __WINDOWS__ bool Switcher::isWindowFullscreen() { RECT appBounds; RECT rc; @@ -120,8 +157,17 @@ bool Switcher::isWindowFullscreen() { } return false; } +#endif + +#ifdef __APPLE__ +bool Switcher::isWindowFullscreen() { + //TODO: implement the MAC OS version + return false; +} +#endif //reads the title of the currently active window +#ifdef __WINDOWS__ string Switcher::GetActiveWindowTitle() { char wnd_title[256]; @@ -130,6 +176,20 @@ string Switcher::GetActiveWindowTitle() GetWindowTextA(hwnd, wnd_title, sizeof(wnd_title)); return wnd_title; } +#endif + +#ifdef __APPLE__ +string Switcher::GetActiveWindowTitle() +{ + string cmd = "osascript -e 'tell application \"System Events\"' -e 'set frontApp to name of first application process whose frontmost is true' -e 'end tell'"; + char buffer[256]; + FILE * f = popen(cmd.c_str(), "r"); + fgets(buffer, 255, f); + pclose(f); + return buffer; +} +#endif + //tell the thread to stop void Switcher::stop() { @@ -141,7 +201,7 @@ void Switcher::stop() { string Switcher::getSettingsFilePath() { - return settings.getSettingsFilePath(); + return settings.getSettingsFilePath();; } bool Switcher::getIsRunning() diff --git a/switcher.h b/switcher.h index 77d53e03..4a7dff70 100644 --- a/switcher.h +++ b/switcher.h @@ -1,7 +1,6 @@ #pragma once #include "settings.h" #include -#include #include using namespace std;