Selaa lähdekoodia

Add helper function for locale (name) enumeration

Palana 11 vuotta sitten
vanhempi
sitoutus
0413ada9b5
2 muutettua tiedostoa jossa 25 lisäystä ja 0 poistoa
  1. 23 0
      obs/obs-app.cpp
  2. 2 0
      obs/obs-app.hpp

+ 23 - 0
obs/obs-app.cpp

@@ -440,6 +440,29 @@ string GenerateTimeDateFilename(const char *extension)
 	return string(file);
 }
 
+vector<pair<string, string>> GetLocaleNames()
+{
+	string path;
+	if (!GetDataFilePath("locale.ini", path))
+		throw "Could not find locale.ini path";
+
+	ConfigFile ini;
+	if (ini.Open(path.c_str(), CONFIG_OPEN_EXISTING) != 0)
+		throw "Could not open locale.ini";
+
+	size_t sections = config_num_sections(ini);
+
+	vector<pair<string, string>> names;
+	names.reserve(sections);
+	for (size_t i = 0; i < sections; i++) {
+		const char *tag = config_get_section(ini, i);
+		const char *name = config_get_string(ini, tag, "Name");
+		names.emplace_back(tag, name);
+	}
+
+	return names;
+}
+
 static void create_log_file(fstream &logFile)
 {
 	stringstream dst;

+ 2 - 0
obs/obs-app.hpp

@@ -23,6 +23,7 @@
 #include <util/util.hpp>
 #include <string>
 #include <memory>
+#include <vector>
 
 #include "window-main.hpp"
 
@@ -98,5 +99,6 @@ inline OBSApp *App() {return static_cast<OBSApp*>(qApp);}
 
 inline config_t GetGlobalConfig() {return App()->GlobalConfig();}
 
+std::vector<std::pair<std::string, std::string>> GetLocaleNames();
 inline const char *Str(const char *lookup) {return App()->GetString(lookup);}
 #define QTStr(lookupVal) QString::fromUtf8(Str(lookupVal))