summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp50
-rw-r--r--src/defaults.cpp2
-rw-r--r--src/gui/widgets/setupitem.cpp32
-rw-r--r--src/gui/widgets/setupitem.h14
-rw-r--r--src/gui/widgets/tabs/setup_other.cpp4
-rw-r--r--src/utils/base64.cpp29
-rw-r--r--src/utils/base64.h14
7 files changed, 107 insertions, 38 deletions
diff --git a/src/client.cpp b/src/client.cpp
index daa2d83a2..133be841f 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -107,6 +107,7 @@
#include "resources/db/palettedb.h"
#include "resources/db/petdb.h"
+#include "utils/base64.h"
#include "utils/cpu.h"
#include "utils/files.h"
#include "utils/fuzzer.h"
@@ -2299,40 +2300,39 @@ void Client::initScreenshotDir()
}
else if (mScreenshotDir.empty())
{
+ mScreenshotDir = decodeBase64String(
+ config.getStringValue("screenshotDirectory2"));
+ if (mScreenshotDir.empty())
+ {
#ifdef __ANDROID__
- mScreenshotDir = getSdStoragePath() + std::string("/images");
+ mScreenshotDir = getSdStoragePath() + std::string("/images");
- if (mkdir_r(mScreenshotDir.c_str()))
- {
- // TRANSLATORS: directory creation error
- logger->log(strprintf(
- _("Error: %s doesn't exist and can't be created! "
- "Exiting."), mScreenshotDir.c_str()));
- }
+ if (mkdir_r(mScreenshotDir.c_str()))
+ {
+ // TRANSLATORS: directory creation error
+ logger->log(strprintf(
+ _("Error: %s doesn't exist and can't be created! "
+ "Exiting."), mScreenshotDir.c_str()));
+ }
#else
- const std::string configScreenshotDir =
- config.getStringValue("screenshotDirectory");
- if (!configScreenshotDir.empty())
- mScreenshotDir = configScreenshotDir;
- else
mScreenshotDir = getPicturesDir();
#endif
-
-// config.setValue("screenshotDirectory", mScreenshotDir);
- logger->log("screenshotDirectory: " + mScreenshotDir);
-
- if (config.getBoolValue("useScreenshotDirectorySuffix"))
- {
- const std::string configScreenshotSuffix =
- branding.getValue("screenshots", "ManaPlus");
-
- if (!configScreenshotSuffix.empty())
+ if (config.getBoolValue("useScreenshotDirectorySuffix"))
{
- mScreenshotDir.append(dirSeparator).append(
- configScreenshotSuffix);
+ const std::string configScreenshotSuffix =
+ branding.getValue("screenshots", "ManaPlus");
+
+ if (!configScreenshotSuffix.empty())
+ {
+ mScreenshotDir.append(dirSeparator).append(
+ configScreenshotSuffix);
+ }
}
+ config.setValue("screenshotDirectory2",
+ encodeBase64String(mScreenshotDir));
}
}
+ logger->log("screenshotDirectory: " + mScreenshotDir);
}
void Client::accountLogin(LoginData *const data) const
diff --git a/src/defaults.cpp b/src/defaults.cpp
index ebab42d54..9362473fd 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -152,7 +152,7 @@ DefaultsData* getConfigDefaults()
AddDEF("lastCharacter", "");
AddDEF("altfpslimit", 5);
AddDEF("updatehost", "");
- AddDEF("screenshotDirectory", "");
+ AddDEF("screenshotDirectory2", "");
AddDEF("useScreenshotDirectorySuffix", true);
AddDEF("screenshotDirectorySuffix", "");
AddDEF("EnableSync", false);
diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp
index e8bec1db6..6ce8ce102 100644
--- a/src/gui/widgets/setupitem.cpp
+++ b/src/gui/widgets/setupitem.cpp
@@ -37,6 +37,7 @@
#include "gui/widgets/sliderlist.h"
#include "gui/widgets/vertcontainer.h"
+#include "utils/base64.h"
#include "utils/gettext.h"
#include "utils/mathutils.h"
@@ -136,7 +137,7 @@ void SetupItem::load()
}
}
-void SetupItem::save() const
+void SetupItem::save()
{
if (mKeyName.empty())
return;
@@ -267,13 +268,15 @@ SetupItemTextField::SetupItemTextField(const std::string &restrict text,
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- const bool mainConfig) :
+ const bool mainConfig,
+ const bool useBase64) :
SetupItem(text, description, keyName, parent, eventName, mainConfig),
mHorizont(nullptr),
mLabel(nullptr),
mTextField(nullptr),
mButton(nullptr),
- mEditDialog(nullptr)
+ mEditDialog(nullptr),
+ mUseBase64(useBase64)
{
mValueType = VSTR;
createControls();
@@ -285,13 +288,15 @@ SetupItemTextField::SetupItemTextField(const std::string &restrict text,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
const std::string &restrict def,
- const bool mainConfig) :
+ const bool mainConfig,
+ const bool useBase64) :
SetupItem(text, description, keyName, parent, eventName, def, mainConfig),
mHorizont(nullptr),
mLabel(nullptr),
mTextField(nullptr),
mButton(nullptr),
- mEditDialog(nullptr)
+ mEditDialog(nullptr),
+ mUseBase64(useBase64)
{
mValueType = VSTR;
createControls();
@@ -306,9 +311,26 @@ SetupItemTextField::~SetupItemTextField()
mButton = nullptr;
}
+void SetupItemTextField::save()
+{
+ if (mUseBase64)
+ {
+ std::string normalValue = mValue;
+ mValue = encodeBase64String(mValue);
+ SetupItem::save();
+ mValue = normalValue;
+ }
+ else
+ {
+ SetupItem::save();
+ }
+}
+
void SetupItemTextField::createControls()
{
load();
+ if (mUseBase64)
+ mValue = decodeBase64String(mValue);
mHorizont = new HorizontContainer(this, 32, 2);
mLabel = new Label(this, mText);
diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h
index 40a20a985..91547733f 100644
--- a/src/gui/widgets/setupitem.h
+++ b/src/gui/widgets/setupitem.h
@@ -63,7 +63,7 @@ class SetupItem : public gcn::ActionListener,
void load();
- void save() const;
+ virtual void save();
virtual void fromWidget() = 0;
@@ -188,7 +188,8 @@ class SetupItemTextField final : public SetupItem
const std::string &restrict keyName,
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
- const bool mainConfig = true);
+ const bool mainConfig = true,
+ const bool useBase64 = false);
SetupItemTextField(const std::string &restrict text,
const std::string &restrict description,
@@ -196,7 +197,8 @@ class SetupItemTextField final : public SetupItem
SetupTabScroll *restrict const parent,
const std::string &restrict eventName,
const std::string &restrict def,
- const bool mainConfig = true);
+ const bool mainConfig = true,
+ const bool useBase64 = false);
A_DELETE_COPY(SetupItemTextField)
@@ -212,12 +214,18 @@ class SetupItemTextField final : public SetupItem
void apply(const std::string &eventName) override final;
+ void save() override final;
+
+ void setUseBase64(const bool b)
+ { mUseBase64 = b; }
+
protected:
HorizontContainer *mHorizont;
Label *mLabel;
TextField *mTextField;
Button *mButton;
EditDialog *mEditDialog;
+ bool mUseBase64;
};
class SetupItemIntTextField final : public SetupItem
diff --git a/src/gui/widgets/tabs/setup_other.cpp b/src/gui/widgets/tabs/setup_other.cpp
index 7dea0021f..940623379 100644
--- a/src/gui/widgets/tabs/setup_other.cpp
+++ b/src/gui/widgets/tabs/setup_other.cpp
@@ -372,6 +372,10 @@ Setup_Other::Setup_Other(const Widget2 *const widget) :
#endif
// TRANSLATORS: settings option
+ new SetupItemTextField(_("Screenshot directory"), "",
+ "screenshotDirectory2", this, "screenshotDirectory2Event", true, true);
+
+ // TRANSLATORS: settings option
new SetupItemIntTextField(_("Network delay between sub servers"),
"", "networksleep", this, "networksleepEvent", 0, 10000);
diff --git a/src/utils/base64.cpp b/src/utils/base64.cpp
index 280e71ff0..f887a9e1b 100644
--- a/src/utils/base64.cpp
+++ b/src/utils/base64.cpp
@@ -174,3 +174,32 @@ unsigned char *php3_base64_decode(const unsigned char *restrict const string,
result[k] = '\0';
return result;
}
+
+std::string encodeBase64String(std::string value)
+{
+ int sz = 0;
+ unsigned char *str = reinterpret_cast<unsigned char*>(
+ const_cast<char*>(value.c_str()));
+ unsigned char *const buf = php3_base64_encode(str, value.size(), &sz);
+ if (!buf)
+ return std::string();
+
+ value = std::string(reinterpret_cast<char*>(buf), sz);
+ free(buf);
+ return value;
+}
+
+std::string decodeBase64String(std::string value)
+{
+ int sz = 0;
+ unsigned char *str = reinterpret_cast<unsigned char*>(
+ const_cast<char*>(value.c_str()));
+ unsigned char *const buf = php3_base64_decode(str, value.size(), &sz);
+
+ if (buf)
+ value = std::string(reinterpret_cast<char*>(buf), sz);
+ else
+ value.clear();
+ free(buf);
+ return value;
+}
diff --git a/src/utils/base64.h b/src/utils/base64.h
index 0e6546df5..4518a3e5a 100644
--- a/src/utils/base64.h
+++ b/src/utils/base64.h
@@ -30,11 +30,17 @@
#ifndef UTILS_BASE64_H
#define UTILS_BASE64_H
+#include <string>
+
#include "localconsts.h"
-extern unsigned char *php3_base64_encode(const unsigned char *restrict,
- int, int *restrict) A_WARN_UNUSED;
-extern unsigned char *php3_base64_decode(const unsigned char *restrict,
- int, int *restrict ) A_WARN_UNUSED;
+unsigned char *php3_base64_encode(const unsigned char *restrict,
+ int, int *restrict) A_WARN_UNUSED;
+unsigned char *php3_base64_decode(const unsigned char *restrict,
+ int, int *restrict ) A_WARN_UNUSED;
+
+std::string encodeBase64String(std::string value) A_WARN_UNUSED;
+
+std::string decodeBase64String(std::string value) A_WARN_UNUSED;
#endif // UTILS_BASE64_H