Skip to content

Commit

Permalink
Moved to MSVS 2017
Browse files Browse the repository at this point in the history
Moved to WTL v10
Updated Boost
  • Loading branch information
zenden2k committed Jun 4, 2019
1 parent eeaba55 commit 63a5128
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 73 deletions.
31 changes: 15 additions & 16 deletions COMPILING.txt
@@ -1,26 +1,15 @@
============ Building Image Uploader on Windows ============

Before building you should copy file "Source\versioninfo.h.dist" to "Source\versioninfo.h". This file will be regenerated
Before building Image Uploader you should copy file "Source\versioninfo.h.dist" to "Source\versioninfo.h". This file will be regenerated
by "versioninc.py" utility and will contain information about build number, version, date, git commit hash.
Python 2.7 interpreter should be installed for performing pre-build and post-build events. Ensure that your %PATH% environment
variable includes the directory of your Python distribution.

You need CMake and Microsoft Visual Studio 2013 (with C++ compiler) or newer to build Image Uploader from source.
Installing Update 4 for Visual Studio 2013 is strongly recommended (older versions corrupt .rc files after editing)
If you are using a newer MSVC version, you may experience some compilation errors, which can be solved easily
(if you fix these errors, please provide a patch or pull request). But also you need to recompile 3rd-party
libraries (boost, glog, jsoncpp, etc) against your compiler version.
You need CMake (tested with v3.14.0) and Microsoft Visual Studio 2017 or newer (with C++ compiler) to build Image Uploader from sources.
Also you need to compile 3rd-party libraries (such as boost, glog, jsoncpp, etc) against your compiler version.

All libraries (except ffmpeg) have to be built statically with static runtime. To enable Windows XP support the corresponding
toolset has to be chosen (for example, "v120_xp" in VS 2013, "v141_xp" in Visual Studio 2017).

You can download all necessary libraries (including header-only libraries in "Include" subfolder) by following link:

https://drive.google.com/drive/folders/1dHjuif2sagpyNPoPs_EL63On1_A0m98N?usp=sharing

Precompiled libraries for MS Visual Studio 2013 (not compatible with newer MSVS versions):

https://drive.google.com/file/d/1jJM9NLEPfdPLCjh_dOTx1O9S7bonjsr2/view?usp=drivesdk
All libraries (except ffmpeg) can be built statically with static runtime (/MT option for VC++ compiler).
To enable Windows XP support the corresponding toolset has to be chosen (for example "v141_xp" in Visual Studio 2017).

To generate Visual Studio solution from CMakeLists.txt you need to create a directory for
temporary files and call cmake:
Expand All @@ -32,6 +21,16 @@ cmake <path_to_imageuploader_source>\Source
The last command will generate project files for your default compiler (should be Visual Studio).
You can use CMake GUI to achieve the same result.

If you are using v141_xp toolset, for fixing broken _stat() function on Windows XP you should change
the "TargetUniversalCRTVersion" option in file
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Common.props"
to the latest Windows 10 SDK version installed on your computer. Tested with Windows SDK 10.0.17763.0 .

You can download all necessary libraries (including header-only libraries in "Include" subfolder) by following link:

https://drive.google.com/drive/folders/1dHjuif2sagpyNPoPs_EL63On1_A0m98N?usp=sharing


Image Uploader is using the following libraries:

WTL http://sourceforge.net/projects/wtl/
Expand Down
15 changes: 6 additions & 9 deletions Contrib/Source/curl-notes.txt
@@ -1,26 +1,23 @@
cd winbuild
nmake /f Makefile.vc mode=static VC=12 ENABLE_WINSSL=yes WITH_ZLIB=static DEBUG=no ENABLE_IDN=no RTLIBCFG=static
nmake /f Makefile.vc mode=static VC=12 WITH_SSL=static WITH_ZLIB=static DEBUG=yes ENABLE_IDN=no RTLIBCFG=static
nmake /f Makefile.vc mode=static VC=12 ENABLE_WINSSL=yes WITH_ZLIB=static DEBUG=yes ENABLE_IDN=no RTLIBCFG=static

nmake /f Makefile.vc mode=static VC=14 ENABLE_WINSSL=yes WITH_ZLIB=static DEBUG=no ENABLE_IDN=no RTLIBCFG=shared

