From b773ef08afff14bf0e342578c21122758c26b680 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 15 Dec 2013 23:46:48 +0100 Subject: Fix/remove tests from the gutted updater --- mmc_updater/src/UpdateScript.h | 4 +- mmc_updater/src/UpdaterOptions.cpp | 3 +- mmc_updater/src/tests/CMakeLists.txt | 28 ++-- mmc_updater/src/tests/TestParseScript.cpp | 24 ++++ mmc_updater/src/tests/TestParseScript.h | 8 ++ mmc_updater/src/tests/TestUpdateScript.cpp | 27 ---- mmc_updater/src/tests/TestUpdateScript.h | 8 -- mmc_updater/src/tests/file_list.xml | 15 -- mmc_updater/src/tests/test-update.rb | 218 ----------------------------- mmc_updater/src/tests/v2_file_list.xml | 67 --------- 10 files changed, 45 insertions(+), 357 deletions(-) create mode 100644 mmc_updater/src/tests/TestParseScript.cpp create mode 100644 mmc_updater/src/tests/TestParseScript.h delete mode 100644 mmc_updater/src/tests/TestUpdateScript.cpp delete mode 100644 mmc_updater/src/tests/TestUpdateScript.h delete mode 100755 mmc_updater/src/tests/test-update.rb delete mode 100644 mmc_updater/src/tests/v2_file_list.xml (limited to 'mmc_updater/src') diff --git a/mmc_updater/src/UpdateScript.h b/mmc_updater/src/UpdateScript.h index c825e35d..5c863ff4 100644 --- a/mmc_updater/src/UpdateScript.h +++ b/mmc_updater/src/UpdateScript.h @@ -56,9 +56,7 @@ class UpdateScriptFile } }; -/** Stores information about the packages and files included - * in an update, parsed from an XML file. - */ +/** Stores information about the files included in an update, parsed from an XML file. */ class UpdateScript { public: diff --git a/mmc_updater/src/UpdaterOptions.cpp b/mmc_updater/src/UpdaterOptions.cpp index ae34562d..0945431b 100644 --- a/mmc_updater/src/UpdaterOptions.cpp +++ b/mmc_updater/src/UpdaterOptions.cpp @@ -142,7 +142,7 @@ void UpdaterOptions::parse(int argc, char** argv) showVersion = parser.getFlag("version"); forceElevated = parser.getFlag("force-elevated"); autoClose = parser.getFlag("auto-close"); - + if (installDir.empty()) { // if no --install-dir argument is present, try parsing @@ -152,3 +152,4 @@ void UpdaterOptions::parse(int argc, char** argv) } } + diff --git a/mmc_updater/src/tests/CMakeLists.txt b/mmc_updater/src/tests/CMakeLists.txt index 5de9d096..1d62214e 100644 --- a/mmc_updater/src/tests/CMakeLists.txt +++ b/mmc_updater/src/tests/CMakeLists.txt @@ -5,21 +5,19 @@ if (APPLE) set(HELPER_SHARED_SOURCES ../StlSymbolsLeopard.cpp) endif() -# Create helper binaries for unit tests -add_executable(oldapp - old_app.cpp - ${HELPER_SHARED_SOURCES} -) -add_executable(newapp - new_app.cpp - ${HELPER_SHARED_SOURCES} -) +# # Create helper binaries for unit tests +# add_executable(oldapp +# old_app.cpp +# ${HELPER_SHARED_SOURCES} +# ) +# add_executable(newapp +# new_app.cpp +# ${HELPER_SHARED_SOURCES} +# ) # Install data files required by unit tests set(TEST_FILES file_list.xml - v2_file_list.xml - test-update.rb ) foreach(TEST_FILE ${TEST_FILES}) @@ -40,12 +38,6 @@ macro(ADD_UPDATER_TEST CLASS) endif() endmacro() -add_updater_test(TestUpdateScript) +add_updater_test(TestParseScript) add_updater_test(TestUpdaterOptions) add_updater_test(TestFileUtils) - -# Add updater that that performs a complete update install -# and checks the result -find_program(RUBY_BIN ruby) -add_test(updater_TestUpdateInstall ${RUBY_BIN} test-update.rb) - diff --git a/mmc_updater/src/tests/TestParseScript.cpp b/mmc_updater/src/tests/TestParseScript.cpp new file mode 100644 index 00000000..f4453957 --- /dev/null +++ b/mmc_updater/src/tests/TestParseScript.cpp @@ -0,0 +1,24 @@ +#include "TestParseScript.h" + +#include "TestUtils.h" +#include "UpdateScript.h" + +#include +#include + +void TestParseScript::testParse() +{ + UpdateScript script; + + script.parse("file_list.xml"); + + TEST_COMPARE(script.isValid(),true); +} + +int main(int,char**) +{ + TestList tests; + tests.addTest(&TestParseScript::testParse); + return TestUtils::runTest(tests); +} + diff --git a/mmc_updater/src/tests/TestParseScript.h b/mmc_updater/src/tests/TestParseScript.h new file mode 100644 index 00000000..528e97a8 --- /dev/null +++ b/mmc_updater/src/tests/TestParseScript.h @@ -0,0 +1,8 @@ +#pragma once + +class TestParseScript +{ + public: + void testParse(); +}; + diff --git a/mmc_updater/src/tests/TestUpdateScript.cpp b/mmc_updater/src/tests/TestUpdateScript.cpp deleted file mode 100644 index 30a7572a..00000000 --- a/mmc_updater/src/tests/TestUpdateScript.cpp +++ /dev/null @@ -1,27 +0,0 @@ -#include "TestUpdateScript.h" - -#include "TestUtils.h" -#include "UpdateScript.h" - -#include -#include - -void TestUpdateScript::testV2Script() -{ - UpdateScript newFormat; - UpdateScript oldFormat; - - newFormat.parse("file_list.xml"); - oldFormat.parse("v2_file_list.xml"); - - TEST_COMPARE(newFormat.filesToInstall(),oldFormat.filesToInstall()); - TEST_COMPARE(newFormat.filesToUninstall(),oldFormat.filesToUninstall()); -} - -int main(int,char**) -{ - TestList tests; - tests.addTest(&TestUpdateScript::testV2Script); - return TestUtils::runTest(tests); -} - diff --git a/mmc_updater/src/tests/TestUpdateScript.h b/mmc_updater/src/tests/TestUpdateScript.h deleted file mode 100644 index 513513d5..00000000 --- a/mmc_updater/src/tests/TestUpdateScript.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -class TestUpdateScript -{ - public: - void testV2Script(); -}; - diff --git a/mmc_updater/src/tests/file_list.xml b/mmc_updater/src/tests/file_list.xml index dff4b54f..06ba501d 100644 --- a/mmc_updater/src/tests/file_list.xml +++ b/mmc_updater/src/tests/file_list.xml @@ -1,20 +1,5 @@ - 2.0 - Test - - - - - - app-pkg - $APP_PACKAGE_HASH - $APP_PACKAGE_SIZE - http://some/dummy/URL - - $APP_FILENAME diff --git a/mmc_updater/src/tests/test-update.rb b/mmc_updater/src/tests/test-update.rb deleted file mode 100755 index 82965cf4..00000000 --- a/mmc_updater/src/tests/test-update.rb +++ /dev/null @@ -1,218 +0,0 @@ -#!/usr/bin/ruby - -require 'fileutils.rb' -require 'find' -require 'rbconfig' -require 'optparse' - -# Install directory - this contains a space to check -# for correct escaping of paths when passing comamnd -# line arguments under Windows -INSTALL_DIR = File.expand_path("install dir/") -PACKAGE_DIR = File.expand_path("package-dir/") -PACKAGE_SRC_DIR = File.expand_path("package-src-dir/") -IS_WINDOWS = RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ - -if IS_WINDOWS - OLDAPP_NAME = "oldapp.exe" - NEWAPP_NAME = "newapp.exe" - APP_NAME = "app.exe" - UPDATER_NAME = "updater.exe" - ZIP_TOOL = File.expand_path("../zip-tool.exe") -else - OLDAPP_NAME = "oldapp" - NEWAPP_NAME = "newapp" - APP_NAME = "app" - UPDATER_NAME = "updater" - ZIP_TOOL = File.expand_path("../zip-tool") -end - -file_list_vars = { - "APP_FILENAME" => APP_NAME, - "UPDATER_FILENAME" => UPDATER_NAME -} - -def replace_vars(src_file,dest_file,vars) - content = File.read(src_file) - vars.each do |key,value| - content.gsub! "$#{key}",value - end - File.open(dest_file,'w') do |file| - file.print content - end -end - -# Returns true if |src_file| and |dest_file| have the same contents, type -# and permissions or false otherwise -def compare_files(src_file, dest_file) - if File.ftype(src_file) != File.ftype(dest_file) - $stderr.puts "Type of file #{src_file} and #{dest_file} differ" - return false - end - - if File.file?(src_file) && !FileUtils.identical?(src_file, dest_file) - $stderr.puts "Contents of file #{src_file} and #{dest_file} differ" - return false - end - - src_stat = File.stat(src_file) - dest_stat = File.stat(dest_file) - - if src_stat.mode != dest_stat.mode - $stderr.puts "Permissions of #{src_file} and #{dest_file} differ" - return false - end - - return true -end - -# Compares the contents of two directories and returns a map of (file path => change type) -# for files and directories which differ between the two -def compare_dirs(src_dir, dest_dir) - src_dir += '/' if !src_dir.end_with?('/') - dest_dir += '/' if !dest_dir.end_with?('/') - - src_file_map = {} - Find.find(src_dir) do |src_file| - src_file = src_file[src_dir.length..-1] - src_file_map[src_file] = nil - end - - change_map = {} - Find.find(dest_dir) do |dest_file| - dest_file = dest_file[dest_dir.length..-1] - - if !src_file_map.include?(dest_file) - change_map[dest_file] = :deleted - elsif !compare_files("#{src_dir}/#{dest_file}", "#{dest_dir}/#{dest_file}") - change_map[dest_file] = :updated - end - - src_file_map.delete(dest_file) - end - - src_file_map.each do |file| - change_map[file] = :added - end - - return change_map -end - -def create_test_file(name, content) - File.open(name, 'w') do |file| - file.puts content - end - return name -end - -force_elevation = false -run_in_debugger = false - -OptionParser.new do |parser| - parser.on("-f","--force-elevated","Force the updater to elevate itself") do - force_elevation = true - end - parser.on("-d","--debug","Run the updater under GDB") do - run_in_debugger = true - end -end.parse! - -# copy 'src' to 'dest', preserving the attributes -# of 'src' -def copy_file(src, dest) - FileUtils.cp src, dest, :preserve => true -end - -# Remove the install and package dirs if they -# already exist -FileUtils.rm_rf(INSTALL_DIR) -FileUtils.rm_rf(PACKAGE_DIR) -FileUtils.rm_rf(PACKAGE_SRC_DIR) - -# Create the install directory with the old app -Dir.mkdir(INSTALL_DIR) -copy_file OLDAPP_NAME, "#{INSTALL_DIR}/#{APP_NAME}" - -# Create a dummy file to uninstall -uninstall_test_file = create_test_file("#{INSTALL_DIR}/file-to-uninstall.txt", "this file should be removed after the update") -uninstall_test_symlink = if not IS_WINDOWS - FileUtils.ln_s("#{INSTALL_DIR}/file-to-uninstall.txt", "#{INSTALL_DIR}/symlink-to-file-to-uninstall.txt") -else - create_test_file("#{INSTALL_DIR}/symlink-to-file-to-uninstall.txt", "dummy file. this is a symlink on Unix") -end - -# Populate package source dir with files to install -Dir.mkdir(PACKAGE_SRC_DIR) -nested_dir_path = "#{PACKAGE_SRC_DIR}/new-dir/new-dir2" -FileUtils.mkdir_p(nested_dir_path) -FileUtils::chmod 0755, "#{PACKAGE_SRC_DIR}/new-dir" -FileUtils::chmod 0755, "#{PACKAGE_SRC_DIR}/new-dir/new-dir2" -nested_dir_test_file = "#{nested_dir_path}/new-file.txt" -File.open(nested_dir_test_file,'w') do |file| - file.puts "this is a new file in a new nested dir" -end -FileUtils::chmod 0644, nested_dir_test_file -copy_file NEWAPP_NAME, "#{PACKAGE_SRC_DIR}/#{APP_NAME}" -FileUtils::chmod 0755, "#{PACKAGE_SRC_DIR}/#{APP_NAME}" - -# Create .zip packages from source files -Dir.mkdir(PACKAGE_DIR) -Dir.chdir(PACKAGE_SRC_DIR) do - if !system("#{ZIP_TOOL} #{PACKAGE_DIR}/app-pkg.zip .") - raise "Unable to create update package" - end -end - -# Copy the install script and updater to the target -# directory -replace_vars("file_list.xml","#{PACKAGE_DIR}/file_list.xml",file_list_vars) -copy_file "../#{UPDATER_NAME}", "#{PACKAGE_DIR}/#{UPDATER_NAME}" - -# Run the updater using the new syntax -# -# Run the application from the install directory to -# make sure that it looks in the correct directory for -# the file_list.xml file and packages -# -install_path = File.expand_path(INSTALL_DIR) -Dir.chdir(INSTALL_DIR) do - flags = "--force-elevated" if force_elevation - debug_flags = "gdb --args" if run_in_debugger - cmd = "#{debug_flags} #{PACKAGE_DIR}/#{UPDATER_NAME} #{flags} --install-dir \"#{install_path}\" --package-dir \"#{PACKAGE_DIR}\" --script file_list.xml --auto-close" - puts "Running '#{cmd}'" - system(cmd) -end - -# TODO - Correctly wait until updater has finished -sleep(1) - -# Check that the app was updated -app_path = "#{INSTALL_DIR}/#{APP_NAME}" -output = `"#{app_path}"` -if (output.strip != "new app starting") - throw "Updated app produced unexpected output: #{output}" -end - -# Check that the packaged dir and install dir match -dir_diff = compare_dirs(PACKAGE_SRC_DIR, INSTALL_DIR) -ignored_files = ["test-dir", "test-dir/app-symlink", UPDATER_NAME] -have_unexpected_change = false -dir_diff.each do |path, change_type| - if !ignored_files.include?(path) - case change_type - when :added - $stderr.puts "File #{path} was not installed" - when :changed - $stderr.puts "File #{path} differs between install and package dir" - when :deleted - $stderr.puts "File #{path} was not uninstalled" - end - have_unexpected_change = true - end -end - -if have_unexpected_change - throw "Unexpected differences between packaging and update dir" -end - -puts "Test passed" diff --git a/mmc_updater/src/tests/v2_file_list.xml b/mmc_updater/src/tests/v2_file_list.xml deleted file mode 100644 index 202e5bbe..00000000 --- a/mmc_updater/src/tests/v2_file_list.xml +++ /dev/null @@ -1,67 +0,0 @@ - - - - - 2.0 - Test - - - - - - app-pkg - $APP_PACKAGE_HASH - $APP_PACKAGE_SIZE - http://some/dummy/URL - - - - - - - - - - $APP_FILENAME - $UPDATED_APP_HASH - $UPDATED_APP_SIZE - 0755 - app-pkg - true - - - $UPDATER_FILENAME - $UPDATER_HASH - $UPDATER_SIZE - 0755 - - - - test-dir/app-symlink - ../app - - - new-dir/new-dir2/new-file.txt - $TEST_FILENAME - $TEST_SIZE - app-pkg - 0644 - - - - - file-to-uninstall.txt - symlink-to-file-to-uninstall.txt - - -- cgit From f8067a60346207d4b9b9f0c0eb5b1c3a70e28485 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Tue, 17 Dec 2013 00:37:56 +0100 Subject: Magical pixie dust for windows updater reliability Don't ask. --- MultiMC.manifest | 27 +++++++++++++++++++++++++++ mmc_updater/CMakeLists.txt | 8 ++++++++ mmc_updater/src/resources/updater.manifest | 27 +++++++++++++++++++++++++++ mmc_updater/src/resources/updater.rc | 30 +++++++++++++++--------------- multimc.rc | 28 ++++++++++++++++++++++++++++ 5 files changed, 105 insertions(+), 15 deletions(-) create mode 100644 MultiMC.manifest create mode 100644 mmc_updater/src/resources/updater.manifest (limited to 'mmc_updater/src') diff --git a/MultiMC.manifest b/MultiMC.manifest new file mode 100644 index 00000000..3acf8f7f --- /dev/null +++ b/MultiMC.manifest @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + Custom Minecraft launcher for managing multiple installs. + + + + + + + + + + + \ No newline at end of file diff --git a/mmc_updater/CMakeLists.txt b/mmc_updater/CMakeLists.txt index 61c8cd09..971ac153 100644 --- a/mmc_updater/CMakeLists.txt +++ b/mmc_updater/CMakeLists.txt @@ -9,6 +9,14 @@ include_directories(depends) if (WIN32) include_directories(depends/win32cpp) + # static all the things. The updater must have no dependencies, or it will fail. + if (MINGW) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc -static") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++ -static") +#set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS} -static-libgcc -s") +#set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS} -static-libgcc -static-libstdc++ -s") + endif() + if(MSVC) # - Link the updater binary statically with the Visual C++ runtime # so that the executable can function standalone. diff --git a/mmc_updater/src/resources/updater.manifest b/mmc_updater/src/resources/updater.manifest new file mode 100644 index 00000000..cafc47d3 --- /dev/null +++ b/mmc_updater/src/resources/updater.manifest @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + Software updater for MultiMC. + + + + + + + + + + + \ No newline at end of file diff --git a/mmc_updater/src/resources/updater.rc b/mmc_updater/src/resources/updater.rc index 550970a8..9c7c5711 100644 --- a/mmc_updater/src/resources/updater.rc +++ b/mmc_updater/src/resources/updater.rc @@ -1,30 +1,30 @@ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include + IDI_APPICON ICON DISCARDABLE "updater.ico" -1 VERSIONINFO -FILEVERSION 0,0,1,0 -PRODUCTVERSION 1,0,1,0 -FILEFLAGSMASK 0X3FL -FILEFLAGS 0X8L -FILEOS 0X40004L -FILETYPE 0X1 -FILESUBTYPE 0 +1 RT_MANIFEST "updater.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 "FileVersion", "0.0.1.0" - VALUE "ProductVersion", "1.0.1.0" - VALUE "OriginalFilename", "updater.exe" - VALUE "InternalName", "updater.exe" - VALUE "FileDescription", "Software Update Tool" VALUE "CompanyName", "MultiMC Contributors" + VALUE "FileDescription", "Software Update Tool" + VALUE "FileVersion", "1.0.0.0" VALUE "ProductName", "MultiMC Software Updater" - VALUE "PrivateBuild", "Built by BuildBot" + VALUE "ProductVersion", "1.0" END END BLOCK "VarFileInfo" BEGIN - VALUE "Translation", 0x0000, 0x04b0 + VALUE "Translation", 0x0000, 0x04b0 // Unicode END END \ No newline at end of file diff --git a/multimc.rc b/multimc.rc index decf7d3a..2140e3f4 100644 --- a/multimc.rc +++ b/multimc.rc @@ -1 +1,29 @@ +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include + IDI_ICON1 ICON DISCARDABLE "resources/icons/MultiMC.ico" +1 RT_MANIFEST "MultiMC.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", "Minecraft Launcher" + VALUE "FileVersion", "1.0.0.0" + VALUE "ProductName", "MultiMC" + VALUE "ProductVersion", "5" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0000, 0x04b0 // Unicode + END +END -- cgit From 3051d0d3283656baafe6021e5036fdca9db0c4aa Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sun, 22 Dec 2013 18:49:52 +0100 Subject: Make pack200 use QFile by proxy, eliminating some unicode issues. --- depends/pack200/anti200.cpp | 43 +++++++++++++++++++++++------------ depends/pack200/include/unpack200.h | 2 +- depends/pack200/src/unpack200.cpp | 13 +---------- logic/net/ForgeXzDownload.cpp | 45 ++++++++++++++++++++++++++++++++----- mmc_updater/src/Platform.h | 4 +++- 5 files changed, 73 insertions(+), 34 deletions(-) (limited to 'mmc_updater/src') diff --git a/depends/pack200/anti200.cpp b/depends/pack200/anti200.cpp index 3dfdb5dc..1e1ec0c8 100644 --- a/depends/pack200/anti200.cpp +++ b/depends/pack200/anti200.cpp @@ -8,21 +8,36 @@ int main(int argc, char **argv) { - if (argc == 3) + if (argc != 3) { - try - { - unpack_200(argv[1], argv[2]); - } - catch (std::runtime_error &e) - { - std::cerr << "Bad things happened: " << e.what() << std::endl; - return EXIT_FAILURE; - } - return EXIT_SUCCESS; - } - else std::cerr << "Simple pack200 unpacker!" << std::endl << "Run like this:" << std::endl << " " << argv[0] << " input.jar.lzma output.jar" << std::endl; - return EXIT_FAILURE; + return EXIT_FAILURE; + } + + FILE *input = fopen(argv[1], "rb"); + FILE *output = fopen(argv[2], "wb"); + if (!input) + { + std::cerr << "Can't open input file"; + return EXIT_FAILURE; + } + if (!output) + { + fclose(output); + std::cerr << "Can't open output file"; + return EXIT_FAILURE; + } + try + { + unpack_200(input, output); + } + catch (std::runtime_error &e) + { + std::cerr << "Bad things happened: " << e.what() << std::endl; + fclose(input); + fclose(output); + return EXIT_FAILURE; + } + return EXIT_SUCCESS; } diff --git a/depends/pack200/include/unpack200.h b/depends/pack200/include/unpack200.h index bcee8009..f9239488 100644 --- a/depends/pack200/include/unpack200.h +++ b/depends/pack200/include/unpack200.h @@ -34,4 +34,4 @@ * @return void * @throw std::runtime_error for any error encountered */ -void unpack_200(std::string input_path, std::string output_path); +void unpack_200(FILE * input, FILE * output); diff --git a/depends/pack200/src/unpack200.cpp b/depends/pack200/src/unpack200.cpp index 0a9d2714..22b7f3b0 100644 --- a/depends/pack200/src/unpack200.cpp +++ b/depends/pack200/src/unpack200.cpp @@ -94,20 +94,9 @@ static int read_magic(unpacker *u, char peek[], int peeklen) return magic; } -void unpack_200(std::string input_path, std::string output_path) +void unpack_200(FILE *input, FILE *output) { unpacker u; - FILE *input = fopen(input_path.c_str(), "rb"); - if (!input) - { - throw std::runtime_error("Can't open input file" + input_path); - } - FILE *output = fopen(output_path.c_str(), "wb"); - if (!output) - { - fclose(output); - throw std::runtime_error("Can't open output file" + output_path); - } u.init(read_input_via_stdio); // initialize jar output diff --git a/logic/net/ForgeXzDownload.cpp b/logic/net/ForgeXzDownload.cpp index 83cbabd0..359ad858 100644 --- a/logic/net/ForgeXzDownload.cpp +++ b/logic/net/ForgeXzDownload.cpp @@ -311,18 +311,51 @@ void ForgeXzDownload::decompressAndInstall() m_pack200_xz_file.remove(); // revert pack200 - pack200_file.close(); - QString pack_name = pack200_file.fileName(); - QString source_native = QDir::toNativeSeparators(pack_name); - QString target_native = QDir::toNativeSeparators(m_target_path); + pack200_file.seek(0); + int handle_in = pack200_file.handle(); + // FIXME: dispose of file handles, pointers and the like. Ideally wrap in objects. + if(handle_in == -1) + { + QLOG_ERROR() << "Error reopening " << pack200_file.fileName(); + failAndTryNextMirror(); + return; + } + FILE * file_in = fdopen(handle_in,"r"); + if(!file_in) + { + QLOG_ERROR() << "Error reopening " << pack200_file.fileName(); + failAndTryNextMirror(); + return; + } + QFile qfile_out(m_target_path); + if(!qfile_out.open(QIODevice::WriteOnly)) + { + QLOG_ERROR() << "Error opening " << qfile_out.fileName(); + failAndTryNextMirror(); + return; + } + int handle_out = qfile_out.handle(); + if(handle_out == -1) + { + QLOG_ERROR() << "Error opening " << qfile_out.fileName(); + failAndTryNextMirror(); + return; + } + FILE * file_out = fdopen(handle_out,"w"); + if(!file_out) + { + QLOG_ERROR() << "Error opening " << qfile_out.fileName(); + failAndTryNextMirror(); + return; + } try { - unpack_200(source_native.toStdString(), target_native.toStdString()); + unpack_200(file_in, file_out); } catch (std::runtime_error &err) { m_status = Job_Failed; - QLOG_ERROR() << "Error unpacking " << pack_name.toUtf8() << " : " << err.what(); + QLOG_ERROR() << "Error unpacking " << pack200_file.fileName() << " : " << err.what(); QFile f(m_target_path); if (f.exists()) f.remove(); diff --git a/mmc_updater/src/Platform.h b/mmc_updater/src/Platform.h index 6d9afdfb..97867d6a 100644 --- a/mmc_updater/src/Platform.h +++ b/mmc_updater/src/Platform.h @@ -13,7 +13,9 @@ // disable warnings about exception specifications, // which are not implemented in Visual C++ - #pragma warning(disable:4290) + #ifdef MSVC + #pragma warning(disable:4290) + #endif #endif #ifdef __APPLE__ -- cgit From 7652b3d64a63c587f520633364412345083210d4 Mon Sep 17 00:00:00 2001 From: Petr Mrázek 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 --- CMakeLists.txt | 6 ++++- logic/updater/DownloadUpdateTask.cpp | 36 +++++++++++++++++++++---- logic/updater/DownloadUpdateTask.h | 16 ++++++++++- 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 ++++++++++++++++++++ tests/tst_DownloadUpdateTask.cpp | 19 +++++++++++++ 10 files changed, 171 insertions(+), 59 deletions(-) create mode 100644 mmc_updater/src/tests/test.manifest create mode 100644 mmc_updater/src/tests/test.rc (limited to 'mmc_updater/src') diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b371aa9..7c8087cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -662,8 +662,12 @@ ELSE() ENDIF() add_custom_target (translations DEPENDS ${QM_FILES}) +IF(APPLE AND UNIX) ## OSX + install(FILES ${QM_FILES} DESTINATION MultiMC.app/Contents/MacOS/translations) +ELSE() + install(FILES ${QM_FILES} DESTINATION translations) +ENDIF() -install(FILES ${QM_FILES} DESTINATION ${CMAKE_INSTALL_PREFIX}/translations) # Tests add_subdirectory(tests) diff --git a/logic/updater/DownloadUpdateTask.cpp b/logic/updater/DownloadUpdateTask.cpp index 057ca436..0b09ad2a 100644 --- a/logic/updater/DownloadUpdateTask.cpp +++ b/logic/updater/DownloadUpdateTask.cpp @@ -66,7 +66,7 @@ void DownloadUpdateTask::processChannels() if (channel.id == channelId) { QLOG_INFO() << "Found matching channel."; - m_cRepoUrl = preparePath(channel.url); + m_cRepoUrl = fixPathForTests(channel.url); break; } } @@ -207,8 +207,17 @@ bool DownloadUpdateTask::parseVersionInfo(const QByteArray &data, VersionFileLis { QJsonObject fileObj = fileValue.toObject(); + QString file_path = fileObj.value("Path").toString(); +#ifdef Q_OS_MAC + // On OSX, the paths for the updater need to be fixed. + // basically, anything that isn't in the .app folder is ignored. + // everything else is changed so the code that processes the files actually finds + // them and puts the replacements in the right spots. + if(!fixPathForOSX(file_path)) + continue; +#endif VersionFileEntry file{ - fileObj.value("Path").toString(), fileObj.value("Perms").toVariant().toInt(), + file_path , fileObj.value("Perms").toVariant().toInt(), FileSourceList(), fileObj.value("MD5").toString(), }; QLOG_DEBUG() << "File" << file.path << "with perms" << file.mode; @@ -221,12 +230,12 @@ bool DownloadUpdateTask::parseVersionInfo(const QByteArray &data, VersionFileLis if (type == "http") { file.sources.append( - FileSource("http", preparePath(sourceObj.value("Url").toString()))); + FileSource("http", fixPathForTests(sourceObj.value("Url").toString()))); } else if (type == "httpc") { file.sources.append(FileSource("httpc", - preparePath(sourceObj.value("Url").toString()), + fixPathForTests(sourceObj.value("Url").toString()), sourceObj.value("CompressionType").toString())); } else @@ -491,7 +500,7 @@ bool DownloadUpdateTask::writeInstallScript(UpdateOperationList &opsList, QStrin return true; } -QString DownloadUpdateTask::preparePath(const QString &path) +QString DownloadUpdateTask::fixPathForTests(const QString &path) { if(path.startsWith("$PWD")) { @@ -502,6 +511,23 @@ QString DownloadUpdateTask::preparePath(const QString &path) return path; } +bool DownloadUpdateTask::fixPathForOSX(QString &path) +{ + if(path.startsWith("MultiMC.app/")) + { + // remove the prefix and add a new, more appropriate one. + path.remove(0,12); + path = QString("../../") + path; + return true; + } + else + { + QLOG_ERROR() << "Update path not within .app: " << path; + return false; + } +} + + void DownloadUpdateTask::fileDownloadFinished() { emitSucceeded(); diff --git a/logic/updater/DownloadUpdateTask.h b/logic/updater/DownloadUpdateTask.h index 79d73af3..d82b044f 100644 --- a/logic/updater/DownloadUpdateTask.h +++ b/logic/updater/DownloadUpdateTask.h @@ -198,7 +198,21 @@ protected: * Filters paths * Path of the format $PWD/path, it is converted to a file:///$PWD/ URL */ - static QString preparePath(const QString &path); + static QString fixPathForTests(const QString &path); + + /*! + * Filters paths + * This fixes destination paths for OSX. + * The updater runs in MultiMC.app/Contents/MacOs by default + * The destination paths are such as this: MultiMC.app/blah/blah + * + * Therefore we chop off the 'MultiMC.app' prefix and prepend ../.. + * + * Returns false if the path couldn't be fixed (is invalid) + * + * Has no effect on systems that aren't OSX + */ + static bool fixPathForOSX(QString &path); protected slots: void vinfoDownloadFinished(); 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 diff --git a/tests/tst_DownloadUpdateTask.cpp b/tests/tst_DownloadUpdateTask.cpp index f47552fe..3b2c6793 100644 --- a/tests/tst_DownloadUpdateTask.cpp +++ b/tests/tst_DownloadUpdateTask.cpp @@ -245,6 +245,25 @@ slots: QVERIFY(succeededSpy.wait()); } + + void test_OSXPathFixup() + { + QString path, pathOrig; + bool result; + // Proper OSX path + pathOrig = path = "MultiMC.app/Foo/Bar/Baz"; + qDebug() << "Proper OSX path: " << path; + result = DownloadUpdateTask::fixPathForOSX(path); + QCOMPARE(path, QString("../../Foo/Bar/Baz")); + QCOMPARE(result, true); + + // Bad OSX path + pathOrig = path = "translations/klingon.lol"; + qDebug() << "Bad OSX path: " << path; + result = DownloadUpdateTask::fixPathForOSX(path); + QCOMPARE(path, pathOrig); + QCOMPARE(result, false); + } }; QTEST_GUILESS_MAIN_MULTIMC(DownloadUpdateTaskTest) -- cgit From 595e4b697e911e2ed036446dd624dca77e234944 Mon Sep 17 00:00:00 2001 From: Petr Mrázek Date: Sat, 28 Dec 2013 04:55:38 +0100 Subject: Change TestParseScript path back to what it was. --- mmc_updater/src/tests/TestParseScript.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mmc_updater/src') diff --git a/mmc_updater/src/tests/TestParseScript.cpp b/mmc_updater/src/tests/TestParseScript.cpp index e8087b33..f4453957 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("mmc_updater/src/tests/file_list.xml"); + script.parse("file_list.xml"); TEST_COMPARE(script.isValid(),true); } -- cgit From 9fbe3a7ccd9bbd76b47e0fcc4e51d5eb0bb9a99c Mon Sep 17 00:00:00 2001 From: Sky Date: Wed, 1 Jan 2014 20:23:06 +0000 Subject: Tweak update result dialog size --- mmc_updater/src/UpdateDialogWin32.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mmc_updater/src') diff --git a/mmc_updater/src/UpdateDialogWin32.cpp b/mmc_updater/src/UpdateDialogWin32.cpp index bdc25437..8b38bed2 100644 --- a/mmc_updater/src/UpdateDialogWin32.cpp +++ b/mmc_updater/src/UpdateDialogWin32.cpp @@ -85,8 +85,8 @@ UpdateDialogWin32::~UpdateDialogWin32() void UpdateDialogWin32::init(int /* argc */, char** /* argv */) { - int width = 300; - int height = 130; + int width = 400; + int height = 150; DWORD style = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX; m_window.CreateEx(0 /* dwExStyle */, -- cgit