commit a6f2f586541802dc4caf4a73f554962287ed7483
parent 7317f1e57d156543f4ce649b99b79c454eaa813f
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 1 May 2016 17:27:55 -0400
more refactoring
Diffstat:
4 files changed, 28 insertions(+), 21 deletions(-)
diff --git a/src/encoding.hpp b/src/encoding.hpp
@@ -34,6 +34,7 @@ typedef std::wstring auto_string;
#define to_autostring std::to_wstring
#define auto_snprintf(buf, size, ...) _snwprintf(buf, size - 1, __VA_ARGS__)
auto_string make_autostring(const std::string &);
+#define make_autocstring(cstr) make_autostring(cstr).c_str() // temporary string!
std::string from_autostring(const auto_string &);
#else
@@ -45,6 +46,7 @@ typedef std::string auto_string;
#define to_autostring std::to_string
#define auto_snprintf snprintf
#define make_autostring(string) string
+#define make_autocstring(cstr) cstr
#define from_autostring(string) string
#endif
diff --git a/src/main.cpp b/src/main.cpp
@@ -59,8 +59,7 @@ static bool loadAPI(void *(*getFunc)(const char *))
auto_snprintf(msg, auto_size(msg),
AUTO_STR("ReaPack v%s is incompatible with this version of REAPER.\r\n\r\n")
AUTO_STR("(Unable to import the following API function: %s)"),
- make_autostring(ReaPack::VERSION).c_str(),
- make_autostring(string(func.name)).c_str());
+ make_autocstring(ReaPack::VERSION), make_autocstring(func.name));
MessageBox(Splash_GetWnd ? Splash_GetWnd() : nullptr,
msg, AUTO_STR("ReaPack: Fatal Error"), MB_OK);
@@ -103,7 +102,7 @@ static void menuHook(const char *name, HMENU handle, int f)
auto_char aboutLabel[32] = {};
auto_snprintf(aboutLabel, auto_size(aboutLabel),
- AUTO_STR("&About ReaPack v%s"), make_autostring(ReaPack::VERSION).c_str());
+ AUTO_STR("&About ReaPack v%s"), make_autocstring(ReaPack::VERSION));
menu.addAction(aboutLabel, NamedCommandLookup("_REAPACK_ABOUT"));
}
diff --git a/src/reapack.cpp b/src/reapack.cpp
@@ -33,8 +33,8 @@
using namespace std;
-const string ReaPack::VERSION = "0.10-beta";
-const string ReaPack::BUILDTIME = __DATE__ " " __TIME__;
+const char *ReaPack::VERSION = "0.10-beta";
+const char *ReaPack::BUILDTIME = __DATE__ " " __TIME__;
#ifdef _WIN32
// Removes temporary files that could not be removed by an installation task
@@ -245,21 +245,23 @@ void ReaPack::import(const Remote &remote, HWND parent)
return;
}
else if(existing.url() != remote.url()) {
- const string msg = remote.name() +
- " is already configured with a different URL.\r\n"
- "Do you want to overwrite it?";
+ auto_char msg[1024] = {};
+ auto_snprintf(msg, auto_size(msg),
+ AUTO_STR("%s is already configured with a different URL.\r\n")
+ AUTO_STR("Do you want to overwrite it?"),
+ make_autostring(remote.name()).c_str());
- const auto answer = MessageBox(parent, make_autostring(msg).c_str(),
- Import::TITLE, MB_YESNO);
+ const auto answer = MessageBox(parent, msg, Import::TITLE, MB_YESNO);
if(answer != IDYES)
return;
}
else if(existing.isEnabled()) {
- const string msg = remote.name() +
- " is already configured.\r\nNothing to do!";
-
- MessageBox(parent, make_autostring(msg).c_str(), Import::TITLE, MB_OK);
+ auto_char msg[1024] = {};
+ auto_snprintf(msg, auto_size(msg),
+ AUTO_STR("%s is already configured.\r\nNothing to do!"),
+ make_autostring(remote.name()).c_str());
+ MessageBox(parent, msg, Import::TITLE, MB_OK);
return;
}
@@ -269,8 +271,10 @@ void ReaPack::import(const Remote &remote, HWND parent)
m_config->write();
- const string msg = remote.name() + " has been enabled.";
- MessageBox(parent, make_autostring(msg).c_str(), Import::TITLE, MB_OK);
+ auto_char msg[1024] = {};
+ auto_snprintf(msg, auto_size(msg), AUTO_STR("%s has been enabled."),
+ make_autostring(remote.name()).c_str());
+ MessageBox(parent, msg, Import::TITLE, MB_OK);
return;
}
@@ -282,9 +286,11 @@ void ReaPack::import(const Remote &remote, HWND parent)
refreshManager();
refreshBrowser();
- const string msg = remote.name() +
- " has been successfully imported into your repository list.";
- MessageBox(parent, make_autostring(msg).c_str(), Import::TITLE, MB_OK);
+ auto_char msg[1024] = {};
+ auto_snprintf(msg, auto_size(msg),
+ "%s has been successfully imported into your repository list.",
+ make_autostring(remote.name()).c_str());
+ MessageBox(parent, msg, Import::TITLE, MB_OK);
}
void ReaPack::manageRemotes()
diff --git a/src/reapack.hpp b/src/reapack.hpp
@@ -46,8 +46,8 @@ public:
typedef std::function<void (IndexPtr)> IndexCallback;
typedef std::function<void (const std::vector<IndexPtr> &)> IndexesCallback;
- static const std::string VERSION;
- static const std::string BUILDTIME;
+ static const char *VERSION;
+ static const char *BUILDTIME;
gaccel_register_t syncAction;
gaccel_register_t browseAction;