summaryrefslogtreecommitdiff
path: root/zen
diff options
context:
space:
mode:
authorDaniel Wilhelm <shieldwed@outlook.com>2018-05-09 00:04:33 +0200
committerDaniel Wilhelm <shieldwed@outlook.com>2018-05-09 00:04:33 +0200
commit017e56b81ba735c39c43701f737ac7dde55da7b4 (patch)
treeea7aaaee13a06a702701e2f74f5d390e10ae303e /zen
parent9.4 (diff)
downloadFreeFileSync-017e56b81ba735c39c43701f737ac7dde55da7b4.tar.gz
FreeFileSync-017e56b81ba735c39c43701f737ac7dde55da7b4.tar.bz2
FreeFileSync-017e56b81ba735c39c43701f737ac7dde55da7b4.zip
9.5
Diffstat (limited to 'zen')
-rwxr-xr-xzen/error_log.h14
-rwxr-xr-xzen/file_error.h5
-rwxr-xr-xzen/format_unit.cpp8
-rwxr-xr-xzen/format_unit.h12
-rwxr-xr-xzen/i18n.h2
-rwxr-xr-xzen/process_priority.h6
-rwxr-xr-xzen/shell_execute.h15
-rwxr-xr-xzen/shutdown.cpp62
-rwxr-xr-xzen/shutdown.h18
-rwxr-xr-xzen/sys_error.cpp6
-rwxr-xr-xzen/sys_error.h4
-rwxr-xr-xzen/time.h6
-rwxr-xr-xzen/zstring.cpp9
-rwxr-xr-xzen/zstring.h11
14 files changed, 145 insertions, 33 deletions
diff --git a/zen/error_log.h b/zen/error_log.h
index 90016666..0d62dd1f 100755
--- a/zen/error_log.h
+++ b/zen/error_log.h
@@ -49,12 +49,12 @@ public:
//subset of std::vector<> interface:
using const_iterator = std::vector<LogEntry>::const_iterator;
- const_iterator begin() const { return entries.begin(); }
- const_iterator end () const { return entries.end (); }
- bool empty() const { return entries.empty(); }
+ const_iterator begin() const { return entries_.begin(); }
+ const_iterator end () const { return entries_.end (); }
+ bool empty() const { return entries_.empty(); }
private:
- std::vector<LogEntry> entries; //list of non-resolved errors and warnings
+ std::vector<LogEntry> entries_; //list of non-resolved errors and warnings
};
@@ -70,14 +70,14 @@ template <class String> inline
void ErrorLog::logMsg(const String& text, zen::MessageType type)
{
const LogEntry newEntry = { std::time(nullptr), type, copyStringTo<MsgString>(text) };
- entries.push_back(newEntry);
+ entries_.push_back(newEntry);
}
inline
int ErrorLog::getItemCount(int typeFilter) const
{
- return static_cast<int>(std::count_if(entries.begin(), entries.end(), [&](const LogEntry& e) { return e.type & typeFilter; }));
+ return static_cast<int>(std::count_if(entries_.begin(), entries_.end(), [&](const LogEntry& e) { return e.type & typeFilter; }));
}
@@ -103,7 +103,7 @@ String formatMessageImpl(const LogEntry& entry) //internal linkage
return std::wstring();
};
- String formattedText = L"[" + formatTime<String>(FORMAT_TIME, getLocalTime(entry.time)) + L"] " + copyStringTo<String>(getTypeName()) + L": ";
+ String formattedText = L"[" + formatTime<String>(FORMAT_TIME, getLocalTime(entry.time)) + L"] " + copyStringTo<String>(getTypeName()) + L": ";
const size_t prefixLen = formattedText.size();
for (auto it = entry.message.begin(); it != entry.message.end(); )
diff --git a/zen/file_error.h b/zen/file_error.h
index b318e708..18e790de 100755
--- a/zen/file_error.h
+++ b/zen/file_error.h
@@ -14,8 +14,7 @@
namespace zen
{
-//A high-level exception class giving detailed context information for end users
-class FileError
+class FileError //A high-level exception class giving detailed context information for end users
{
public:
explicit FileError(const std::wstring& msg) : msg_(msg) {}
@@ -28,7 +27,7 @@ private:
std::wstring msg_;
};
-#define DEFINE_NEW_FILE_ERROR(X) struct X : public FileError { X(const std::wstring& msg) : FileError(msg) {} X(const std::wstring& msg, const std::wstring& descr) : FileError(msg, descr) {} };
+#define DEFINE_NEW_FILE_ERROR(X) struct X : public zen::FileError { X(const std::wstring& msg) : FileError(msg) {} X(const std::wstring& msg, const std::wstring& descr) : FileError(msg, descr) {} };
DEFINE_NEW_FILE_ERROR(ErrorTargetExisting);
//DEFINE_NEW_FILE_ERROR(ErrorTargetPathMissing);
diff --git a/zen/format_unit.cpp b/zen/format_unit.cpp
index c0667fb1..e62c9286 100755
--- a/zen/format_unit.cpp
+++ b/zen/format_unit.cpp
@@ -39,7 +39,7 @@ std::wstring zen::formatThreeDigitPrecision(double value)
}
-std::wstring zen::filesizeToShortString(int64_t size)
+std::wstring zen::formatFilesizeShort(int64_t size)
{
//if (size < 0) return _("Error"); -> really?
@@ -122,7 +122,7 @@ std::wstring roundToBlock(double timeInHigh,
}
-std::wstring zen::remainingTimeToString(double timeInSec)
+std::wstring zen::formatRemainingTime(double timeInSec)
{
const int steps10[] = { 1, 2, 5, 10 };
const int steps24[] = { 1, 2, 3, 4, 6, 8, 12, 24 };
@@ -154,7 +154,7 @@ std::wstring zen::remainingTimeToString(double timeInSec)
//}
-std::wstring zen::fractionToString(double fraction)
+std::wstring zen::formatFraction(double fraction)
{
return printNumber<std::wstring>(L"%.2f", fraction * 100.0) + L'%'; //no need to internationalize fraction!?
}
@@ -188,7 +188,7 @@ std::wstring zen::ffs_Impl::includeNumberSeparator(const std::wstring& number)
}
-std::wstring zen::utcToLocalTimeString(int64_t utcTime)
+std::wstring zen::formatUtcToLocalTime(int64_t utcTime)
{
auto errorMsg = [&] { return _("Error") + L" (time_t: " + numberTo<std::wstring>(utcTime) + L")"; };
diff --git a/zen/format_unit.h b/zen/format_unit.h
index 336df74c..3dcc6858 100755
--- a/zen/format_unit.h
+++ b/zen/format_unit.h
@@ -15,16 +15,16 @@
namespace zen
{
-std::wstring filesizeToShortString(int64_t filesize);
-std::wstring remainingTimeToString(double timeInSec);
-std::wstring fractionToString(double fraction); //within [0, 1]
-std::wstring utcToLocalTimeString(int64_t utcTime); //like Windows Explorer would...
+std::wstring formatFilesizeShort(int64_t filesize);
+std::wstring formatRemainingTime(double timeInSec);
+std::wstring formatFraction(double fraction); //within [0, 1]
+std::wstring formatUtcToLocalTime(int64_t utcTime); //like Windows Explorer would...
std::wstring formatTwoDigitPrecision (double value); //format with fixed number of digits
std::wstring formatThreeDigitPrecision(double value); //(unless value is too large)
template <class NumberType>
-std::wstring toGuiString(NumberType number); //format integer number including thousands separator
+std::wstring formatNumber(NumberType number); //format integer number including thousands separator
@@ -43,7 +43,7 @@ std::wstring includeNumberSeparator(const std::wstring& number);
}
template <class NumberType> inline
-std::wstring toGuiString(NumberType number)
+std::wstring formatNumber(NumberType number)
{
static_assert(IsInteger<NumberType>::value, "");
return ffs_Impl::includeNumberSeparator(zen::numberTo<std::wstring>(number));
diff --git a/zen/i18n.h b/zen/i18n.h
index ebe22459..e6d97b7b 100755
--- a/zen/i18n.h
+++ b/zen/i18n.h
@@ -106,7 +106,7 @@ std::wstring translate(const std::wstring& singular, const std::wstring& plural,
return translation;
}
//fallback:
- return replaceCpy(std::abs(n64) == 1 ? singular : plural, L"%x", toGuiString(n));
+ return replaceCpy(std::abs(n64) == 1 ? singular : plural, L"%x", formatNumber(n));
}
}
diff --git a/zen/process_priority.h b/zen/process_priority.h
index 07679b0c..ac96a8ae 100755
--- a/zen/process_priority.h
+++ b/zen/process_priority.h
@@ -3,13 +3,13 @@
// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
// *****************************************************************************
+
#ifndef PROCESS_PRIORITY_H_83421759082143245
#define PROCESS_PRIORITY_H_83421759082143245
#include <memory>
#include "file_error.h"
-
namespace zen
{
//signal a "busy" state to the operating system
@@ -20,7 +20,7 @@ public:
~PreventStandby();
private:
struct Impl;
- const std::unique_ptr<Impl> pimpl;
+ const std::unique_ptr<Impl> pimpl_;
};
//lower CPU and file I/O priorities
@@ -31,7 +31,7 @@ public:
~ScheduleForBackgroundProcessing();
private:
struct Impl;
- const std::unique_ptr<Impl> pimpl;
+ const std::unique_ptr<Impl> pimpl_;
};
}
diff --git a/zen/shell_execute.h b/zen/shell_execute.h
index 7dcd6653..077f18e7 100755
--- a/zen/shell_execute.h
+++ b/zen/shell_execute.h
@@ -39,12 +39,23 @@ void shellExecute(const Zstring& command, ExecutionType type) //throw FileError
if (type == EXEC_TYPE_SYNC)
{
//Posix::system - execute a shell command
- int rv = ::system(command.c_str()); //do NOT use std::system as its documentation says nothing about "WEXITSTATUS(rv)", ect...
+ const int rv = ::system(command.c_str()); //do NOT use std::system as its documentation says nothing about "WEXITSTATUS(rv)", ect...
if (rv == -1 || WEXITSTATUS(rv) == 127) //http://linux.die.net/man/3/system "In case /bin/sh could not be executed, the exit status will be that of a command that does exit(127)"
throw FileError(_("Incorrect command line:") + L"\n" + utfTo<std::wstring>(command));
}
else
- runAsync([=] { int rv = ::system(command.c_str()); (void)rv; });
+ {
+ runAsync([=] { int rv = ::system(command.c_str()); (void)rv; });
+
+ warn_static("finish:")
+
+
+
+
+
+
+
+ }
}
}
}
diff --git a/zen/shutdown.cpp b/zen/shutdown.cpp
new file mode 100755
index 00000000..b21ab8db
--- /dev/null
+++ b/zen/shutdown.cpp
@@ -0,0 +1,62 @@
+// *****************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
+// *****************************************************************************
+
+#include "shutdown.h"
+ #include <zen/shell_execute.h>
+
+
+using namespace zen;
+
+
+
+
+void zen::shutdownSystem() //throw FileError
+{
+ //https://linux.die.net/man/2/reboot => needs admin rights!
+
+ //should work without admin rights:
+ shellExecute("sleep 1; systemctl poweroff", EXEC_TYPE_ASYNC); //throw FileError
+ //sleep 1: give FFS some time to properly shut down!
+ //Linux: main thread will wait on detached threads!
+ warn_static("get rid of shellExecute's thread implementation!")
+
+}
+
+
+void zen::suspendSystem() //throw FileError
+{
+ //should work without admin rights:
+ shellExecute("systemctl suspend", EXEC_TYPE_ASYNC); //throw FileError
+
+}
+
+/*
+Command line alternatives:
+
+#ifdef ZEN_WIN
+#ifdef ZEN_WIN_VISTA_AND_LATER
+ Shut down: shutdown /s /t 60
+ Sleep: rundll32.exe powrprof.dll,SetSuspendState Sleep
+ Log off: shutdown /l
+#else //XP
+ Shut down: shutdown -s -t 60
+ Standby: rundll32.exe powrprof.dll,SetSuspendState //this triggers standby OR hibernate, depending on whether hibernate setting is active! no suspend on XP?
+ Log off: shutdown -l
+#endif
+
+#elif defined ZEN_LINUX
+ Shut down: systemctl poweroff //alternative requiring admin: sudo shutdown -h 1
+ Sleep: systemctl suspend //alternative requiring admin: sudo pm-suspend
+ Log off: gnome-session-quit --no-prompt
+ //alternative requiring admin: sudo killall Xorg
+ //alternative without admin: dbus-send --session --print-reply --dest=org.gnome.SessionManager /org/gnome/SessionManager org.gnome.SessionManager.Logout uint32:1
+
+#elif defined ZEN_MAC
+ Shut down: osascript -e 'tell application "System Events" to shut down'
+ Sleep: osascript -e 'tell application "System Events" to sleep'
+ Log off: osascript -e 'tell application "System Events" to log out'
+#endif
+*/
diff --git a/zen/shutdown.h b/zen/shutdown.h
new file mode 100755
index 00000000..e64dee41
--- /dev/null
+++ b/zen/shutdown.h
@@ -0,0 +1,18 @@
+// *****************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
+// *****************************************************************************
+
+#ifndef SHUTDOWN_H_3423847870238407783265
+#define SHUTDOWN_H_3423847870238407783265
+
+#include "file_error.h"
+
+namespace zen
+{
+void shutdownSystem(); //throw FileError
+void suspendSystem(); //
+}
+
+#endif //SHUTDOWN_H_3423847870238407783265
diff --git a/zen/sys_error.cpp b/zen/sys_error.cpp
new file mode 100755
index 00000000..fd4c8f1e
--- /dev/null
+++ b/zen/sys_error.cpp
@@ -0,0 +1,6 @@
+// *****************************************************************************
+// * This file is part of the FreeFileSync project. It is distributed under *
+// * GNU General Public License: http://www.gnu.org/licenses/gpl-3.0 *
+// * Copyright (C) Zenju (zenju AT freefilesync DOT org) - All Rights Reserved *
+// *****************************************************************************
+
diff --git a/zen/sys_error.h b/zen/sys_error.h
index 026a3be5..f4361e69 100755
--- a/zen/sys_error.h
+++ b/zen/sys_error.h
@@ -26,6 +26,8 @@ ErrorCode getLastError();
std::wstring formatSystemError(const std::wstring& functionName, ErrorCode ec);
std::wstring formatSystemError(const std::wstring& functionName, const std::wstring& errorCode, const std::wstring& errorMsg);
+
+
//A low-level exception class giving (non-translated) detail information only - same conceptional level like "GetLastError()"!
class SysError
{
@@ -37,7 +39,7 @@ private:
std::wstring msg_;
};
-#define DEFINE_NEW_SYS_ERROR(X) struct X : public SysError { X(const std::wstring& msg) : SysError(msg) {} };
+#define DEFINE_NEW_SYS_ERROR(X) struct X : public zen::SysError { X(const std::wstring& msg) : SysError(msg) {} };
diff --git a/zen/time.h b/zen/time.h
index 3323a318..2ac67399 100755
--- a/zen/time.h
+++ b/zen/time.h
@@ -191,11 +191,11 @@ bool isValid(const std::tm& t)
auto inRange = [](int value, int minVal, int maxVal) { return minVal <= value && value <= maxVal; };
//http://www.cplusplus.com/reference/clibrary/ctime/tm/
- return inRange(t.tm_sec , 0, 61) &&
- inRange(t.tm_min , 0, 59) &&
+ return inRange(t.tm_sec, 0, 61) &&
+ inRange(t.tm_min, 0, 59) &&
inRange(t.tm_hour, 0, 23) &&
inRange(t.tm_mday, 1, 31) &&
- inRange(t.tm_mon , 0, 11) &&
+ inRange(t.tm_mon, 0, 11) &&
//tm_year
inRange(t.tm_wday, 0, 6) &&
inRange(t.tm_yday, 0, 365);
diff --git a/zen/zstring.cpp b/zen/zstring.cpp
index 6b41af13..fb62424a 100755
--- a/zen/zstring.cpp
+++ b/zen/zstring.cpp
@@ -74,9 +74,12 @@ int cmpStringNaturalLinux(const char* lhs, size_t lhsLen, const char* rhs, size_
- compare strings after conceptually creating blocks of whitespace/numbers/text
- implement strict weak ordering!
- don't follow broken "strnatcasecmp": https://github.com/php/php-src/blob/master/ext/standard/strnatcmp.c
- 1. incorrect non-ASCII CI-comparison 2. incorrect bounds checks
- 3. incorrect trimming of *all* whitespace 4. arbitrary handling of leading 0 only at string begin
- 5. incorrect handling of whitespace following a number 6. code is a mess
+ 1. incorrect non-ASCII CI-comparison
+ 2. incorrect bounds checks
+ 3. incorrect trimming of *all* whitespace
+ 4. arbitrary handling of leading 0 only at string begin
+ 5. incorrect handling of whitespace following a number
+ 6. code is a mess
*/
for (;;)
{
diff --git a/zen/zstring.h b/zen/zstring.h
index 273efd2f..33f48990 100755
--- a/zen/zstring.h
+++ b/zen/zstring.h
@@ -72,6 +72,17 @@ S ciReplaceCpy(const S& str, const T& oldTerm, const U& newTerm);
+//common unicode sequences
+const wchar_t EM_DASH = L'\u2014';
+const wchar_t* const SPACED_DASH = L" \u2013 "; //using 'EN DASH'
+const wchar_t LTR_MARK = L'\u200E'; //UTF-8: E2 80 8E
+const wchar_t RTL_MARK = L'\u200F'; //UTF-8: E2 80 8F
+const wchar_t ELLIPSIS = L'\u2026'; //"..."
+
+
+
+
+
//################################# inline implementation ########################################
inline
bgstack15