Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 32 additions & 55 deletions frontend/OBSApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

#include <QCheckBox>
#include <QDesktopServices>
#include <QDateTime>
#if defined(_WIN32) || defined(ENABLE_SPARKLE_UPDATER)
#include <QFile>
#endif
Expand Down Expand Up @@ -331,10 +332,8 @@ bool OBSApp::InitGlobalConfigDefaults()

bool OBSApp::InitGlobalLocationDefaults()
{
char path[512];

int len = GetAppConfigPath(path, sizeof(path), nullptr);
if (len <= 0) {
BPtr<char> path = GetAppConfigPathPtr(nullptr);
if (!path || !*path.Get()) {
OBSErrorBox(NULL, "Unable to get global configuration path.");
return false;
}
Expand Down Expand Up @@ -407,49 +406,37 @@ static bool do_mkdir(const char *path)

static bool MakeUserDirs()
{
char path[512];
BPtr<char> path;

if (GetAppConfigPath(path, sizeof(path), "obs-studio/basic") <= 0) {
return false;
}
if (!do_mkdir(path)) {
path = GetAppConfigPathPtr("obs-studio/basic");
if (!path || !*path.Get() || !do_mkdir(path)) {
return false;
}

if (GetAppConfigPath(path, sizeof(path), "obs-studio/logs") <= 0) {
return false;
}
if (!do_mkdir(path)) {
path = GetAppConfigPathPtr("obs-studio/logs");
if (!path || !*path.Get() || !do_mkdir(path)) {
return false;
}

if (GetAppConfigPath(path, sizeof(path), "obs-studio/profiler_data") <= 0) {
return false;
}
if (!do_mkdir(path)) {
path = GetAppConfigPathPtr("obs-studio/profiler_data");
if (!path || !*path.Get() || !do_mkdir(path)) {
return false;
}

#ifdef _WIN32
if (GetAppConfigPath(path, sizeof(path), "obs-studio/crashes") <= 0) {
return false;
}
if (!do_mkdir(path)) {
path = GetAppConfigPathPtr("obs-studio/crashes");
if (!path || !*path.Get() || !do_mkdir(path)) {
return false;
}
#endif

if (GetAppConfigPath(path, sizeof(path), "obs-studio/updates") <= 0) {
return false;
}
if (!do_mkdir(path)) {
path = GetAppConfigPathPtr("obs-studio/updates");
if (!path || !*path.Get() || !do_mkdir(path)) {
return false;
}

if (GetAppConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0) {
return false;
}
if (!do_mkdir(path)) {
path = GetAppConfigPathPtr("obs-studio/plugin_config");
if (!path || !*path.Get() || !do_mkdir(path)) {
return false;
}

Expand Down Expand Up @@ -537,10 +524,8 @@ bool OBSApp::UpdatePre22MultiviewLayout(const char *layout)

bool OBSApp::InitGlobalConfig()
{
char path[512];

int len = GetAppConfigPath(path, sizeof(path), "obs-studio/global.ini");
if (len <= 0) {
BPtr<char> path = GetAppConfigPathPtr("obs-studio/global.ini");
if (!path || !*path.Get()) {
return false;
}

Expand Down Expand Up @@ -676,10 +661,8 @@ static constexpr string_view OBSUserIniPath = "/obs-studio/user.ini";

bool OBSApp::MigrateGlobalSettings()
{
char path[512];

int len = GetAppConfigPath(path, sizeof(path), nullptr);
if (len <= 0) {
BPtr<char> path = GetAppConfigPathPtr(nullptr);
if (!path || !*path.Get()) {
OBSErrorBox(nullptr, "Unable to get global configuration path.");
return false;
}
Expand Down Expand Up @@ -970,13 +953,13 @@ OBSApp::~OBSApp()

static void move_basic_to_profiles(void)
{
char path[512];
BPtr<char> path = GetAppConfigPathPtr("obs-studio/basic");

if (GetAppConfigPath(path, 512, "obs-studio/basic") <= 0) {
if (!path || !*path.Get()) {
return;
}

const std::filesystem::path basicPath = std::filesystem::u8path(path);
const std::filesystem::path basicPath = std::filesystem::u8path(path.Get());

if (!std::filesystem::exists(basicPath)) {
return;
Expand Down Expand Up @@ -1034,13 +1017,13 @@ static void move_basic_to_profiles(void)

static void move_basic_to_scene_collections(void)
{
char path[512];
BPtr<char> path = GetAppConfigPathPtr("obs-studio/basic");

if (GetAppConfigPath(path, 512, "obs-studio/basic") <= 0) {
if (!path || !*path.Get()) {
return;
}

const std::filesystem::path basicPath = std::filesystem::u8path(path);
const std::filesystem::path basicPath = std::filesystem::u8path(path.Get());

if (!std::filesystem::exists(basicPath)) {
return;
Expand Down Expand Up @@ -1169,9 +1152,9 @@ const char *OBSApp::GetRenderModule() const

static bool StartupOBS(const char *locale, profiler_name_store_t *store)
{
char path[512];
BPtr<char> path = GetAppConfigPathPtr("obs-studio/plugin_config");

if (GetAppConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0) {
if (!path || !*path.Get()) {
return false;
}

Expand Down Expand Up @@ -1515,16 +1498,10 @@ bool OBSApp::notify(QObject *receiver, QEvent *e)

string GenerateTimeDateFilename(const char *extension, bool noSpace)
{
time_t now = time(0);
char file[256] = {};
struct tm *cur_time;

cur_time = localtime(&now);
snprintf(file, sizeof(file), "%d-%02d-%02d%c%02d-%02d-%02d.%s", cur_time->tm_year + 1900, cur_time->tm_mon + 1,
cur_time->tm_mday, noSpace ? '_' : ' ', cur_time->tm_hour, cur_time->tm_min, cur_time->tm_sec,
extension);
QString format = noSpace ? "yyyy-MM-dd_hh-mm-ss" : "yyyy-MM-dd hh-mm-ss";
QString filename = QDateTime::currentDateTime().toString(format) + "." + extension;

return string(file);
return filename.toStdString();
}

string GenerateSpecifiedFilename(const char *extension, bool noSpace, const char *format)
Expand Down Expand Up @@ -1743,7 +1720,7 @@ char *GetAppConfigPathPtr(const char *name)
{
#if ALLOW_PORTABLE_MODE
if (portable_mode) {
char path[512];
char path[MAX_PATH_UTF8];

if (snprintf(path, sizeof(path), CONFIG_PATH "/%s", name) > 0) {
return bstrdup(path);
Expand Down
12 changes: 6 additions & 6 deletions frontend/OBSApp_Themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1000,9 +1000,9 @@ bool OBSApp::SetTheme(const QString &name)
filename += ".out";

filesystem::path debugOut;
char configPath[512];
if (GetAppConfigPath(configPath, sizeof(configPath), filename.c_str())) {
debugOut = absolute(filesystem::u8path(configPath));
BPtr<char> configPath = GetAppConfigPathPtr(filename.c_str());
if (configPath && *configPath.Get()) {
debugOut = absolute(filesystem::u8path(configPath.Get()));
filesystem::create_directories(debugOut.parent_path());
}

Expand Down Expand Up @@ -1063,9 +1063,9 @@ bool OBSApp::InitTheme()
QDir::addSearchPath("theme", absolute(installSearchDir));
}

char userDir[512];
if (GetAppConfigPath(userDir, sizeof(userDir), "obs-studio/themes")) {
auto configSearchDir = filesystem::u8path(userDir);
BPtr<char> userDir = GetAppConfigPathPtr("obs-studio/themes");
if (userDir && *userDir.Get()) {
auto configSearchDir = filesystem::u8path(userDir.Get());
QDir::addSearchPath("theme", absolute(configSearchDir));
}

Expand Down
10 changes: 5 additions & 5 deletions frontend/dialogs/OBSLogViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ void OBSLogViewer::on_showStartup_clicked(bool checked)

void OBSLogViewer::InitLog()
{
char logDir[512];
BPtr<char> logDir = GetAppConfigPathPtr("obs-studio/logs");
std::string path;

if (GetAppConfigPath(logDir, sizeof(logDir), "obs-studio/logs")) {
if (logDir.Get()) {
path += logDir;
path += "/";
path += App()->GetCurrentLog();
Expand Down Expand Up @@ -114,14 +114,14 @@ void OBSLogViewer::AddLine(int type, const QString &str)

void OBSLogViewer::on_openButton_clicked()
{
char logDir[512];
if (GetAppConfigPath(logDir, sizeof(logDir), "obs-studio/logs") <= 0) {
BPtr<char> logDir = GetAppConfigPathPtr("obs-studio/logs");
if (!logDir || !*logDir.Get()) {
return;
}

const char *log = App()->GetCurrentLog();

std::string path = logDir;
std::string path(logDir);
path += "/";
path += log;

Expand Down
7 changes: 3 additions & 4 deletions frontend/importers/classic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -548,9 +548,8 @@ OBSImporterFiles ClassicImporter::FindFiles()
OBSImporterFiles res;

#ifdef _WIN32
char dst[512];
int found = os_get_config_path(dst, 512, "OBS\\sceneCollection\\");
if (found == -1) {
BPtr<char> dst = os_get_config_path_ptr("OBS\\sceneCollection\\");
if (!dst) {
return res;
}

Expand All @@ -564,7 +563,7 @@ OBSImporterFiles ClassicImporter::FindFiles()
string name = ent->d_name;
size_t pos = name.find(".xconfig");
if (pos != -1 && pos == name.length() - 8) {
string path = dst + name;
string path = dst.Get() + name;
res.push_back(path);
}
}
Expand Down
8 changes: 3 additions & 5 deletions frontend/importers/sl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,9 @@ OBSImporterFiles SLImporter::FindFiles()
{
OBSImporterFiles res;
#if defined(_WIN32) || defined(__APPLE__)
char dst[512];
BPtr<char> dst = os_get_config_path_ptr("slobs-client/SceneCollections/");

int found = os_get_config_path(dst, 512, "slobs-client/SceneCollections/");

if (found == -1) {
if (!dst) {
return res;
}

Expand All @@ -515,7 +513,7 @@ OBSImporterFiles SLImporter::FindFiles()
size_t pos = name.find_last_of(".json");
size_t end_pos = name.size() - 1;
if (pos != string::npos && pos == end_pos) {
string str = dst + name;
string str = dst.Get() + name;
res.push_back(str);
}
}
Expand Down
14 changes: 5 additions & 9 deletions frontend/importers/studio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,23 @@ void TranslateOSStudio(Json &res)

static string CheckPath(const string &path, const string &rootDir)
{
char root[512];
*root = 0;
size_t rootLen = os_get_abs_path(rootDir.c_str(), root, sizeof(root));
BPtr<char> root = os_get_abs_path_ptr(rootDir.c_str());

char absPath[512];
*absPath = 0;
size_t len = os_get_abs_path((rootDir + path).c_str(), absPath, sizeof(absPath));
BPtr<char> absPath = os_get_abs_path_ptr((rootDir + path).c_str());

if (len == 0) {
if (!absPath || !*absPath.Get()) {
return path;
}

if (strstr(absPath, root) != absPath) {
return path;
}

if (*(absPath + rootLen) != QDir::separator().toLatin1()) {
if (*(absPath + strlen(root)) != QDir::separator().toLatin1()) {
return path;
}

return absPath;
return string(absPath);
}

void TranslatePaths(Json &res, const string &rootDir)
Expand Down
8 changes: 3 additions & 5 deletions frontend/importers/xsplit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,8 @@ OBSImporterFiles XSplitImporter::FindFiles()
{
OBSImporterFiles res;
#ifdef _WIN32
char dst[512];
int found = os_get_program_data_path(dst, 512, "SplitMediaLabs\\XSplit\\Presentation2.0\\");

if (found == -1) {
BPtr<char> dst = os_get_program_data_path_ptr("SplitMediaLabs\\XSplit\\Presentation2.0\\");
if (!dst) {
return res;
}

Expand All @@ -521,7 +519,7 @@ OBSImporterFiles XSplitImporter::FindFiles()
}

if (name == "Placements.bpres") {
string str = dst + name;
string str = dst.Get() + name;
res.push_back(str);

break;
Expand Down
3 changes: 2 additions & 1 deletion frontend/updater/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,8 @@ static bool Update(wchar_t *cmdLine)
continue;
}

char outputPath[MAX_PATH];
// Double buffer size to fit filename from wide char API
char outputPath[MAX_PATH * 2];
if (!WideToUTF8Buf(outputPath, update.outputPath.c_str())) {
continue;
}
Expand Down
13 changes: 5 additions & 8 deletions frontend/utility/platform-windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ bool GetDataFilePath(const char *data, string &output)
string GetDefaultVideoSavePath()
{
wchar_t path_utf16[MAX_PATH];
char path_utf8[MAX_PATH] = {};
BPtr<char> path_utf8;

SHGetFolderPathW(NULL, CSIDL_MYVIDEO, NULL, SHGFP_TYPE_CURRENT, path_utf16);

os_wcs_to_utf8(path_utf16, wcslen(path_utf16), path_utf8, MAX_PATH);
os_wcs_to_utf8_ptr(path_utf16, wcslen(path_utf16), &path_utf8);
return string(path_utf8);
}

Expand Down Expand Up @@ -307,12 +307,9 @@ RunOnceMutex CheckIfAlreadyRunning(bool &already_running)
if (!portable_mode) {
name = "OBSStudioCore";
} else {
char path[500];
char absPath[512];
*path = 0;
*absPath = 0;
GetAppConfigPath(path, sizeof(path), "");
os_get_abs_path(path, absPath, sizeof(absPath));
BPtr<char> path = GetAppConfigPathPtr("");
BPtr<char> absPath = os_get_abs_path_ptr(path);

name = "OBSStudioPortable";
name += absPath;
}
Expand Down
Loading
Loading