nmake /f Makefile.vc mode=static VC=9 WITH_SSL=static WITH_ZLIB=static DEBUG=no ENABLE_IDN=no
#nmake /f Makefile.vc mode=static VC=9 ENABLE_WINSSL=yes WITH_ZLIB=static DEBUG=no ENABLE_IDN=no

nmake /f Makefile.vc mode=static VC=9 ENABLE_WINSSL=yes WITH_ZLIB=static DEBUG=no ENABLE_IDN=no
nmake /E CC="cl /D_USING_V120_SDK71_ /D_WIN32_WINNT=0x0501" /f Makefile.vc mode=static VC=12 ENABLE_WINSSL=yes WITH_ZLIB=static DEBUG=no ENABLE_IDN=no RTLIBCFG=static

nmake /f Makefile.vc mode=static VC=15 ENABLE_WINSSL=yes ENABLE_IPV6=yes WITH_ZLIB=static DEBUG=yes ENABLE_IDN=no ENABLE_SSPI=yes RTLIBCFG=static MACHINE=x86

nmake /E CC="cl /D_USING_V120_SDK71_ /D_WIN32_WINNT=0x0501" /f Makefile.vc mode=static VC=12 ENABLE_WINSSL=yes WITH_ZLIB=static DEBUG=no ENABLE_IDN=no RTLIBCFG=static

\lib\config-win32.h
Add to "lib\config-win32.h"


#undef WINVER
#define WINVER 0x0501
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501

Comment entire block starting with:

#if defined(_MSC_VER) && (_MSC_VER >= 1700)

Patch http.c !

Expand Down
5 changes: 1 addition & 4 deletions Contrib/Source/ffmpeg-notes.txt
Expand Up @@ -9,16 +9,13 @@ pacman -s yasm diffutils
Finally, run:

For MSVC:
./configure --enable-asm --enable-yasm --arch=i386 --disable-ffserver --disable-avdevice --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffmpeg --enable-shared --disable-static --disable-bzlib --disable-libopenjpeg --disable-iconv --prefix=/c/ffmpeg --disable-encoders --disable-muxers --disable-filters --disable-devices --disable-swresample --disable-avfilter --disable-network --toolchain=msvc
./configure --enable-asm --enable-yasm --arch=i386 --disable-avdevice --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffmpeg --enable-shared --disable-static --disable-bzlib --disable-libopenjpeg --disable-iconv --prefix=/c/ffmpeg --disable-encoders --disable-muxers --disable-filters --disable-devices --disable-swresample --disable-avfilter --disable-network --toolchain=msvc

For ICL:
./configure --toolchain=icl

make
make install

Note:
configure script is modified for VS 2008 support.
Configure may fail to detect headers, so you must edit config.h and set

#define HAVE_DIRECT_H 1
Expand Down
7 changes: 5 additions & 2 deletions Source/CMakeLists.txt
Expand Up @@ -34,11 +34,14 @@ set(IU_USE_OPENSSL OFF CACHE BOOL "Use OpenSSL library for secured connections")
if (MSVC)
set(IU_STATIC_RUNTIME ON CACHE BOOL "Use static runtime")
add_definitions("/MP")
add_compile_options(/wd4091) # disable warning C4091: 'typedef ': ignored on left of '*' when no variable is declared
endif()

if (MSVC AND IU_STATIC_RUNTIME)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} /MT")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /MT")
endif()

#SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SUBSYSTEM:CONSOLE,5.01")
Expand Down Expand Up @@ -111,10 +114,10 @@ if(WIN32)
endif()

if (IU_USE_OPENSSL)
list(APPEND COMMON_LIBS_LIST ssleay32 libeay32)
list(APPEND COMMON_LIBS_LIST libssl libcrypto)
endif()

list(APPEND COMMON_LIBS_LIST libcurl libeay32 ssleay32 Oleacc libglog_static minizip Userenv Psapi Iphlpapi Winhttp base64 libwebpdecoder libwebpdemux zlib)
list(APPEND COMMON_LIBS_LIST libcurl Oleacc glog minizip Userenv Psapi Iphlpapi Winhttp base64 libwebpdecoder libwebpdemux zlib Crypt32 Wldap32)
else()
list(APPEND COMMON_LIBS_LIST curl ssl crypto glog pthread uv rt sqlite3 freeimage gflags ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES})
endif()
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/OutputCodeGenerator.cpp
Expand Up @@ -40,8 +40,8 @@ void ZOutputCodeGenerator::setType(CodeType type)

