obs-app.cpp 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462
  1. /******************************************************************************
  2. Copyright (C) 2013 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include <time.h>
  15. #include <stdio.h>
  16. #include <wchar.h>
  17. #include <chrono>
  18. #include <ratio>
  19. #include <sstream>
  20. #include <mutex>
  21. #include <util/bmem.h>
  22. #include <util/dstr.h>
  23. #include <util/platform.h>
  24. #include <util/profiler.hpp>
  25. #include <obs-config.h>
  26. #include <obs.hpp>
  27. #include <QProxyStyle>
  28. #include "qt-wrappers.hpp"
  29. #include "obs-app.hpp"
  30. #include "window-basic-main.hpp"
  31. #include "window-basic-settings.hpp"
  32. #include "window-license-agreement.hpp"
  33. #include "crash-report.hpp"
  34. #include "platform.hpp"
  35. #include <fstream>
  36. #include <curl/curl.h>
  37. #ifdef _WIN32
  38. #include <windows.h>
  39. #else
  40. #include <signal.h>
  41. #endif
  42. using namespace std;
  43. static log_handler_t def_log_handler;
  44. static string currentLogFile;
  45. static string lastLogFile;
  46. static bool portable_mode = false;
  47. QObject *CreateShortcutFilter()
  48. {
  49. return new OBSEventFilter([](QObject *obj, QEvent *event)
  50. {
  51. auto mouse_event = [](QMouseEvent &event)
  52. {
  53. obs_key_combination_t hotkey = {0, OBS_KEY_NONE};
  54. bool pressed = event.type() == QEvent::MouseButtonPress;
  55. switch (event.button()) {
  56. case Qt::NoButton:
  57. case Qt::LeftButton:
  58. case Qt::RightButton:
  59. case Qt::AllButtons:
  60. case Qt::MouseButtonMask:
  61. return false;
  62. case Qt::MidButton:
  63. hotkey.key = OBS_KEY_MOUSE3;
  64. break;
  65. #define MAP_BUTTON(i, j) case Qt::ExtraButton ## i: \
  66. hotkey.key = OBS_KEY_MOUSE ## j; break;
  67. MAP_BUTTON( 1, 4);
  68. MAP_BUTTON( 2, 5);
  69. MAP_BUTTON( 3, 6);
  70. MAP_BUTTON( 4, 7);
  71. MAP_BUTTON( 5, 8);
  72. MAP_BUTTON( 6, 9);
  73. MAP_BUTTON( 7, 10);
  74. MAP_BUTTON( 8, 11);
  75. MAP_BUTTON( 9, 12);
  76. MAP_BUTTON(10, 13);
  77. MAP_BUTTON(11, 14);
  78. MAP_BUTTON(12, 15);
  79. MAP_BUTTON(13, 16);
  80. MAP_BUTTON(14, 17);
  81. MAP_BUTTON(15, 18);
  82. MAP_BUTTON(16, 19);
  83. MAP_BUTTON(17, 20);
  84. MAP_BUTTON(18, 21);
  85. MAP_BUTTON(19, 22);
  86. MAP_BUTTON(20, 23);
  87. MAP_BUTTON(21, 24);
  88. MAP_BUTTON(22, 25);
  89. MAP_BUTTON(23, 26);
  90. MAP_BUTTON(24, 27);
  91. #undef MAP_BUTTON
  92. }
  93. hotkey.modifiers = TranslateQtKeyboardEventModifiers(
  94. event.modifiers());
  95. obs_hotkey_inject_event(hotkey, pressed);
  96. return true;
  97. };
  98. auto key_event = [&](QKeyEvent *event)
  99. {
  100. QDialog *dialog = qobject_cast<QDialog*>(obj);
  101. obs_key_combination_t hotkey = {0, OBS_KEY_NONE};
  102. bool pressed = event->type() == QEvent::KeyPress;
  103. switch (event->key()) {
  104. case Qt::Key_Shift:
  105. case Qt::Key_Control:
  106. case Qt::Key_Alt:
  107. case Qt::Key_Meta:
  108. break;
  109. #ifdef __APPLE__
  110. case Qt::Key_CapsLock:
  111. // kVK_CapsLock == 57
  112. hotkey.key = obs_key_from_virtual_key(57);
  113. pressed = true;
  114. break;
  115. #endif
  116. case Qt::Key_Enter:
  117. case Qt::Key_Escape:
  118. case Qt::Key_Return:
  119. if (dialog && pressed)
  120. return false;
  121. default:
  122. hotkey.key = obs_key_from_virtual_key(
  123. event->nativeVirtualKey());
  124. }
  125. hotkey.modifiers = TranslateQtKeyboardEventModifiers(
  126. event->modifiers());
  127. obs_hotkey_inject_event(hotkey, pressed);
  128. return true;
  129. };
  130. switch (event->type()) {
  131. case QEvent::MouseButtonPress:
  132. case QEvent::MouseButtonRelease:
  133. return mouse_event(*static_cast<QMouseEvent*>(event));
  134. /*case QEvent::MouseButtonDblClick:
  135. case QEvent::Wheel:*/
  136. case QEvent::KeyPress:
  137. case QEvent::KeyRelease:
  138. return key_event(static_cast<QKeyEvent*>(event));
  139. default:
  140. return false;
  141. }
  142. });
  143. }
  144. string CurrentTimeString()
  145. {
  146. using namespace std::chrono;
  147. struct tm tstruct;
  148. char buf[80];
  149. auto tp = system_clock::now();
  150. auto now = system_clock::to_time_t(tp);
  151. tstruct = *localtime(&now);
  152. size_t written = strftime(buf, sizeof(buf), "%X", &tstruct);
  153. if (ratio_less<system_clock::period, seconds::period>::value &&
  154. written && (sizeof(buf) - written) > 5) {
  155. auto tp_secs =
  156. time_point_cast<seconds>(tp);
  157. auto millis =
  158. duration_cast<milliseconds>(tp - tp_secs).count();
  159. snprintf(buf + written, sizeof(buf) - written, ".%03u",
  160. static_cast<unsigned>(millis));
  161. }
  162. return buf;
  163. }
  164. string CurrentDateTimeString()
  165. {
  166. time_t now = time(0);
  167. struct tm tstruct;
  168. char buf[80];
  169. tstruct = *localtime(&now);
  170. strftime(buf, sizeof(buf), "%Y-%m-%d, %X", &tstruct);
  171. return buf;
  172. }
  173. static inline void LogString(fstream &logFile, const char *timeString,
  174. char *str)
  175. {
  176. logFile << timeString << str << endl;
  177. }
  178. static inline void LogStringChunk(fstream &logFile, char *str)
  179. {
  180. char *nextLine = str;
  181. string timeString = CurrentTimeString();
  182. timeString += ": ";
  183. while (*nextLine) {
  184. char *nextLine = strchr(str, '\n');
  185. if (!nextLine)
  186. break;
  187. if (nextLine != str && nextLine[-1] == '\r') {
  188. nextLine[-1] = 0;
  189. } else {
  190. nextLine[0] = 0;
  191. }
  192. LogString(logFile, timeString.c_str(), str);
  193. nextLine++;
  194. str = nextLine;
  195. }
  196. LogString(logFile, timeString.c_str(), str);
  197. }
  198. #define MAX_REPEATED_LINES 30
  199. #define MAX_CHAR_VARIATION (255 * 3)
  200. static inline int sum_chars(const char *str)
  201. {
  202. int val = 0;
  203. for (; *str != 0; str++)
  204. val += *str;
  205. return val;
  206. }
  207. static inline bool too_many_repeated_entries(fstream &logFile, const char *msg,
  208. const char *output_str)
  209. {
  210. static mutex log_mutex;
  211. static const char *last_msg_ptr = nullptr;
  212. static int last_char_sum = 0;
  213. static char cmp_str[4096];
  214. static int rep_count = 0;
  215. int new_sum = sum_chars(output_str);
  216. lock_guard<mutex> guard(log_mutex);
  217. if (last_msg_ptr == msg) {
  218. int diff = std::abs(new_sum - last_char_sum);
  219. if (diff < MAX_CHAR_VARIATION) {
  220. return (rep_count++ >= MAX_REPEATED_LINES);
  221. }
  222. }
  223. if (rep_count > MAX_REPEATED_LINES) {
  224. logFile << CurrentTimeString() <<
  225. ": Last log entry repeated for " <<
  226. to_string(rep_count - MAX_REPEATED_LINES) <<
  227. " more lines" << endl;
  228. }
  229. last_msg_ptr = msg;
  230. strcpy(cmp_str, output_str);
  231. last_char_sum = new_sum;
  232. rep_count = 0;
  233. return false;
  234. }
  235. static void do_log(int log_level, const char *msg, va_list args, void *param)
  236. {
  237. fstream &logFile = *static_cast<fstream*>(param);
  238. char str[4096];
  239. #ifndef _WIN32
  240. va_list args2;
  241. va_copy(args2, args);
  242. #endif
  243. vsnprintf(str, 4095, msg, args);
  244. #ifdef _WIN32
  245. OutputDebugStringA(str);
  246. OutputDebugStringA("\n");
  247. #else
  248. def_log_handler(log_level, msg, args2, nullptr);
  249. #endif
  250. if (too_many_repeated_entries(logFile, msg, str))
  251. return;
  252. if (log_level <= LOG_INFO)
  253. LogStringChunk(logFile, str);
  254. #ifdef _WIN32
  255. if (log_level <= LOG_ERROR && IsDebuggerPresent())
  256. __debugbreak();
  257. #endif
  258. }
  259. #define DEFAULT_LANG "en-US"
  260. bool OBSApp::InitGlobalConfigDefaults()
  261. {
  262. config_set_default_string(globalConfig, "General", "Language",
  263. DEFAULT_LANG);
  264. config_set_default_uint(globalConfig, "General", "MaxLogs", 10);
  265. #if _WIN32
  266. config_set_default_string(globalConfig, "Video", "Renderer",
  267. "Direct3D 11");
  268. #else
  269. config_set_default_string(globalConfig, "Video", "Renderer", "OpenGL");
  270. #endif
  271. config_set_default_bool(globalConfig, "BasicWindow", "PreviewEnabled",
  272. true);
  273. return true;
  274. }
  275. static bool do_mkdir(const char *path)
  276. {
  277. if (os_mkdirs(path) == MKDIR_ERROR) {
  278. OBSErrorBox(NULL, "Failed to create directory %s", path);
  279. return false;
  280. }
  281. return true;
  282. }
  283. static bool MakeUserDirs()
  284. {
  285. char path[512];
  286. if (GetConfigPath(path, sizeof(path), "obs-studio/basic") <= 0)
  287. return false;
  288. if (!do_mkdir(path))
  289. return false;
  290. if (GetConfigPath(path, sizeof(path), "obs-studio/logs") <= 0)
  291. return false;
  292. if (!do_mkdir(path))
  293. return false;
  294. if (GetConfigPath(path, sizeof(path), "obs-studio/profiler_data") <= 0)
  295. return false;
  296. if (!do_mkdir(path))
  297. return false;
  298. #ifdef _WIN32
  299. if (GetConfigPath(path, sizeof(path), "obs-studio/crashes") <= 0)
  300. return false;
  301. if (!do_mkdir(path))
  302. return false;
  303. #endif
  304. if (GetConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0)
  305. return false;
  306. if (!do_mkdir(path))
  307. return false;
  308. return true;
  309. }
  310. static bool MakeUserProfileDirs()
  311. {
  312. char path[512];
  313. if (GetConfigPath(path, sizeof(path), "obs-studio/basic/profiles") <= 0)
  314. return false;
  315. if (!do_mkdir(path))
  316. return false;
  317. if (GetConfigPath(path, sizeof(path), "obs-studio/basic/scenes") <= 0)
  318. return false;
  319. if (!do_mkdir(path))
  320. return false;
  321. return true;
  322. }
  323. bool OBSApp::InitGlobalConfig()
  324. {
  325. char path[512];
  326. int len = GetConfigPath(path, sizeof(path),
  327. "obs-studio/global.ini");
  328. if (len <= 0) {
  329. return false;
  330. }
  331. int errorcode = globalConfig.Open(path, CONFIG_OPEN_ALWAYS);
  332. if (errorcode != CONFIG_SUCCESS) {
  333. OBSErrorBox(NULL, "Failed to open global.ini: %d", errorcode);
  334. return false;
  335. }
  336. return InitGlobalConfigDefaults();
  337. }
  338. bool OBSApp::InitLocale()
  339. {
  340. ProfileScope("OBSApp::InitLocale");
  341. const char *lang = config_get_string(globalConfig, "General",
  342. "Language");
  343. locale = lang;
  344. string englishPath;
  345. if (!GetDataFilePath("locale/" DEFAULT_LANG ".ini", englishPath)) {
  346. OBSErrorBox(NULL, "Failed to find locale/" DEFAULT_LANG ".ini");
  347. return false;
  348. }
  349. textLookup = text_lookup_create(englishPath.c_str());
  350. if (!textLookup) {
  351. OBSErrorBox(NULL, "Failed to create locale from file '%s'",
  352. englishPath.c_str());
  353. return false;
  354. }
  355. bool userLocale = config_has_user_value(globalConfig, "General",
  356. "Language");
  357. bool defaultLang = astrcmpi(lang, DEFAULT_LANG) == 0;
  358. if (userLocale && defaultLang)
  359. return true;
  360. if (!userLocale && defaultLang) {
  361. for (auto &locale_ : GetPreferredLocales()) {
  362. if (locale_ == lang)
  363. return true;
  364. stringstream file;
  365. file << "locale/" << locale_ << ".ini";
  366. string path;
  367. if (!GetDataFilePath(file.str().c_str(), path))
  368. continue;
  369. if (!text_lookup_add(textLookup, path.c_str()))
  370. continue;
  371. blog(LOG_INFO, "Using preferred locale '%s'",
  372. locale_.c_str());
  373. locale = locale_;
  374. return true;
  375. }
  376. return true;
  377. }
  378. stringstream file;
  379. file << "locale/" << lang << ".ini";
  380. string path;
  381. if (GetDataFilePath(file.str().c_str(), path)) {
  382. if (!text_lookup_add(textLookup, path.c_str()))
  383. blog(LOG_ERROR, "Failed to add locale file '%s'",
  384. path.c_str());
  385. } else {
  386. blog(LOG_ERROR, "Could not find locale file '%s'",
  387. file.str().c_str());
  388. }
  389. return true;
  390. }
  391. bool OBSApp::SetTheme(std::string name, std::string path)
  392. {
  393. theme = name;
  394. /* Check user dir first, then preinstalled themes. */
  395. if (path == "") {
  396. char userDir[512];
  397. name = "themes/" + name + ".qss";
  398. string temp = "obs-studio/" + name;
  399. int ret = GetConfigPath(userDir, sizeof(userDir),
  400. temp.c_str());
  401. if (ret > 0 && QFile::exists(userDir)) {
  402. path = string(userDir);
  403. } else if (!GetDataFilePath(name.c_str(), path)) {
  404. OBSErrorBox(NULL, "Failed to find %s.", name.c_str());
  405. return false;
  406. }
  407. }
  408. QString mpath = QString("file:///") + path.c_str();
  409. setStyleSheet(mpath);
  410. return true;
  411. }
  412. bool OBSApp::InitTheme()
  413. {
  414. const char *themeName = config_get_string(globalConfig, "General",
  415. "Theme");
  416. if (!themeName)
  417. themeName = "Default";
  418. stringstream t;
  419. t << themeName;
  420. return SetTheme(t.str());
  421. }
  422. OBSApp::OBSApp(int &argc, char **argv, profiler_name_store_t *store)
  423. : QApplication(argc, argv),
  424. profilerNameStore(store)
  425. {
  426. sleepInhibitor = os_inhibit_sleep_create("OBS Video/audio");
  427. }
  428. OBSApp::~OBSApp()
  429. {
  430. os_inhibit_sleep_set_active(sleepInhibitor, false);
  431. os_inhibit_sleep_destroy(sleepInhibitor);
  432. }
  433. static void move_basic_to_profiles(void)
  434. {
  435. char path[512];
  436. char new_path[512];
  437. os_glob_t *glob;
  438. /* if not first time use */
  439. if (GetConfigPath(path, 512, "obs-studio/basic") <= 0)
  440. return;
  441. if (!os_file_exists(path))
  442. return;
  443. /* if the profiles directory doesn't already exist */
  444. if (GetConfigPath(new_path, 512, "obs-studio/basic/profiles") <= 0)
  445. return;
  446. if (os_file_exists(new_path))
  447. return;
  448. if (os_mkdir(new_path) == MKDIR_ERROR)
  449. return;
  450. strcat(new_path, "/");
  451. strcat(new_path, Str("Untitled"));
  452. if (os_mkdir(new_path) == MKDIR_ERROR)
  453. return;
  454. strcat(path, "/*.*");
  455. if (os_glob(path, 0, &glob) != 0)
  456. return;
  457. strcpy(path, new_path);
  458. for (size_t i = 0; i < glob->gl_pathc; i++) {
  459. struct os_globent ent = glob->gl_pathv[i];
  460. char *file;
  461. if (ent.directory)
  462. continue;
  463. file = strrchr(ent.path, '/');
  464. if (!file++)
  465. continue;
  466. if (astrcmpi(file, "scenes.json") == 0)
  467. continue;
  468. strcpy(new_path, path);
  469. strcat(new_path, "/");
  470. strcat(new_path, file);
  471. os_rename(ent.path, new_path);
  472. }
  473. os_globfree(glob);
  474. }
  475. static void move_basic_to_scene_collections(void)
  476. {
  477. char path[512];
  478. char new_path[512];
  479. if (GetConfigPath(path, 512, "obs-studio/basic") <= 0)
  480. return;
  481. if (!os_file_exists(path))
  482. return;
  483. if (GetConfigPath(new_path, 512, "obs-studio/basic/scenes") <= 0)
  484. return;
  485. if (os_file_exists(new_path))
  486. return;
  487. if (os_mkdir(new_path) == MKDIR_ERROR)
  488. return;
  489. strcat(path, "/scenes.json");
  490. strcat(new_path, "/");
  491. strcat(new_path, Str("Untitled"));
  492. strcat(new_path, ".json");
  493. os_rename(path, new_path);
  494. }
  495. void OBSApp::AppInit()
  496. {
  497. ProfileScope("OBSApp::AppInit");
  498. if (!InitApplicationBundle())
  499. throw "Failed to initialize application bundle";
  500. if (!MakeUserDirs())
  501. throw "Failed to create required user directories";
  502. if (!InitGlobalConfig())
  503. throw "Failed to initialize global config";
  504. if (!InitLocale())
  505. throw "Failed to load locale";
  506. if (!InitTheme())
  507. throw "Failed to load theme";
  508. config_set_default_string(globalConfig, "Basic", "Profile",
  509. Str("Untitled"));
  510. config_set_default_string(globalConfig, "Basic", "ProfileDir",
  511. Str("Untitled"));
  512. config_set_default_string(globalConfig, "Basic", "SceneCollection",
  513. Str("Untitled"));
  514. config_set_default_string(globalConfig, "Basic", "SceneCollectionFile",
  515. Str("Untitled"));
  516. move_basic_to_profiles();
  517. move_basic_to_scene_collections();
  518. if (!MakeUserProfileDirs())
  519. throw "Failed to create profile directories";
  520. }
  521. const char *OBSApp::GetRenderModule() const
  522. {
  523. const char *renderer = config_get_string(globalConfig, "Video",
  524. "Renderer");
  525. return (astrcmpi(renderer, "Direct3D 11") == 0) ?
  526. DL_D3D11 : DL_OPENGL;
  527. }
  528. static bool StartupOBS(const char *locale, profiler_name_store_t *store)
  529. {
  530. char path[512];
  531. if (GetConfigPath(path, sizeof(path), "obs-studio/plugin_config") <= 0)
  532. return false;
  533. return obs_startup(locale, path, store);
  534. }
  535. bool OBSApp::OBSInit()
  536. {
  537. ProfileScope("OBSApp::OBSInit");
  538. bool licenseAccepted = config_get_bool(globalConfig, "General",
  539. "LicenseAccepted");
  540. OBSLicenseAgreement agreement(nullptr);
  541. if (licenseAccepted || agreement.exec() == QDialog::Accepted) {
  542. if (!licenseAccepted) {
  543. config_set_bool(globalConfig, "General",
  544. "LicenseAccepted", true);
  545. config_save(globalConfig);
  546. }
  547. if (!StartupOBS(locale.c_str(), GetProfilerNameStore()))
  548. return false;
  549. mainWindow = new OBSBasic();
  550. mainWindow->setAttribute(Qt::WA_DeleteOnClose, true);
  551. connect(mainWindow, SIGNAL(destroyed()), this, SLOT(quit()));
  552. mainWindow->OBSInit();
  553. connect(this, &QGuiApplication::applicationStateChanged,
  554. [](Qt::ApplicationState state)
  555. {
  556. obs_hotkey_enable_background_press(
  557. state != Qt::ApplicationActive);
  558. });
  559. obs_hotkey_enable_background_press(
  560. applicationState() != Qt::ApplicationActive);
  561. return true;
  562. } else {
  563. return false;
  564. }
  565. }
  566. string OBSApp::GetVersionString() const
  567. {
  568. stringstream ver;
  569. #ifdef HAVE_OBSCONFIG_H
  570. ver << OBS_VERSION;
  571. #else
  572. ver << LIBOBS_API_MAJOR_VER << "." <<
  573. LIBOBS_API_MINOR_VER << "." <<
  574. LIBOBS_API_PATCH_VER;
  575. #endif
  576. ver << " (";
  577. #ifdef _WIN32
  578. if (sizeof(void*) == 8)
  579. ver << "64bit, ";
  580. ver << "windows)";
  581. #elif __APPLE__
  582. ver << "mac)";
  583. #elif __FreeBSD__
  584. ver << "freebsd)";
  585. #else /* assume linux for the time being */
  586. ver << "linux)";
  587. #endif
  588. return ver.str();
  589. }
  590. #ifdef __APPLE__
  591. #define INPUT_AUDIO_SOURCE "coreaudio_input_capture"
  592. #define OUTPUT_AUDIO_SOURCE "coreaudio_output_capture"
  593. #elif _WIN32
  594. #define INPUT_AUDIO_SOURCE "wasapi_input_capture"
  595. #define OUTPUT_AUDIO_SOURCE "wasapi_output_capture"
  596. #else
  597. #define INPUT_AUDIO_SOURCE "pulse_input_capture"
  598. #define OUTPUT_AUDIO_SOURCE "pulse_output_capture"
  599. #endif
  600. const char *OBSApp::InputAudioSource() const
  601. {
  602. return INPUT_AUDIO_SOURCE;
  603. }
  604. const char *OBSApp::OutputAudioSource() const
  605. {
  606. return OUTPUT_AUDIO_SOURCE;
  607. }
  608. const char *OBSApp::GetLastLog() const
  609. {
  610. return lastLogFile.c_str();
  611. }
  612. const char *OBSApp::GetCurrentLog() const
  613. {
  614. return currentLogFile.c_str();
  615. }
  616. QString OBSTranslator::translate(const char *context, const char *sourceText,
  617. const char *disambiguation, int n) const
  618. {
  619. const char *out = nullptr;
  620. if (!text_lookup_getstr(App()->GetTextLookup(), sourceText, &out))
  621. return QString();
  622. UNUSED_PARAMETER(context);
  623. UNUSED_PARAMETER(disambiguation);
  624. UNUSED_PARAMETER(n);
  625. return QT_UTF8(out);
  626. }
  627. static bool get_token(lexer *lex, string &str, base_token_type type)
  628. {
  629. base_token token;
  630. if (!lexer_getbasetoken(lex, &token, IGNORE_WHITESPACE))
  631. return false;
  632. if (token.type != type)
  633. return false;
  634. str.assign(token.text.array, token.text.len);
  635. return true;
  636. }
  637. static bool expect_token(lexer *lex, const char *str, base_token_type type)
  638. {
  639. base_token token;
  640. if (!lexer_getbasetoken(lex, &token, IGNORE_WHITESPACE))
  641. return false;
  642. if (token.type != type)
  643. return false;
  644. return strref_cmp(&token.text, str) == 0;
  645. }
  646. static uint64_t convert_log_name(const char *name)
  647. {
  648. BaseLexer lex;
  649. string year, month, day, hour, minute, second;
  650. lexer_start(lex, name);
  651. if (!get_token(lex, year, BASETOKEN_DIGIT)) return 0;
  652. if (!expect_token(lex, "-", BASETOKEN_OTHER)) return 0;
  653. if (!get_token(lex, month, BASETOKEN_DIGIT)) return 0;
  654. if (!expect_token(lex, "-", BASETOKEN_OTHER)) return 0;
  655. if (!get_token(lex, day, BASETOKEN_DIGIT)) return 0;
  656. if (!get_token(lex, hour, BASETOKEN_DIGIT)) return 0;
  657. if (!expect_token(lex, "-", BASETOKEN_OTHER)) return 0;
  658. if (!get_token(lex, minute, BASETOKEN_DIGIT)) return 0;
  659. if (!expect_token(lex, "-", BASETOKEN_OTHER)) return 0;
  660. if (!get_token(lex, second, BASETOKEN_DIGIT)) return 0;
  661. stringstream timestring;
  662. timestring << year << month << day << hour << minute << second;
  663. return std::stoull(timestring.str());
  664. }
  665. static void delete_oldest_file(const char *location)
  666. {
  667. BPtr<char> logDir(GetConfigPathPtr(location));
  668. string oldestLog;
  669. uint64_t oldest_ts = (uint64_t)-1;
  670. struct os_dirent *entry;
  671. unsigned int maxLogs = (unsigned int)config_get_uint(
  672. App()->GlobalConfig(), "General", "MaxLogs");
  673. os_dir_t *dir = os_opendir(logDir);
  674. if (dir) {
  675. unsigned int count = 0;
  676. while ((entry = os_readdir(dir)) != NULL) {
  677. if (entry->directory || *entry->d_name == '.')
  678. continue;
  679. uint64_t ts = convert_log_name(entry->d_name);
  680. if (ts) {
  681. if (ts < oldest_ts) {
  682. oldestLog = entry->d_name;
  683. oldest_ts = ts;
  684. }
  685. count++;
  686. }
  687. }
  688. os_closedir(dir);
  689. if (count > maxLogs) {
  690. stringstream delPath;
  691. delPath << logDir << "/" << oldestLog;
  692. os_unlink(delPath.str().c_str());
  693. }
  694. }
  695. }
  696. static void get_last_log(void)
  697. {
  698. BPtr<char> logDir(GetConfigPathPtr("obs-studio/logs"));
  699. struct os_dirent *entry;
  700. os_dir_t *dir = os_opendir(logDir);
  701. uint64_t highest_ts = 0;
  702. if (dir) {
  703. while ((entry = os_readdir(dir)) != NULL) {
  704. if (entry->directory || *entry->d_name == '.')
  705. continue;
  706. uint64_t ts = convert_log_name(entry->d_name);
  707. if (ts > highest_ts) {
  708. lastLogFile = entry->d_name;
  709. highest_ts = ts;
  710. }
  711. }
  712. os_closedir(dir);
  713. }
  714. }
  715. string GenerateTimeDateFilename(const char *extension)
  716. {
  717. time_t now = time(0);
  718. char file[256] = {};
  719. struct tm *cur_time;
  720. cur_time = localtime(&now);
  721. snprintf(file, sizeof(file), "%d-%02d-%02d %02d-%02d-%02d.%s",
  722. cur_time->tm_year+1900,
  723. cur_time->tm_mon+1,
  724. cur_time->tm_mday,
  725. cur_time->tm_hour,
  726. cur_time->tm_min,
  727. cur_time->tm_sec,
  728. extension);
  729. return string(file);
  730. }
  731. vector<pair<string, string>> GetLocaleNames()
  732. {
  733. string path;
  734. if (!GetDataFilePath("locale.ini", path))
  735. throw "Could not find locale.ini path";
  736. ConfigFile ini;
  737. if (ini.Open(path.c_str(), CONFIG_OPEN_EXISTING) != 0)
  738. throw "Could not open locale.ini";
  739. size_t sections = config_num_sections(ini);
  740. vector<pair<string, string>> names;
  741. names.reserve(sections);
  742. for (size_t i = 0; i < sections; i++) {
  743. const char *tag = config_get_section(ini, i);
  744. const char *name = config_get_string(ini, tag, "Name");
  745. names.emplace_back(tag, name);
  746. }
  747. return names;
  748. }
  749. static void create_log_file(fstream &logFile)
  750. {
  751. stringstream dst;
  752. get_last_log();
  753. currentLogFile = GenerateTimeDateFilename("txt");
  754. dst << "obs-studio/logs/" << currentLogFile.c_str();
  755. BPtr<char> path(GetConfigPathPtr(dst.str().c_str()));
  756. logFile.open(path,
  757. ios_base::in | ios_base::out | ios_base::trunc);
  758. if (logFile.is_open()) {
  759. delete_oldest_file("obs-studio/logs");
  760. base_set_log_handler(do_log, &logFile);
  761. } else {
  762. blog(LOG_ERROR, "Failed to open log file");
  763. }
  764. }
  765. static auto ProfilerNameStoreRelease = [](profiler_name_store_t *store)
  766. {
  767. profiler_name_store_free(store);
  768. };
  769. using ProfilerNameStore =
  770. std::unique_ptr<profiler_name_store_t,
  771. decltype(ProfilerNameStoreRelease)>;
  772. ProfilerNameStore CreateNameStore()
  773. {
  774. return ProfilerNameStore{profiler_name_store_create(),
  775. ProfilerNameStoreRelease};
  776. }
  777. static auto SnapshotRelease = [](profiler_snapshot_t *snap)
  778. {
  779. profile_snapshot_free(snap);
  780. };
  781. using ProfilerSnapshot =
  782. std::unique_ptr<profiler_snapshot_t, decltype(SnapshotRelease)>;
  783. ProfilerSnapshot GetSnapshot()
  784. {
  785. return ProfilerSnapshot{profile_snapshot_create(), SnapshotRelease};
  786. }
  787. static void SaveProfilerData(const ProfilerSnapshot &snap)
  788. {
  789. if (currentLogFile.empty())
  790. return;
  791. auto pos = currentLogFile.rfind('.');
  792. if (pos == currentLogFile.npos)
  793. return;
  794. #define LITERAL_SIZE(x) x, (sizeof(x) - 1)
  795. ostringstream dst;
  796. dst.write(LITERAL_SIZE("obs-studio/profiler_data/"));
  797. dst.write(currentLogFile.c_str(), pos);
  798. dst.write(LITERAL_SIZE(".csv.gz"));
  799. #undef LITERAL_SIZE
  800. BPtr<char> path = GetConfigPathPtr(dst.str().c_str());
  801. if (!profiler_snapshot_dump_csv_gz(snap.get(), path))
  802. blog(LOG_WARNING, "Could not save profiler data to '%s'",
  803. static_cast<const char*>(path));
  804. }
  805. static auto ProfilerFree = [](void *)
  806. {
  807. profiler_stop();
  808. auto snap = GetSnapshot();
  809. profiler_print(snap.get());
  810. profiler_print_time_between_calls(snap.get());
  811. SaveProfilerData(snap);
  812. profiler_free();
  813. };
  814. static const char *run_program_init = "run_program_init";
  815. static int run_program(fstream &logFile, int argc, char *argv[])
  816. {
  817. int ret = -1;
  818. auto profilerNameStore = CreateNameStore();
  819. std::unique_ptr<void, decltype(ProfilerFree)>
  820. prof_release(static_cast<void*>(&ProfilerFree),
  821. ProfilerFree);
  822. profiler_start();
  823. profile_register_root(run_program_init, 0);
  824. auto PrintInitProfile = [&]()
  825. {
  826. auto snap = GetSnapshot();
  827. profiler_snapshot_filter_roots(snap.get(), [](void *data,
  828. const char *name, bool *remove)
  829. {
  830. *remove = (*static_cast<const char**>(data)) != name;
  831. return true;
  832. }, static_cast<void*>(&run_program_init));
  833. profiler_print(snap.get());
  834. };
  835. ScopeProfiler prof{run_program_init};
  836. QCoreApplication::addLibraryPath(".");
  837. OBSApp program(argc, argv, profilerNameStore.get());
  838. try {
  839. program.AppInit();
  840. OBSTranslator translator;
  841. create_log_file(logFile);
  842. delete_oldest_file("obs-studio/profiler_data");
  843. program.installTranslator(&translator);
  844. if (!program.OBSInit())
  845. return 0;
  846. prof.Stop();
  847. PrintInitProfile();
  848. return program.exec();
  849. } catch (const char *error) {
  850. blog(LOG_ERROR, "%s", error);
  851. OBSErrorBox(nullptr, "%s", error);
  852. }
  853. return ret;
  854. }
  855. #define MAX_CRASH_REPORT_SIZE (50 * 1024)
  856. #ifdef _WIN32
  857. #define CRASH_MESSAGE \
  858. "Woops, OBS has crashed!\n\nWould you like to copy the crash log " \
  859. "to the clipboard? (Crash logs will still be saved to the " \
  860. "%appdata%\\obs-studio\\crashes directory)"
  861. static void main_crash_handler(const char *format, va_list args, void *param)
  862. {
  863. char *text = new char[MAX_CRASH_REPORT_SIZE];
  864. vsnprintf(text, MAX_CRASH_REPORT_SIZE, format, args);
  865. delete_oldest_file("obs-studio/crashes");
  866. string name = "obs-studio/crashes/Crash ";
  867. name += GenerateTimeDateFilename("txt");
  868. BPtr<char> path(GetConfigPathPtr(name.c_str()));
  869. fstream file;
  870. file.open(path, ios_base::in | ios_base::out | ios_base::trunc);
  871. file << text;
  872. file.close();
  873. int ret = MessageBoxA(NULL, CRASH_MESSAGE, "OBS has crashed!",
  874. MB_YESNO | MB_ICONERROR | MB_TASKMODAL);
  875. if (ret == IDYES) {
  876. size_t len = strlen(text);
  877. HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, len);
  878. memcpy(GlobalLock(mem), text, len);
  879. GlobalUnlock(mem);
  880. OpenClipboard(0);
  881. EmptyClipboard();
  882. SetClipboardData(CF_TEXT, mem);
  883. CloseClipboard();
  884. }
  885. exit(-1);
  886. UNUSED_PARAMETER(param);
  887. }
  888. static void load_debug_privilege(void)
  889. {
  890. const DWORD flags = TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY;
  891. TOKEN_PRIVILEGES tp;
  892. HANDLE token;
  893. LUID val;
  894. if (!OpenProcessToken(GetCurrentProcess(), flags, &token)) {
  895. return;
  896. }
  897. if (!!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &val)) {
  898. tp.PrivilegeCount = 1;
  899. tp.Privileges[0].Luid = val;
  900. tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  901. AdjustTokenPrivileges(token, false, &tp,
  902. sizeof(tp), NULL, NULL);
  903. }
  904. CloseHandle(token);
  905. }
  906. #endif
  907. #ifdef __APPLE__
  908. #define BASE_PATH ".."
  909. #else
  910. #define BASE_PATH "../.."
  911. #endif
  912. #define CONFIG_PATH BASE_PATH "/config"
  913. #ifndef OBS_UNIX_STRUCTURE
  914. #define OBS_UNIX_STRUCTURE 0
  915. #endif
  916. int GetConfigPath(char *path, size_t size, const char *name)
  917. {
  918. if (!OBS_UNIX_STRUCTURE && portable_mode) {
  919. if (name && *name) {
  920. return snprintf(path, size, CONFIG_PATH "/%s", name);
  921. } else {
  922. return snprintf(path, size, CONFIG_PATH);
  923. }
  924. } else {
  925. return os_get_config_path(path, size, name);
  926. }
  927. }
  928. char *GetConfigPathPtr(const char *name)
  929. {
  930. if (!OBS_UNIX_STRUCTURE && portable_mode) {
  931. char path[512];
  932. if (snprintf(path, sizeof(path), CONFIG_PATH "/%s", name) > 0) {
  933. return bstrdup(path);
  934. } else {
  935. return NULL;
  936. }
  937. } else {
  938. return os_get_config_path_ptr(name);
  939. }
  940. }
  941. bool GetFileSafeName(const char *name, std::string &file)
  942. {
  943. size_t base_len = strlen(name);
  944. size_t len = os_utf8_to_wcs(name, base_len, nullptr, 0);
  945. std::wstring wfile;
  946. if (!len)
  947. return false;
  948. wfile.resize(len);
  949. os_utf8_to_wcs(name, base_len, &wfile[0], len);
  950. for (size_t i = wfile.size(); i > 0; i--) {
  951. size_t im1 = i - 1;
  952. if (iswspace(wfile[im1])) {
  953. wfile[im1] = '_';
  954. } else if (wfile[im1] != '_' && !iswalnum(wfile[im1])) {
  955. wfile.erase(im1, 1);
  956. }
  957. }
  958. if (wfile.size() == 0)
  959. wfile = L"characters_only";
  960. len = os_wcs_to_utf8(wfile.c_str(), wfile.size(), nullptr, 0);
  961. if (!len)
  962. return false;
  963. file.resize(len);
  964. os_wcs_to_utf8(wfile.c_str(), wfile.size(), &file[0], len);
  965. return true;
  966. }
  967. bool GetClosestUnusedFileName(std::string &path, const char *extension)
  968. {
  969. size_t len = path.size();
  970. if (extension) {
  971. path += ".";
  972. path += extension;
  973. }
  974. if (!os_file_exists(path.c_str()))
  975. return true;
  976. int index = 1;
  977. do {
  978. path.resize(len);
  979. path += std::to_string(++index);
  980. if (extension) {
  981. path += ".";
  982. path += extension;
  983. }
  984. } while (os_file_exists(path.c_str()));
  985. return true;
  986. }
  987. static inline bool arg_is(const char *arg,
  988. const char *long_form, const char *short_form)
  989. {
  990. return (long_form && strcmp(arg, long_form) == 0) ||
  991. (short_form && strcmp(arg, short_form) == 0);
  992. }
  993. #if !defined(_WIN32) && !defined(__APPLE__)
  994. #define IS_UNIX 1
  995. #endif
  996. /* if using XDG and was previously using an older build of OBS, move config
  997. * files to XDG directory */
  998. #if defined(USE_XDG) && defined(IS_UNIX)
  999. static void move_to_xdg(void)
  1000. {
  1001. char old_path[512];
  1002. char new_path[512];
  1003. char *home = getenv("HOME");
  1004. if (!home)
  1005. return;
  1006. if (snprintf(old_path, 512, "%s/.obs-studio", home) <= 0)
  1007. return;
  1008. /* make base xdg path if it doesn't already exist */
  1009. if (GetConfigPath(new_path, 512, "") <= 0)
  1010. return;
  1011. if (os_mkdirs(new_path) == MKDIR_ERROR)
  1012. return;
  1013. if (GetConfigPath(new_path, 512, "obs-studio") <= 0)
  1014. return;
  1015. if (os_file_exists(old_path) && !os_file_exists(new_path)) {
  1016. rename(old_path, new_path);
  1017. }
  1018. }
  1019. #endif
  1020. static bool update_ffmpeg_output(ConfigFile &config)
  1021. {
  1022. if (config_has_user_value(config, "AdvOut", "FFOutputToFile"))
  1023. return false;
  1024. const char *url = config_get_string(config, "AdvOut", "FFURL");
  1025. if (!url)
  1026. return false;
  1027. bool isActualURL = strstr(url, "://") != nullptr;
  1028. if (isActualURL)
  1029. return false;
  1030. string urlStr = url;
  1031. string extension;
  1032. for (size_t i = urlStr.length(); i > 0; i--) {
  1033. size_t idx = i - 1;
  1034. if (urlStr[idx] == '.') {
  1035. extension = &urlStr[i];
  1036. }
  1037. if (urlStr[idx] == '\\' || urlStr[idx] == '/') {
  1038. urlStr[idx] = 0;
  1039. break;
  1040. }
  1041. }
  1042. if (urlStr.empty() || extension.empty())
  1043. return false;
  1044. config_remove_value(config, "AdvOut", "FFURL");
  1045. config_set_string(config, "AdvOut", "FFFilePath", urlStr.c_str());
  1046. config_set_string(config, "AdvOut", "FFExtension", extension.c_str());
  1047. config_set_bool(config, "AdvOut", "FFOutputToFile", true);
  1048. return true;
  1049. }
  1050. static bool move_reconnect_settings(ConfigFile &config, const char *sec)
  1051. {
  1052. bool changed = false;
  1053. if (config_has_user_value(config, sec, "Reconnect")) {
  1054. bool reconnect = config_get_bool(config, sec, "Reconnect");
  1055. config_set_bool(config, "Output", "Reconnect", reconnect);
  1056. changed = true;
  1057. }
  1058. if (config_has_user_value(config, sec, "RetryDelay")) {
  1059. int delay = (int)config_get_uint(config, sec, "RetryDelay");
  1060. config_set_uint(config, "Output", "RetryDelay", delay);
  1061. changed = true;
  1062. }
  1063. if (config_has_user_value(config, sec, "MaxRetries")) {
  1064. int retries = (int)config_get_uint(config, sec, "MaxRetries");
  1065. config_set_uint(config, "Output", "MaxRetries", retries);
  1066. changed = true;
  1067. }
  1068. return changed;
  1069. }
  1070. static bool update_reconnect(ConfigFile &config)
  1071. {
  1072. if (!config_has_user_value(config, "Output", "Mode"))
  1073. return false;
  1074. const char *mode = config_get_string(config, "Output", "Mode");
  1075. if (!mode)
  1076. return false;
  1077. const char *section = (strcmp(mode, "Advanced") == 0) ?
  1078. "AdvOut" : "SimpleOutput";
  1079. if (move_reconnect_settings(config, section)) {
  1080. config_remove_value(config, "SimpleOutput", "Reconnect");
  1081. config_remove_value(config, "SimpleOutput", "RetryDelay");
  1082. config_remove_value(config, "SimpleOutput", "MaxRetries");
  1083. config_remove_value(config, "AdvOut", "Reconnect");
  1084. config_remove_value(config, "AdvOut", "RetryDelay");
  1085. config_remove_value(config, "AdvOut", "MaxRetries");
  1086. return true;
  1087. }
  1088. return false;
  1089. }
  1090. static void upgrade_settings(void)
  1091. {
  1092. char path[512];
  1093. int pathlen = GetConfigPath(path, 512, "obs-studio/basic/profiles");
  1094. if (pathlen <= 0)
  1095. return;
  1096. if (!os_file_exists(path))
  1097. return;
  1098. os_dir_t *dir = os_opendir(path);
  1099. if (!dir)
  1100. return;
  1101. struct os_dirent *ent = os_readdir(dir);
  1102. while (ent) {
  1103. if (ent->directory) {
  1104. strcat(path, "/");
  1105. strcat(path, ent->d_name);
  1106. strcat(path, "/basic.ini");
  1107. ConfigFile config;
  1108. int ret;
  1109. ret = config.Open(path, CONFIG_OPEN_EXISTING);
  1110. if (ret == CONFIG_SUCCESS) {
  1111. if (update_ffmpeg_output(config) ||
  1112. update_reconnect(config)) {
  1113. config_save_safe(config, "tmp",
  1114. nullptr);
  1115. }
  1116. }
  1117. path[pathlen] = 0;
  1118. }
  1119. ent = os_readdir(dir);
  1120. }
  1121. os_closedir(dir);
  1122. }
  1123. int main(int argc, char *argv[])
  1124. {
  1125. #ifndef _WIN32
  1126. signal(SIGPIPE, SIG_IGN);
  1127. #endif
  1128. #ifdef _WIN32
  1129. load_debug_privilege();
  1130. base_set_crash_handler(main_crash_handler, nullptr);
  1131. #endif
  1132. base_get_log_handler(&def_log_handler, nullptr);
  1133. #if defined(USE_XDG) && defined(IS_UNIX)
  1134. move_to_xdg();
  1135. #endif
  1136. for (int i = 1; i < argc; i++) {
  1137. if (arg_is(argv[i], "--portable", "-p")) {
  1138. portable_mode = true;
  1139. }
  1140. }
  1141. #if !OBS_UNIX_STRUCTURE
  1142. if (!portable_mode) {
  1143. portable_mode =
  1144. os_file_exists(BASE_PATH "/portable_mode") ||
  1145. os_file_exists(BASE_PATH "/obs_portable_mode") ||
  1146. os_file_exists(BASE_PATH "/portable_mode.txt") ||
  1147. os_file_exists(BASE_PATH "/obs_portable_mode.txt");
  1148. }
  1149. #endif
  1150. upgrade_settings();
  1151. fstream logFile;
  1152. curl_global_init(CURL_GLOBAL_ALL);
  1153. int ret = run_program(logFile, argc, argv);
  1154. blog(LOG_INFO, "Number of memory leaks: %ld", bnum_allocs());
  1155. base_set_log_handler(nullptr, nullptr);
  1156. return ret;
  1157. }