Skip to content

Commit

Permalink
Windows: fix compilation and add wmain to Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKepzie committed Oct 7, 2016
1 parent 0025874 commit bb22bbe
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 130 deletions.
11 changes: 10 additions & 1 deletion App/NatronApp_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ NATRON_NAMESPACE_USING
#ifdef Q_OS_WIN
// g++ knows nothing about wmain
// https://sourceforge.net/p/mingw-w64/wiki2/Unicode%20apps/
// If it fails to compile it means either UNICODE or _UNICODE is not defined (it should be in global.pri) and
// the project is not linking against -municode
extern "C" {
int wmain(int argc, wchar_t** argv)
#else
Expand Down Expand Up @@ -94,7 +96,11 @@ int main(int argc, char *argv[])
AppManager manager;

// coverity[tainted_data]
#ifdef Q_OS_WIN
if ( !manager.loadW(argc, argv, args) ) {
#else
if ( !manager.load(argc, argv, args) ) {
#endif
return 1;
} else {
return 0;
Expand All @@ -103,8 +109,11 @@ int main(int argc, char *argv[])
GuiApplicationManager manager;

// coverity[tainted_data]
#ifdef Q_OS_WIN
return manager.loadW(argc, argv, args);
#else
return manager.load(argc, argv, args);

#endif
//exec() is called within the GuiApplicationManager
}
} // main
Expand Down
9 changes: 5 additions & 4 deletions Engine/AppManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

#include "Global/ProcInfo.h"
#include "Global/GLIncludes.h"
#include "Global/StrUtils.h"

#include "Engine/AppInstance.h"
#include "Engine/Backdrop.h"
Expand Down Expand Up @@ -454,7 +455,7 @@ AppManager::load(int argc,
}

bool
AppManager::load(int argc,
AppManager::loadW(int argc,
wchar_t **argv,
const CLArgs& cl)
{
Expand Down Expand Up @@ -2913,11 +2914,11 @@ AppManager::initPython()

#ifndef IS_PYTHON_2
#ifdef __NATRON_WIN32__
static const std::wstring pythonHome( Global::utf8_to_utf16(".") );
static const std::wstring pythonHome( StrUtils::utf8_to_utf16(".") );
#elif defined(__NATRON_LINUX__)
static const std::wstring pythonHome( Global::utf8_to_utf16("../lib") );
static const std::wstring pythonHome( StrUtils::utf8_to_utf16("../lib") );
#elif defined(__NATRON_OSX__)
static const std::wstring pythonHome( Global::utf8_to_utf16("../Frameworks/Python.framework/Versions/" NATRON_PY_VERSION_STRING "/lib") );
static const std::wstring pythonHome( StrUtils::utf8_to_utf16("../Frameworks/Python.framework/Versions/" NATRON_PY_VERSION_STRING "/lib") );
#endif
Py_SetPythonHome( const_cast<wchar_t*>( pythonHome.c_str() ) );
PySys_SetArgv( argc, &_imp->args.front() ); /// relative module import
Expand Down
2 changes: 1 addition & 1 deletion Engine/AppManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ GCC_DIAG_SUGGEST_OVERRIDE_ON
* main process.
**/
bool load( int argc, char **argv, const CLArgs& cl);
bool load( int argc, wchar_t **argv, const CLArgs& cl);
bool loadW( int argc, wchar_t **argv, const CLArgs& cl);

private:

Expand Down
3 changes: 2 additions & 1 deletion Engine/AppManagerPrivate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ GCC_DIAG_ON(unused-parameter)
#include "Global/GlobalDefines.h"
#include "Global/GLIncludes.h"
#include "Global/ProcInfo.h"
#include "Global/StrUtils.h"

#include "Engine/FStreamsSupport.h"
#include "Engine/CacheSerialization.h"
Expand Down Expand Up @@ -903,7 +904,7 @@ AppManagerPrivate::handleCommandLineArgsW(int argc, wchar_t** argv)
if (argv) {
for (int i = 0; i < argc; ++i) {
std::wstring ws(argv[i]);
utf8Args.push_back(Global::utf16_to_utf8(ws));
utf8Args.push_back(StrUtils::utf16_to_utf8(ws));
}
} else {
// If the user didn't specify launch arguments (e.g unit testing),
Expand Down
4 changes: 3 additions & 1 deletion Engine/CLArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "Global/GlobalDefines.h"
#include "Global/GitVersion.h"
#include "Global/QtCompat.h"
#include "Global/StrUtils.h"

#include "Engine/AppManager.h"

NATRON_NAMESPACE_ENTER;
Expand Down Expand Up @@ -1152,7 +1154,7 @@ CLArgs::ensureCommandLineArgsUtf8(int argc, char **argv, std::vector<std::string
wchar_t** argList = CommandLineToArgvW(GetCommandLineW(), &nArgsOut);
for (int i = 0; i < nArgsOut; ++i) {
std::wstring wide(argList[i]);
utf8Args->push_back(Global::utf16_to_utf8(wide));
utf8Args->push_back(StrUtils::utf16_to_utf8(wide));
if (argv) {
std::cout << "Non UTF-8 arg: " << argv[i] << std::endl;
}
Expand Down
5 changes: 3 additions & 2 deletions Engine/Cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "Global/GlobalDefines.h"
#include "Global/MemoryInfo.h"
#include "Global/StrUtils.h"

GCC_DIAG_OFF(deprecated)
#include <QtCore/QMutex>
Expand Down Expand Up @@ -1397,7 +1398,7 @@ class Cache
QString getCachePath() const OVERRIDE FINAL WARN_UNUSED_RETURN
{
QString cacheFolderName( appPTR->getDiskCacheLocation() );
Global::ensureLastPathSeparator(cacheFolderName);
StrUtils::ensureLastPathSeparator(cacheFolderName);

cacheFolderName.append( QString::fromUtf8( cacheName().c_str() ) );

Expand All @@ -1407,7 +1408,7 @@ class Cache
std::string getRestoreFilePath() const
{
QString newCachePath( getCachePath() );
Global::ensureLastPathSeparator(newCachePath);
StrUtils::ensureLastPathSeparator(newCachePath);

newCachePath.append( QString::fromUtf8("restoreFile." NATRON_CACHE_FILE_EXT) );

Expand Down
3 changes: 2 additions & 1 deletion Engine/CacheEntry.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include <SequenceParsing.h> // for removePath
#include "Engine/EngineFwd.h"
#include "Global/GlobalDefines.h"
#include "Global/StrUtils.h"

NATRON_NAMESPACE_ENTER;

Expand Down Expand Up @@ -282,7 +283,7 @@ class CacheAPI
{
#ifdef _WIN32
WIN32_FIND_DATAW FindFileData;
std::wstring wpath = Global::utf8_to_utf16 (filename);
std::wstring wpath = StrUtils::utf8_to_utf16 (filename);
HANDLE handle = FindFirstFileW(wpath.c_str(), &FindFileData);
if (handle != INVALID_HANDLE_VALUE) {
FindClose(handle);
Expand Down
2 changes: 2 additions & 0 deletions Engine/Engine.pro
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ SOURCES += \
WriteNode.cpp \
../Global/glad_source.c \
../Global/ProcInfo.cpp \
../Global/StrUtils.cpp \
../libs/SequenceParsing/SequenceParsing.cpp \
NatronEngine/natronengine_module_wrapper.cpp \
NatronEngine/natron_namespace_wrapper.cpp \
Expand Down Expand Up @@ -443,6 +444,7 @@ HEADERS += \
../Global/MemoryInfo.h \
../Global/ProcInfo.h \
../Global/QtCompat.h \
../Global/StrUtils.h \
../libs/SequenceParsing/SequenceParsing.h \
../libs/OpenFX/include/ofxCore.h \
../libs/OpenFX/include/ofxDialog.h \
Expand Down
6 changes: 3 additions & 3 deletions Engine/FStreamsSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// ***** END PYTHON BLOCK ****

#include "FStreamsSupport.h"

#include "Global/StrUtils.h"

NATRON_NAMESPACE_ENTER;

Expand All @@ -36,7 +36,7 @@ FStreamsSupport::open (FStreamsSupport::ifstream *stream,
#ifdef __NATRON_WIN32__
// Windows std::ifstream accepts non-standard wchar_t*
// On MingW, we use our own FStreamsSupport::ifstream
std::wstring wpath = Global::utf8_to_utf16(path);
std::wstring wpath = StrUtils::utf8_to_utf16(path);
stream->open (wpath.c_str(), mode);
stream->seekg (0, std::ios_base::beg); // force seek, otherwise broken
#else
Expand All @@ -52,7 +52,7 @@ FStreamsSupport::open (FStreamsSupport::ofstream *stream,
#ifdef __NATRON_WIN32__
// Windows std::ofstream accepts non-standard wchar_t*
// On MingW, we use our own FStreamsSupport::ofstream
std::wstring wpath = Global::utf8_to_utf16(path);
std::wstring wpath = StrUtils::utf8_to_utf16(path);
stream->open (wpath.c_str(), mode);
#else
stream->open (path.c_str(), mode);
Expand Down
4 changes: 3 additions & 1 deletion Engine/LibraryBinary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include <stdexcept>

#include "Global/GlobalDefines.h"
#include "Global/StrUtils.h"

#ifdef __NATRON_UNIX__
#include <dlfcn.h>
#endif
Expand Down Expand Up @@ -90,7 +92,7 @@ LibraryBinary::loadBinary(const std::string & binaryPath)

_binaryPath = binaryPath;
#ifdef __NATRON_WIN32__
std::wstring ws = Global::utf8_to_utf16(binaryPath);
std::wstring ws = StrUtils::utf8_to_utf16(binaryPath);
_library = LoadLibraryW( ws.c_str() );

#elif defined(__NATRON_UNIX__)
Expand Down
5 changes: 3 additions & 2 deletions Engine/MemoryFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include <stdexcept>

#include "Global/GlobalDefines.h"
#include "Global/StrUtils.h"

#define MIN_FILE_SIZE 4096

Expand Down Expand Up @@ -230,13 +231,13 @@ MemoryFilePrivate::openInternal(MemoryFile::FileOpenModeEnum open_mode)
- R/W
********************************************************
*********************************************************/
std::wstring wpath = Global::utf8_to_utf16(path);
std::wstring wpath = StrUtils::utf8_to_utf16(path);
file_handle = ::CreateFileW(wpath.c_str(), GENERIC_READ | GENERIC_WRITE,
0, 0, windows_open_mode, FILE_ATTRIBUTE_NORMAL, 0);


if (file_handle == INVALID_HANDLE_VALUE) {
std::string winError = Global::GetLastErrorAsString();
std::string winError = StrUtils::GetLastErrorAsString();
std::string str("MemoryFile EXC : Failed to open file ");
str.append(path);
str.append(winError);
Expand Down
12 changes: 7 additions & 5 deletions Engine/Project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ GCC_DIAG_UNUSED_LOCAL_TYPEDEFS_ON
#endif
#include <ofxhXml.h> // OFX::XML::escape

#include "Global/StrUtils.h"

#include "Engine/AppInstance.h"
#include "Engine/AppManager.h"
#include "Engine/CreateNodeArgs.h"
Expand Down Expand Up @@ -191,7 +193,7 @@ Project::loadProject(const QString & path,

try {
QString realPath = path;
Global::ensureLastPathSeparator(realPath);
StrUtils::ensureLastPathSeparator(realPath);
QString realName = name;
bool isAutoSave = isUntitledAutosave;
if (!getApp()->isBackground() && !isUntitledAutosave) {
Expand Down Expand Up @@ -518,7 +520,7 @@ Project::saveProjectInternal(const QString & path,

///Use a temporary file to save, so if Natron crashes it doesn't corrupt the user save.
QString tmpFilename = StandardPaths::writableLocation(StandardPaths::eStandardLocationTemp);
Global::ensureLastPathSeparator(tmpFilename);
StrUtils::ensureLastPathSeparator(tmpFilename);
tmpFilename.append( QString::number( time.toMSecsSinceEpoch() ) );

{
Expand Down Expand Up @@ -1667,7 +1669,7 @@ Project::getLockFileInfos(const QString& projectPath,
qint64* appPID) const
{
QString realPath = projectPath;
Global::ensureLastPathSeparator(realPath);
StrUtils::ensureLastPathSeparator(realPath);
QString lockFilePath = realPath + projectName + QString::fromUtf8(".lock");
QFile f(lockFilePath);

Expand Down Expand Up @@ -1719,7 +1721,7 @@ Project::removeLastAutosave()
*/
QString projectPath = QString::fromUtf8( _imp->getProjectPath().c_str() );
QString projectFilename = QString::fromUtf8( _imp->getProjectFilename().c_str() );
Global::ensureLastPathSeparator(projectPath);
StrUtils::ensureLastPathSeparator(projectPath);
QString autoSaveFilePath = projectPath + projectFilename + QString::fromUtf8(".autosave");
if ( QFile::exists(autoSaveFilePath) ) {
QFile::remove(autoSaveFilePath);
Expand Down Expand Up @@ -1759,7 +1761,7 @@ QString
Project::autoSavesDir()
{
QString str = StandardPaths::writableLocation(StandardPaths::eStandardLocationData);
Global::ensureLastPathSeparator(str);
StrUtils::ensureLastPathSeparator(str);

str += QString::fromUtf8("Autosaves");

Expand Down
3 changes: 2 additions & 1 deletion Engine/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#endif

#include "Global/MemoryInfo.h"
#include "Global/StrUtils.h"

#include "Engine/AppManager.h"
#include "Engine/AppInstance.h"
Expand Down Expand Up @@ -89,7 +90,7 @@ static QStringList
getDefaultOcioConfigPaths()
{
QString binaryPath = appPTR->getApplicationBinaryPath();
Global::ensureLastPathSeparator(binaryPath);
StrUtils::ensureLastPathSeparator(binaryPath);

#ifdef __NATRON_LINUX__
QStringList ret;
Expand Down
Loading

0 comments on commit bb22bbe

Please sign in to comment.