std::string ZOutputCodeGenerator::generate(const std::vector<ZUploadObject>& items)
{
std::string result ="";
for(int i=0; i < items.size(); i++)
std::string result;
for(size_t i=0; i < items.size(); i++)
{
if(i) result += "\r\n";
result += generateCodeForItem(items[i], i);
Expand Down
86 changes: 70 additions & 16 deletions Source/Core/Scripting/API/Process.cpp
Expand Up @@ -6,10 +6,39 @@
#include "ScriptAPI.h"
#include "../Squirrelnc.h"

#ifdef _WIN32
#include <boost/process/windows.hpp>
#include <boost/winapi/process.hpp>
#include <boost/winapi/show_window.hpp>
#include <boost/winapi/basic_types.hpp>
#endif
namespace ScriptAPI {

namespace bp = ::boost::process;

// Thanks to https://stackoverflow.com/questions/43582022/boostprocess-hide-console-on-windows

struct show_window
: ::boost::process::detail::handler_base
{
private:
::boost::winapi::WORD_ const m_flag;

public: explicit
show_window(bool const show) noexcept
: m_flag{ show ? ::boost::winapi::SW_SHOWNORMAL_ : ::boost::winapi::SW_HIDE_ }
{}

// this function will be invoked at child process constructor before spawning process
template <class WindowsExecutor>
void on_setup(WindowsExecutor &e) const
{
// we have a chance to adjust startup info
e.startup_info.dwFlags |= ::boost::winapi::STARTF_USESHOWWINDOW_;
e.startup_info.wShowWindow |= m_flag;
}
};

class ProcessPrivate {
public:
ProcessPrivate() :readProcessOutput_(false), hidden_(false)
Expand All @@ -30,7 +59,7 @@ class ProcessPrivate {

try
{
#ifdef _WIN32
/*#ifdef _WIN32
bp::win32_context ctx;
STARTUPINFO si;
if (hidden_ )
Expand All @@ -48,12 +77,19 @@ class ProcessPrivate {
#endif
ctx.stdout_behavior = readProcessOutput_ ? bp::capture_stream() : bp::silence_stream();
ctx.environment = boost::process::self::get_environment();
#ifdef _WIN32
ctx.environment = boost::process::self::get_environment();*/

if (readProcessOutput_) {
inputStream_ = std::make_unique<bp::ipstream>();
child_.reset(new bp::child(executable_, bp::args(args), show_window{ !hidden_ }, bp::std_out > *inputStream_));
} else {
child_.reset(new bp::child(executable_, bp::args(args), show_window{ !hidden_ }));
}
/*#ifdef _WIN32
child_.reset(new bp::win32_child(bp::win32_launch(executable_, args, ctx)));
#else
child_.reset(new bp::child(bp::launch(executable_, args, ctx)));
#endif
#endif*/
}
catch (std::exception & ex){
LOG(ERROR) << ex.what();
Expand All @@ -67,7 +103,7 @@ class ProcessPrivate {
{
try
{
#ifdef _WIN32
/*#ifdef _WIN32
bp::win32_context ctx;
STARTUPINFO si;
if (hidden_)
Expand All @@ -82,10 +118,25 @@ class ProcessPrivate {
#else
bp::context ctx;
#endif
ctx.stdout_behavior = readProcessOutput_ ? bp::capture_stream() : bp::silence_stream();
#endif**/
/*ctx.stdout_behavior = readProcessOutput_ ? bp::capture_stream() : bp::silence_stream();
ctx.environment = boost::process::self::get_environment();
child_.reset(new bp::child(bp::launch_shell(command, ctx)));
child_.reset(new bp::child(bp::launch_shell(command, ctx)));*/
std::vector<std::string> args = {/*IuCoreUtils::ExtractFileName*/(executable_) };
Sqrat::Array::iterator it;
while (arguments_.Next(it))
{
Sqrat::Object obj(it.getValue(), GetCurrentThreadVM());
args.push_back(obj.Cast<std::string>());
}

if (readProcessOutput_) {
inputStream_ = std::make_unique<bp::ipstream>();
bp::system(executable_, bp::args(args), show_window{ !hidden_ }, bp::std_out > *inputStream_);
}
else {
bp::system(executable_, bp::args(args), show_window{ !hidden_ });
}
}
catch (std::exception & ex){
LOG(ERROR) << ex.what();
Expand All @@ -101,10 +152,10 @@ class ProcessPrivate {
LOG(ERROR) << BOOST_CURRENT_FUNCTION << "\r\n" << "Process not started";
return;
}
bp::pistream &stream = child_->get_stdout();

std::istreambuf_iterator<char> eos;

res = std::string(std::istreambuf_iterator<char>(stream), eos);
res = std::string(std::istreambuf_iterator<char>(*inputStream_), eos);
if (!outputEncoding_.empty())
{
res = IuCoreUtils::ConvertToUtf8(res, outputEncoding_);
Expand All @@ -125,14 +176,17 @@ class ProcessPrivate {
LOG(ERROR) << BOOST_CURRENT_FUNCTION << "\r\n" << "Process not started";
return EXIT_FAILURE;
}
bp::status status = child_->wait();
return status.exited() ? status.exit_status() : EXIT_FAILURE;
std::error_code code;
/*bp::status status = */child_->wait(code);
return child_->exit_code();
// return status.exited() ? status.exit_status() : EXIT_FAILURE;
}
std::string executable_;
Sqrat::Array arguments_;
bool readProcessOutput_;
std::unique_ptr<bp::child> child_;
std::string outputEncoding_;
std::unique_ptr<bp::ipstream> inputStream_;
bool hidden_;
};

Expand All @@ -151,7 +205,7 @@ Process::Process(const std::string& executable, bool findInPath)
{
init();
try {
d_->executable_ = findInPath ? bp::find_executable_in_path(executable) : executable;
d_->executable_ = findInPath ? bp::search_path(executable).string() : executable;
} catch ( std::exception& ex )
{
LOG(ERROR) << ex.what();
Expand All @@ -173,7 +227,7 @@ bool Process::launchInShell(const std::string& command)
return d_->launchShell(command);
}

bp::child start_child(bp::context ctx)
/*bp::child start_child(bp::context ctx)
{
#if defined(BOOST_POSIX_API)
return bp::launch(std::string("env"), std::vector<std::string>(), ctx);
Expand All @@ -182,7 +236,7 @@ bp::child start_child(bp::context ctx)
#else
# error "Unsupported platform."
#endif
}
}*/

bool Process::start()
{
Expand Down Expand Up @@ -213,7 +267,7 @@ void Process::setCaptureOutput(bool read)

const std::string Process::findExecutableInPath(const std::string& executable)
{
return bp::find_executable_in_path(executable);
return bp::search_path(executable).string();
}

void Process::setOutputEncoding(const std::string& encoding)
Expand Down
15 changes: 8 additions & 7 deletions Source/Core/Upload/MegaNzUploadEngine.cpp
Expand Up @@ -37,6 +37,7 @@
#include "3rdpart/GdiplusH.h"
#include "Core/Images/Utils.h"
#endif
#include "Core/AppParams.h"

#define APP_KEY "0dxDFKqD"
#define USER_AGENT "Zenden2k Image Uploader"
Expand All @@ -48,12 +49,12 @@ using namespace mega;
class MyGfxProcessor : public mega::MegaGfxProcessor {
public:
MyGfxProcessor();
virtual bool readBitmap(const std::string& path) override;
virtual int getWidth() override;
virtual int getHeight() override;
virtual int getBitmapDataSize(int width, int height, int px, int py, int rw, int rh) override;
virtual bool getBitmapData(char *bitmapData, size_t size) override;
virtual void freeBitmap() override;
bool readBitmap(const std::string& path) override;
int getWidth() override;
int getHeight() override;
int getBitmapDataSize(int width, int height, int px, int py, int rw, int rh) override;
bool getBitmapData(char *bitmapData, size_t size) override;
void freeBitmap() override;

virtual ~MyGfxProcessor();
protected:
Expand Down Expand Up @@ -185,7 +186,7 @@ CMegaNzUploadEngine::CMegaNzUploadEngine(ServerSync* serverSync, ServerSettingsS
folderList_ = nullptr;
#ifdef _WIN32
proc_ = std::make_unique<MyGfxProcessor>();
megaApi_ = std::make_unique<MegaApi>(APP_KEY, proc_.get(), static_cast<const char *>(nullptr), USER_AGENT);
megaApi_ = std::make_unique<MegaApi>(APP_KEY, proc_.get(), static_cast<const char *>(nullptr)/*AppParams::instance()->tempDirectory().c_str()*/, USER_AGENT);
#else
megaApi_.reset(new MegaApi(APP_KEY, (const char *)NULL, USER_AGENT));
#endif
Expand Down

0 comments on commit 63a5128

Please sign in to comment.