From 7652b3d64a63c587f520633364412345083210d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 28 Dec 2013 02:03:53 +0100 Subject: Various updater fixes Updater tests for path utils The updater now doesn't use splitpath on Windows (fixes problems with Windows XP) Fix up paths for the OSX updater - should now install the updates into the right place Fix translations install path - translation isntall and deploy should be fixed --- mmc_updater/src/FileUtils.cpp | 44 ++----------------------------- mmc_updater/src/tests/CMakeLists.txt | 19 ++++++++----- mmc_updater/src/tests/TestFileUtils.cpp | 33 +++++++++++++++++++++-- mmc_updater/src/tests/TestParseScript.cpp | 2 +- mmc_updater/src/tests/test.manifest | 27 +++++++++++++++++++ mmc_updater/src/tests/test.rc | 28 ++++++++++++++++++++ 6 files changed, 101 insertions(+), 52 deletions(-) create mode 100644 mmc_updater/src/tests/test.manifest create mode 100644 mmc_updater/src/tests/test.rc (limited to 'mmc_updater') diff --git a/mmc_updater/src/FileUtils.cpp b/mmc_updater/src/FileUtils.cpp index 10435e49..712c0c5d 100644 --- a/mmc_updater/src/FileUtils.cpp +++ b/mmc_updater/src/FileUtils.cpp @@ -10,6 +10,8 @@ #include #include #include +// this actually works with mingw32, which we use. +#include #ifdef PLATFORM_UNIX #include @@ -19,7 +21,6 @@ #include #include #include -#include #endif FileUtils::IOException::IOException(const std::string& error) @@ -249,59 +250,18 @@ void FileUtils::removeFile(const char* src) throw (IOException) std::string FileUtils::fileName(const char* path) { -#ifdef PLATFORM_UNIX char* pathCopy = strdup(path); std::string basename = ::basename(pathCopy); free(pathCopy); return basename; -#else - char baseName[MAX_PATH]; - char extension[MAX_PATH]; - _splitpath_s(path, - 0, /* drive */ - 0, /* drive length */ - 0, /* dir */ - 0, /* dir length */ - baseName, - MAX_PATH, /* baseName length */ - extension, - MAX_PATH /* extension length */ - ); - return std::string(baseName) + std::string(extension); -#endif } std::string FileUtils::dirname(const char* path) { -#ifdef PLATFORM_UNIX char* pathCopy = strdup(path); std::string dirname = ::dirname(pathCopy); free(pathCopy); return dirname; -#else - char drive[3]; - char dir[MAX_PATH]; - - _splitpath_s(path, - drive, /* drive */ - 3, /* drive length */ - dir, - MAX_PATH, /* dir length */ - 0, /* filename */ - 0, /* filename length */ - 0, /* extension */ - 0 /* extension length */ - ); - - std::string result; - if (drive[0]) - { - result += std::string(drive); - } - result += dir; - - return result; -#endif } void FileUtils::touch(const char* path) throw (IOException) diff --git a/mmc_updater/src/tests/CMakeLists.txt b/mmc_updater/src/tests/CMakeLists.txt index 1d62214e..79402245 100644 --- a/mmc_updater/src/tests/CMakeLists.txt +++ b/mmc_updater/src/tests/CMakeLists.txt @@ -29,13 +29,18 @@ endforeach() # Add unit test binaries macro(ADD_UPDATER_TEST CLASS) - set(TEST_TARGET updater_${CLASS}) - add_executable(${TEST_TARGET} ${CLASS}.cpp) - target_link_libraries(${TEST_TARGET} updatershared) - add_test(NAME ${TEST_TARGET} COMMAND ${TEST_TARGET}) - if (APPLE) - set_target_properties(${TEST_TARGET} PROPERTIES LINK_FLAGS "-framework Security -framework Cocoa") - endif() + set(TEST_TARGET updater_${CLASS}) + unset(srcs) + list(APPEND srcs ${CLASS}.cpp) + if (WIN32) + list(APPEND srcs ${CMAKE_CURRENT_SOURCE_DIR}/test.rc) + endif() + add_executable(${TEST_TARGET} ${srcs}) + target_link_libraries(${TEST_TARGET} updatershared) + add_test(NAME ${TEST_TARGET} COMMAND ${TEST_TARGET}) + if (APPLE) + set_target_properties(${TEST_TARGET} PROPERTIES LINK_FLAGS "-framework Security -framework Cocoa") + endif() endmacro() add_updater_test(TestParseScript) diff --git a/mmc_updater/src/tests/TestFileUtils.cpp b/mmc_updater/src/tests/TestFileUtils.cpp index 709acc5c..f8535a28 100644 --- a/mmc_updater/src/tests/TestFileUtils.cpp +++ b/mmc_updater/src/tests/TestFileUtils.cpp @@ -5,10 +5,39 @@ void TestFileUtils::testDirName() { + std::string dirName; + std::string fileName; + #ifdef PLATFORM_WINDOWS - std::string dirName = FileUtils::dirname("E:/Some Dir/App.exe"); - TEST_COMPARE(dirName,"E:/Some Dir/"); + // absolute paths + dirName = FileUtils::dirname("E:/Some Dir/App.exe"); + TEST_COMPARE(dirName,"E:/Some Dir"); + fileName = FileUtils::fileName("E:/Some Dir/App.exe"); + TEST_COMPARE(fileName,"App.exe"); + + dirName = FileUtils::dirname("C:/Users/kitteh/AppData/Local/Temp/MultiMC5-yidaaa/MultiMC.exe"); + TEST_COMPARE(dirName,"C:/Users/kitteh/AppData/Local/Temp/MultiMC5-yidaaa"); + fileName = FileUtils::fileName("C:/Users/kitteh/AppData/Local/Temp/MultiMC5-yidaaa/MultiMC.exe"); + TEST_COMPARE(fileName,"MultiMC.exe"); + +#else + // absolute paths + dirName = FileUtils::dirname("/home/tester/foo bar/baz"); + TEST_COMPARE(dirName,"/home/tester/foo bar"); + fileName = FileUtils::fileName("/home/tester/foo bar/baz"); + TEST_COMPARE(fileName,"baz"); #endif + // current directory + dirName = FileUtils::dirname("App.exe"); + TEST_COMPARE(dirName,"."); + fileName = FileUtils::fileName("App.exe"); + TEST_COMPARE(fileName,"App.exe"); + + // relative paths + dirName = FileUtils::dirname("Foo/App.exe"); + TEST_COMPARE(dirName,"Foo"); + fileName = FileUtils::fileName("Foo/App.exe"); + TEST_COMPARE(fileName,"App.exe"); } void TestFileUtils::testIsRelative() diff --git a/mmc_updater/src/tests/TestParseScript.cpp b/mmc_updater/src/tests/TestParseScript.cpp index f4453957..e8087b33 100644 --- a/mmc_updater/src/tests/TestParseScript.cpp +++ b/mmc_updater/src/tests/TestParseScript.cpp @@ -10,7 +10,7 @@ void TestParseScript::testParse() { UpdateScript script; - script.parse("file_list.xml"); + script.parse("mmc_updater/src/tests/file_list.xml"); TEST_COMPARE(script.isValid(),true); } diff --git a/mmc_updater/src/tests/test.manifest b/mmc_updater/src/tests/test.manifest new file mode 100644 index 00000000..8b4dbb98 --- /dev/null +++ b/mmc_updater/src/tests/test.manifest @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + Custom Minecraft launcher for managing multiple installs. + + + + + + + + + + + \ No newline at end of file diff --git a/mmc_updater/src/tests/test.rc b/mmc_updater/src/tests/test.rc new file mode 100644 index 00000000..a288dba6 --- /dev/null +++ b/mmc_updater/src/tests/test.rc @@ -0,0 +1,28 @@ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include + +1 RT_MANIFEST "test.manifest" + +VS_VERSION_INFO VERSIONINFO +FILEVERSION 1,0,0,0 +FILEOS VOS_NT_WINDOWS32 +FILETYPE VFT_APP +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "CompanyName", "MultiMC Contributors" + VALUE "FileDescription", "Testcase" + VALUE "FileVersion", "1.0.0.0" + VALUE "ProductName", "MultiMC Testcase" + VALUE "ProductVersion", "5" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0000, 0x04b0 // Unicode + END +END -- cgit v1.2.3