obs-app.cpp 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463
  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, bool noSpace)
  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%c%02d-%02d-%02d.%s",
  722. cur_time->tm_year+1900,
  723. cur_time->tm_mon+1,
  724. cur_time->tm_mday,
  725. noSpace ? '_' : ' ',
  726. cur_time->tm_hour,
  727. cur_time->tm_min,
  728. cur_time->tm_sec,
  729. extension);
  730. return string(file);
  731. }
  732. vector<pair<string, string>> GetLocaleNames()
  733. {
  734. string path;
  735. if (!GetDataFilePath("locale.ini", path))
  736. throw "Could not find locale.ini path";
  737. ConfigFile ini;
  738. if (ini.Open(path.c_str(), CONFIG_OPEN_EXISTING) != 0)
  739. throw "Could not open locale.ini";
  740. size_t sections = config_num_sections(ini);
  741. vector<pair<string, string>> names;
  742. names.reserve(sections);
  743. for (size_t i = 0; i < sections; i++) {
  744. const char *tag = config_get_section(ini, i);
  745. const char *name = config_get_string(ini, tag, "Name");
  746. names.emplace_back(tag, name);
  747. }
  748. return names;
  749. }
  750. static void create_log_file(fstream &logFile)
  751. {
  752. stringstream dst;
  753. get_last_log();
  754. currentLogFile = GenerateTimeDateFilename("txt");
  755. dst << "obs-studio/logs/" << currentLogFile.c_str();
  756. BPtr<char> path(GetConfigPathPtr(dst.str().c_str()));
  757. logFile.open(path,
  758. ios_base::in | ios_base::out | ios_base::trunc);
  759. if (logFile.is_open()) {
  760. delete_oldest_file("obs-studio/logs");
  761. base_set_log_handler(do_log, &logFile);
  762. } else {
  763. blog(LOG_ERROR, "Failed to open log file");
  764. }
  765. }
  766. static auto ProfilerNameStoreRelease = [](profiler_name_store_t *store)
  767. {
  768. profiler_name_store_free(store);
  769. };
  770. using ProfilerNameStore =
  771. std::unique_ptr<profiler_name_store_t,
  772. decltype(ProfilerNameStoreRelease)>;
  773. ProfilerNameStore CreateNameStore()
  774. {
  775. return ProfilerNameStore{profiler_name_store_create(),
  776. ProfilerNameStoreRelease};
  777. }
  778. static auto SnapshotRelease = [](profiler_snapshot_t *snap)
  779. {
  780. profile_snapshot_free(snap);
  781. };
  782. using ProfilerSnapshot =
  783. std::unique_ptr<profiler_snapshot_t, decltype(SnapshotRelease)>;
  784. ProfilerSnapshot GetSnapshot()
  785. {
  786. return ProfilerSnapshot{profile_snapshot_create(), SnapshotRelease};
  787. }
  788. static void SaveProfilerData(const ProfilerSnapshot &snap)
  789. {
  790. if (currentLogFile.empty())
  791. return;
  792. auto pos = currentLogFile.rfind('.');
  793. if (pos == currentLogFile.npos)
  794. return;
  795. #define LITERAL_SIZE(x) x, (sizeof(x) - 1)
  796. ostringstream dst;
  797. dst.write(LITERAL_SIZE("obs-studio/profiler_data/"));
  798. dst.write(currentLogFile.c_str(), pos);
  799. dst.write(LITERAL_SIZE(".csv.gz"));
  800. #undef LITERAL_SIZE
  801. BPtr<char> path = GetConfigPathPtr(dst.str().c_str());
  802. if (!profiler_snapshot_dump_csv_gz(snap.get(), path))
  803. blog(LOG_WARNING, "Could not save profiler data to '%s'",
  804. static_cast<const char*>(path));
  805. }
  806. static auto ProfilerFree = [](void *)
  807. {
  808. profiler_stop();
  809. auto snap = GetSnapshot();
  810. profiler_print(snap.get());
  811. profiler_print_time_between_calls(snap.get());
  812. SaveProfilerData(snap);
  813. profiler_free();
  814. };
  815. static const char *run_program_init = "run_program_init";
  816. static int run_program(fstream &logFile, int argc, char *argv[])
  817. {
  818. int ret = -1;
  819. auto profilerNameStore = CreateNameStore();
  820. std::unique_ptr<void, decltype(ProfilerFree)>
  821. prof_release(static_cast<void*>(&ProfilerFree),
  822. ProfilerFree);
  823. profiler_start();
  824. profile_register_root(run_program_init, 0);
  825. auto PrintInitProfile = [&]()
  826. {
  827. auto snap = GetSnapshot();
  828. profiler_snapshot_filter_roots(snap.get(), [](void *data,
  829. const char *name, bool *remove)
  830. {
  831. *remove = (*static_cast<const char**>(data)) != name;
  832. return true;
  833. }, static_cast<void*>(&run_program_init));
  834. profiler_print(snap.get());
  835. };
  836. ScopeProfiler prof{run_program_init};
  837. QCoreApplication::addLibraryPath(".");
  838. OBSApp program(argc, argv, profilerNameStore.get());
  839. try {
  840. program.AppInit();
  841. OBSTranslator translator;
  842. create_log_file(logFile);
  843. delete_oldest_file("obs-studio/profiler_data");
  844. program.installTranslator(&translator);
  845. if (!program.OBSInit())
  846. return 0;
  847. prof.Stop();
  848. PrintInitProfile();
  849. return program.exec();
  850. } catch (const char *error) {
  851. blog(LOG_ERROR, "%s", error);
  852. OBSErrorBox(nullptr, "%s", error);
  853. }
  854. return ret;
  855. }
  856. #define MAX_CRASH_REPORT_SIZE (50 * 1024)
  857. #ifdef _WIN32
  858. #define CRASH_MESSAGE \
  859. "Woops, OBS has crashed!\n\nWould you like to copy the crash log " \
  860. "to the clipboard? (Crash logs will still be saved to the " \
  861. "%appdata%\\obs-studio\\crashes directory)"
  862. static void main_crash_handler(const char *format, va_list args, void *param)
  863. {
  864. char *text = new char[MAX_CRASH_REPORT_SIZE];
  865. vsnprintf(text, MAX_CRASH_REPORT_SIZE, format, args);
  866. delete_oldest_file("obs-studio/crashes");
  867. string name = "obs-studio/crashes/Crash ";
  868. name += GenerateTimeDateFilename("txt");
  869. BPtr<char> path(GetConfigPathPtr(name.c_str()));
  870. fstream file;
  871. file.open(path, ios_base::in | ios_base::out | ios_base::trunc);
  872. file << text;
  873. file.close();
  874. int ret = MessageBoxA(NULL, CRASH_MESSAGE, "OBS has crashed!",
  875. MB_YESNO | MB_ICONERROR | MB_TASKMODAL);
  876. if (ret == IDYES) {
  877. size_t len = strlen(text);
  878. HGLOBAL mem = GlobalAlloc(GMEM_MOVEABLE, len);
  879. memcpy(GlobalLock(mem), text, len);
  880. GlobalUnlock(mem);
  881. OpenClipboard(0);
  882. EmptyClipboard();
  883. SetClipboardData(CF_TEXT, mem);
  884. CloseClipboard();
  885. }
  886. exit(-1);
  887. UNUSED_PARAMETER(param);
  888. }
  889. static void load_debug_privilege(void)
  890. {
  891. const DWORD flags = TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY;
  892. TOKEN_PRIVILEGES tp;
  893. HANDLE token;
  894. LUID val;
  895. if (!OpenProcessToken(GetCurrentProcess(), flags, &token)) {
  896. return;
  897. }
  898. if (!!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &val)) {
  899. tp.PrivilegeCount = 1;
  900. tp.Privileges[0].Luid = val;
  901. tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  902. AdjustTokenPrivileges(token, false, &tp,
  903. sizeof(tp), NULL, NULL);
  904. }
  905. CloseHandle(token);
  906. }
  907. #endif
  908. #ifdef __APPLE__
  909. #define BASE_PATH ".."
  910. #else
  911. #define BASE_PATH "../.."
  912. #endif
  913. #define CONFIG_PATH BASE_PATH "/config"
  914. #ifndef OBS_UNIX_STRUCTURE
  915. #define OBS_UNIX_STRUCTURE 0
  916. #endif
  917. int GetConfigPath(char *path, size_t size, const char *name)
  918. {
  919. if (!OBS_UNIX_STRUCTURE && portable_mode) {
  920. if (name && *name) {
  921. return snprintf(path, size, CONFIG_PATH "/%s", name);
  922. } else {
  923. return snprintf(path, size, CONFIG_PATH);
  924. }
  925. } else {
  926. return os_get_config_path(path, size, name);
  927. }
  928. }
  929. char *GetConfigPathPtr(const char *name)
  930. {
  931. if (!OBS_UNIX_STRUCTURE && portable_mode) {
  932. char path[512];
  933. if (snprintf(path, sizeof(path), CONFIG_PATH "/%s", name) > 0) {
  934. return bstrdup(path);
  935. } else {
  936. return NULL;
  937. }
  938. } else {
  939. return os_get_config_path_ptr(name);
  940. }
  941. }
  942. bool GetFileSafeName(const char *name, std::string &file)
  943. {
  944. size_t base_len = strlen(name);
  945. size_t len = os_utf8_to_wcs(name, base_len, nullptr, 0);
  946. std::wstring wfile;
  947. if (!len)
  948. return false;
  949. wfile.resize(len);
  950. os_utf8_to_wcs(name, base_len, &wfile[0], len);
  951. for (size_t i = wfile.size(); i > 0; i--) {
  952. size_t im1 = i - 1;
  953. if (iswspace(wfile[im1])) {
  954. wfile[im1] = '_';
  955. } else if (wfile[im1] != '_' && !iswalnum(wfile[im1])) {
  956. wfile.erase(im1, 1);
  957. }
  958. }
  959. if (wfile.size() == 0)
  960. wfile = L"characters_only";
  961. len = os_wcs_to_utf8(wfile.c_str(), wfile.size(), nullptr, 0);
  962. if (!len)
  963. return false;
  964. file.resize(len);
  965. os_wcs_to_utf8(wfile.c_str(), wfile.size(), &file[0], len);
  966. return true;
  967. }
  968. bool GetClosestUnusedFileName(std::string &path, const char *extension)
  969. {
  970. size_t len = path.size();
  971. if (extension) {
  972. path += ".";
  973. path += extension;
  974. }
  975. if (!os_file_exists(path.c_str()))
  976. return true;
  977. int index = 1;
  978. do {
  979. path.resize(len);
  980. path += std::to_string(++index);
  981. if (extension) {
  982. path += ".";
  983. path += extension;
  984. }
  985. } while (os_file_exists(path.c_str()));
  986. return true;
  987. }
  988. static inline bool arg_is(const char *arg,
  989. const char *long_form, const char *short_form)
  990. {
  991. return (long_form && strcmp(arg, long_form) == 0) ||
  992. (short_form && strcmp(arg, short_form) == 0);
  993. }
  994. #if !defined(_WIN32) && !defined(__APPLE__)
  995. #define IS_UNIX 1
  996. #endif
  997. /* if using XDG and was previously using an older build of OBS, move config
  998. * files to XDG directory */
  999. #if defined(USE_XDG) && defined(IS_UNIX)
  1000. static void move_to_xdg(void)
  1001. {
  1002. char old_path[512];
  1003. char new_path[512];
  1004. char *home = getenv("HOME");
  1005. if (!home)
  1006. return;
  1007. if (snprintf(old_path, 512, "%s/.obs-studio", home) <= 0)
  1008. return;
  1009. /* make base xdg path if it doesn't already exist */
  1010. if (GetConfigPath(new_path, 512, "") <= 0)
  1011. return;
  1012. if (os_mkdirs(new_path) == MKDIR_ERROR)
  1013. return;
  1014. if (GetConfigPath(new_path, 512, "obs-studio") <= 0)
  1015. return;
  1016. if (os_file_exists(old_path) && !os_file_exists(new_path)) {
  1017. rename(old_path, new_path);
  1018. }
  1019. }
  1020. #endif
  1021. static bool update_ffmpeg_output(ConfigFile &config)
  1022. {
  1023. if (config_has_user_value(config, "AdvOut", "FFOutputToFile"))
  1024. return false;
  1025. const char *url = config_get_string(config, "AdvOut", "FFURL");
  1026. if (!url)
  1027. return false;
  1028. bool isActualURL = strstr(url, "://") != nullptr;
  1029. if (isActualURL)
  1030. return false;
  1031. string urlStr = url;
  1032. string extension;
  1033. for (size_t i = urlStr.length(); i > 0; i--) {
  1034. size_t idx = i - 1;
  1035. if (urlStr[idx] == '.') {
  1036. extension = &urlStr[i];
  1037. }
  1038. if (urlStr[idx] == '\\' || urlStr[idx] == '/') {
  1039. urlStr[idx] = 0;
  1040. break;
  1041. }
  1042. }
  1043. if (urlStr.empty() || extension.empty())
  1044. return false;
  1045. config_remove_value(config, "AdvOut", "FFURL");
  1046. config_set_string(config, "AdvOut", "FFFilePath", urlStr.c_str());
  1047. config_set_string(config, "AdvOut", "FFExtension", extension.c_str());
  1048. config_set_bool(config, "AdvOut", "FFOutputToFile", true);
  1049. return true;
  1050. }
  1051. static bool move_reconnect_settings(ConfigFile &config, const char *sec)
  1052. {
  1053. bool changed = false;
  1054. if (config_has_user_value(config, sec, "Reconnect")) {
  1055. bool reconnect = config_get_bool(config, sec, "Reconnect");
  1056. config_set_bool(config, "Output", "Reconnect", reconnect);
  1057. changed = true;
  1058. }
  1059. if (config_has_user_value(config, sec, "RetryDelay")) {
  1060. int delay = (int)config_get_uint(config, sec, "RetryDelay");
  1061. config_set_uint(config, "Output", "RetryDelay", delay);
  1062. changed = true;
  1063. }
  1064. if (config_has_user_value(config, sec, "MaxRetries")) {
  1065. int retries = (int)config_get_uint(config, sec, "MaxRetries");
  1066. config_set_uint(config, "Output", "MaxRetries", retries);
  1067. changed = true;
  1068. }
  1069. return changed;
  1070. }
  1071. static bool update_reconnect(ConfigFile &config)
  1072. {
  1073. if (!config_has_user_value(config, "Output", "Mode"))
  1074. return false;
  1075. const char *mode = config_get_string(config, "Output", "Mode");
  1076. if (!mode)
  1077. return false;
  1078. const char *section = (strcmp(mode, "Advanced") == 0) ?
  1079. "AdvOut" : "SimpleOutput";
  1080. if (move_reconnect_settings(config, section)) {
  1081. config_remove_value(config, "SimpleOutput", "Reconnect");
  1082. config_remove_value(config, "SimpleOutput", "RetryDelay");
  1083. config_remove_value(config, "SimpleOutput", "MaxRetries");
  1084. config_remove_value(config, "AdvOut", "Reconnect");
  1085. config_remove_value(config, "AdvOut", "RetryDelay");
  1086. config_remove_value(config, "AdvOut", "MaxRetries");
  1087. return true;
  1088. }
  1089. return false;
  1090. }
  1091. static void upgrade_settings(void)
  1092. {
  1093. char path[512];
  1094. int pathlen = GetConfigPath(path, 512, "obs-studio/basic/profiles");
  1095. if (pathlen <= 0)
  1096. return;
  1097. if (!os_file_exists(path))
  1098. return;
  1099. os_dir_t *dir = os_opendir(path);
  1100. if (!dir)
  1101. return;
  1102. struct os_dirent *ent = os_readdir(dir);
  1103. while (ent) {
  1104. if (ent->directory) {
  1105. strcat(path, "/");
  1106. strcat(path, ent->d_name);
  1107. strcat(path, "/basic.ini");
  1108. ConfigFile config;
  1109. int ret;
  1110. ret = config.Open(path, CONFIG_OPEN_EXISTING);
  1111. if (ret == CONFIG_SUCCESS) {
  1112. if (update_ffmpeg_output(config) ||
  1113. update_reconnect(config)) {
  1114. config_save_safe(config, "tmp",
  1115. nullptr);
  1116. }
  1117. }
  1118. path[pathlen] = 0;
  1119. }
  1120. ent = os_readdir(dir);
  1121. }
  1122. os_closedir(dir);
  1123. }
  1124. int main(int argc, char *argv[])
  1125. {
  1126. #ifndef _WIN32
  1127. signal(SIGPIPE, SIG_IGN);
  1128. #endif
  1129. #ifdef _WIN32
  1130. load_debug_privilege();
  1131. base_set_crash_handler(main_crash_handler, nullptr);
  1132. #endif
  1133. base_get_log_handler(&def_log_handler, nullptr);
  1134. #if defined(USE_XDG) && defined(IS_UNIX)
  1135. move_to_xdg();
  1136. #endif
  1137. for (int i = 1; i < argc; i++) {
  1138. if (arg_is(argv[i], "--portable", "-p")) {
  1139. portable_mode = true;
  1140. }
  1141. }
  1142. #if !OBS_UNIX_STRUCTURE
  1143. if (!portable_mode) {
  1144. portable_mode =
  1145. os_file_exists(BASE_PATH "/portable_mode") ||
  1146. os_file_exists(BASE_PATH "/obs_portable_mode") ||
  1147. os_file_exists(BASE_PATH "/portable_mode.txt") ||
  1148. os_file_exists(BASE_PATH "/obs_portable_mode.txt");
  1149. }
  1150. #endif
  1151. upgrade_settings();
  1152. fstream logFile;
  1153. curl_global_init(CURL_GLOBAL_ALL);
  1154. int ret = run_program(logFile, argc, argv);
  1155. blog(LOG_INFO, "Number of memory leaks: %ld", bnum_allocs());
  1156. base_set_log_handler(nullptr, nullptr);
  1157. return ret;
  1158. }