smpq-1.6/0000775000175000017500000000000013023644211012232 5ustar palipali00000000000000smpq-1.6/smpq.xml0000664000175000017500000000107312065607370013747 0ustar palipali00000000000000 MPQ archive MPQ Encrypted archive smpq-1.6/smpq.protocol0000664000175000017500000000061212065607370015006 0ustar palipali00000000000000[Protocol] exec=kio_smpq protocol=mpq archiveMimetype=application/x-mpq,application/x-mpqe,application/x-ms-dos-executable input=filesystem output=filesystem listing=Name,Type,Size,Date reading=true writing=true makedir=true deleting=true linking=false moving=true opening=true source=true Icon=package-x-generic Description=A kioslave for smpq #X-DocPath=kioslave/smpq/index.html Class=:local smpq-1.6/smpq.nsi0000664000175000017500000001403112735741267013746 0ustar palipali00000000000000; ; smpq.nsi - Windows NSIS Installer for StormLib MPQ archiving utility ; Copyright (C) 2010 - 2016 Pali Rohár ; ; This program is free software: you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation, either version 3 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program. If not, see . ; ; ;-------------------------------- !ifdef QUIET !verbose 2 !endif !define redefine "!insertmacro redefine" !macro redefine symbol value !undef ${symbol} !define ${symbol} "${value}" !macroend ;-------------------------------- !include "MUI2.nsh" ;-------------------------------- !define NAME "SMPQ" !define DESCRIPTION "StormLib MPQ archiving utility" !define VIVERSION "${VERSION}.0.0" !define HOMEPAGE "https://launchpad.net/smpq" !define LICENSE "GPL v3" !define COPYRIGHT "Copyright (c) 2010 - 2016 by Pali Rohar" ;-------------------------------- !define EXE "smpq.exe" !define README "README" !define COPYING "COPYING" !define CHANGELOG "CHANGELOG" !define UNINSTALL "uninstall.exe" !define INSTALLER "${NAME}-${VERSION}.exe" !define INSTALLDIR "$PROGRAMFILES\${NAME}\" !define LANGUAGE "English" !ifdef x86_64 ${redefine} INSTALLER "${NAME}-${VERSION}-x86_64.exe" ${redefine} INSTALLDIR "$PROGRAMFILES64\${NAME}\" ${redefine} NAME "${NAME} (64 bit)" !endif !define REGKEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${NAME}" ;-------------------------------- LangString INSTALLER_RUNNING ${LANG_ENGLISH} "${NAME} Installer is already running" LangString REMOVEPREVIOUS ${LANG_ENGLISH} "Removing previous installation" LangString DESC_REMOVEEXE ${LANG_ENGLISH} "Remove ${NAME} executable" !ifdef x86_64 LangString x86_64_ONLY ${LANG_ENGLISH} "This version is for 64 bits computers only" !endif ;-------------------------------- SetCompressor lzma !define MUI_ABORTWARNING !define MUI_FINISHPAGE_NOAUTOCLOSE !define MUI_UNFINISHPAGE_NOAUTOCLOSE !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE "${COPYING}" !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_COMPONENTS !insertmacro MUI_UNPAGE_INSTFILES !insertmacro MUI_UNPAGE_FINISH !insertmacro MUI_LANGUAGE "${LANGUAGE}" ;-------------------------------- Name "${NAME}" OutFile "${INSTALLER}" InstallDir "${INSTALLDIR}" InstallDirRegKey HKLM "${REGKEY}" "InstallLocation" VIAddVersionKey /LANG=${LANG_ENGLISH} "FileDescription" "${NAME} Installer - ${DESCRIPTION}" VIAddVersionKey /LANG=${LANG_ENGLISH} "FileVersion" "${VERSION}" VIAddVersionKey /LANG=${LANG_ENGLISH} "InternalName" "${NAME} Installer" VIAddVersionKey /LANG=${LANG_ENGLISH} "LegalCopyright" "${COPYRIGHT}" VIAddVersionKey /LANG=${LANG_ENGLISH} "License" "${LICENSE}" VIAddVersionKey /LANG=${LANG_ENGLISH} "Homepage" "${HOMEPAGE}" VIAddVersionKey /LANG=${LANG_ENGLISH} "OriginalFilename" "${INSTALLER}" VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductName" "${NAME} Installer" VIAddVersionKey /LANG=${LANG_ENGLISH} "ProductVersion" "${VERSION}" VIProductVersion "${VIVERSION}" BrandingText "${NAME} - ${DESCRIPTION}, version ${VERSION} ${HOMEPAGE}" ShowInstDetails Show ShowUnInstDetails Show XPStyle on RequestExecutionLevel admin ;-------------------------------- Function .onInit System::Call 'kernel32::CreateMutexA(i 0, i 0, t "${NAME}") i .r1 ?e' Pop $0 StrCmp $0 0 +3 MessageBox MB_OK|MB_ICONEXCLAMATION "$(INSTALLER_RUNNING)" Abort !ifdef x86_64 System::Call "kernel32::GetCurrentProcess() i .s" System::Call "kernel32::IsWow64Process(i s, *i .r0)" IntCmp $0 0 0 0 +3 MessageBox MB_OK|MB_ICONSTOP "$(x86_64_ONLY)" Abort !endif FunctionEnd ;-------------------------------- Section "-${NAME}" UninstallPrevious SectionIn RO ReadRegStr $0 HKLM "${REGKEY}" "InstallLocation" StrCmp $0 "" +7 DetailPrint "$(REMOVEPREVIOUS)" SetDetailsPrint none ExecWait "$0\${UNINSTALL} /S _?=$0" Delete "$0\${UNINSTALL}" RMDir $0 SetDetailsPrint lastused SectionEnd Section "${NAME}" SectionIn RO SetOutPath $INSTDIR File "${EXE}" File "${README}" File "${COPYING}" File "${CHANGELOG}" WriteRegStr HKLM "${REGKEY}" "DisplayName" "${NAME} - ${DESCRIPTION}" WriteRegStr HKLM "${REGKEY}" "UninstallString" "$\"$INSTDIR\${UNINSTALL}$\"" WriteRegStr HKLM "${REGKEY}" "QuietUninstallString" "$\"$INSTDIR\${UNINSTALL}$\" /S" WriteRegStr HKLM "${REGKEY}" "InstallLocation" "$INSTDIR" WriteRegStr HKLM "${REGKEY}" "DisplayIcon" "$\"$INSTDIR\${EXE}$\",0" WriteRegStr HKLM "${REGKEY}" "DisplayVersion" "${VERSION}" WriteRegStr HKLM "${REGKEY}" "HelpLink" "${HOMEPAGE}" WriteRegStr HKLM "${REGKEY}" "URLUpdateInfo" "${HOMEPAGE}" WriteRegStr HKLM "${REGKEY}" "URLInfoAbout" "${HOMEPAGE}" WriteRegDWORD HKLM "${REGKEY}" "NoModify" 1 WriteRegDWORD HKLM "${REGKEY}" "NoRepair" 1 WriteUninstaller "$INSTDIR\${UNINSTALL}" SectionEnd ;-------------------------------- Section "un.${NAME}" Executable SectionIn RO Delete "$INSTDIR\${EXE}" Delete "$INSTDIR\${README}" Delete "$INSTDIR\${COPYING}" Delete "$INSTDIR\${CHANGELOG}" DeleteRegKey /ifempty HKLM "${REGKEY}" Delete "$INSTDIR\${UNINSTALL}" RMDir "$INSTDIR" SectionEnd !insertmacro MUI_UNFUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${Executable} $(DESC_REMOVEEXE) !insertmacro MUI_UNFUNCTION_DESCRIPTION_END ;-------------------------------- !ifndef UPX !define UPX "upx" !endif !ifndef UPX_FLAGS !define UPX_FLAGS "-9" !else ${redefine} UPX_FLAGS "${UPX_FLAGS} -9" !endif !ifdef QUIET ${redefine} UPX_FLAGS "${UPX_FLAGS} -qq" !endif !packhdr "exehead.tmp" "${UPX} ${UPX_FLAGS} exehead.tmp" ;!finalize "gpg --armor --sign --detach-sig %1" ;-------------------------------- smpq-1.6/rename.c0000664000175000017500000000373712676030205013664 0ustar palipali00000000000000/* rename.cpp - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include "common.h" int smpq_rename(const char * archive, const char * oldName, const char * newName, unsigned int flags, const char * listfile, unsigned int locale) { HANDLE SArchive = NULL; unsigned int SFlags = 0; if ( flags & NO_LISTFILE ) SFlags |= MPQ_OPEN_NO_LISTFILE; if ( flags & NO_ATTRIBUTES ) SFlags |= MPQ_OPEN_NO_ATTRIBUTES; if ( flags & MPQ_VERSION_1 ) SFlags |= MPQ_OPEN_FORCE_MPQ_V1; if ( flags & SECTOR_CRC ) SFlags |= MPQ_OPEN_CHECK_SECTOR_CRC; if ( ! SFileOpenArchive(archive, 0, SFlags, &SArchive) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot open archive", archive, GetLastError()); return -1; } if ( ! ( flags & NO_SYSTEM_LF ) ) smpq_systemlistfiles(SArchive, archive, flags); if ( ! ( flags & NO_LISTFILE ) ) SFileAddListFile(SArchive, NULL); SFileAddListFile(SArchive, listfile); SFileSetLocale(locale); if ( flags & VERBOSE ) printVerbose(archive, "Rename file", oldName); if ( ! SFileRenameFile(SArchive, oldName, newName) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot rename file", oldName, GetLastError()); SFileCloseArchive(SArchive); return -1; } SFileCloseArchive(SArchive); return 0; } smpq-1.6/remove.c0000664000175000017500000000622212676030205013702 0ustar palipali00000000000000/* remove.cpp - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include "common.h" int smpq_remove(const char * archive, const char * const files[], unsigned int flags, const char * listfile, unsigned int locale) { int i; int needCompact = 0; HANDLE SArchive = NULL; unsigned int SFlags = 0; if ( flags & NO_LISTFILE ) SFlags |= MPQ_OPEN_NO_LISTFILE; if ( flags & NO_ATTRIBUTES ) SFlags |= MPQ_OPEN_NO_ATTRIBUTES; if ( flags & MPQ_VERSION_1 ) SFlags |= MPQ_OPEN_FORCE_MPQ_V1; if ( flags & SECTOR_CRC ) SFlags |= MPQ_OPEN_CHECK_SECTOR_CRC; if ( ! SFileOpenArchive(archive, 0, SFlags, &SArchive) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot open archive", archive, GetLastError()); return -1; } if ( ! ( flags & NO_SYSTEM_LF ) ) smpq_systemlistfiles(SArchive, archive, flags); if ( ! ( flags & NO_LISTFILE ) ) SFileAddListFile(SArchive, NULL); SFileSetLocale(locale); for ( i = 0; files[i]; ++i ) { const char * fileName = files[i]; char SFileName[1024]; if ( strlen(fileName)+1 > 1024 ) continue; toArchivePath(SFileName, fileName); if ( flags & VERBOSE ) printVerbose(archive, "Remove file", SFileName); SFlags = SFILE_OPEN_FROM_MPQ; if ( ! SFileRemoveFile(SArchive, SFileName, SFlags) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot remove existing file", SFileName, GetLastError()); continue; } if ( ! needCompact ) needCompact = 1; SFileFlushArchive(SArchive); } if ( needCompact ) { unsigned int fileCount; unsigned int maxFileCount; if ( ! SFileGetFileInfo(SArchive, SFileMpqNumberOfFiles, &fileCount, sizeof(fileCount), 0) ) fileCount = 6; if ( ! SFileGetFileInfo(SArchive, SFileMpqMaxFileCount, &maxFileCount, sizeof(maxFileCount), 0) ) maxFileCount = 6; if ( fileCount < 6 ) fileCount = 6; if ( fileCount * 2 <= maxFileCount ) { if ( flags & VERBOSE ) printVerbose(archive, "Change maximum file count", archive); if ( ! SFileSetMaxFileCount(SArchive, fileCount) ) if ( ! ( flags & QUIET ) ) printError(archive, "Cannot change maximum file count", archive, GetLastError()); } if ( flags & VERBOSE ) printVerbose(archive, "Compact archive", archive); if ( ! SFileCompactArchive(SArchive, listfile, 0) ) if ( ! ( flags & QUIET ) ) printError(archive, "Cannot compact archive", archive, GetLastError()); SFileFlushArchive(SArchive); } SFileCloseArchive(SArchive); return 0; } smpq-1.6/print.c0000664000175000017500000000327512676030205013546 0ustar palipali00000000000000/* print.c - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include "common.h" void printError(const char * archive, const char * message, const char * file, int errnum) { const char * error = NULL; if ( errnum < 105 ) error = strerror(errnum); else if ( errnum == 105 ) error = "Bad format"; else if ( errnum == 106 ) error = "No more files"; else if ( errnum == 107 ) error = "Handle EOF"; else if ( errnum == 108 ) error = "Cannot compile"; else if ( errnum == 109 ) error = "File corrupted"; fprintf(stderr, "%s: %s: Error: %s `%s': %s\n", app, archive, message, file, error); fflush(stderr); } void printVerbose(const char * archive, const char * message, const char * file) { printf("%s: %s: %s `%s' ...\n", app, archive, message, file); fflush(stdout); } void printMessage(const char * message, ...) { va_list ap; va_start(ap, message); vprintf(message, ap); va_end(ap); putchar('\n'); fflush(stdout); } smpq-1.6/mangen.c0000664000175000017500000000735413014423420013651 0ustar palipali00000000000000/* mangen.c - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #define main main_unused #include "main.c" #undef main char StormLibCopyright[] = { 0 }; const char * app = "smpq"; int smpq_append(const char * archive, const char * const files[], unsigned int flags, unsigned int locale, unsigned int maxFileCount, const char * compression) { (void)archive; (void)files; (void)flags; (void)locale; (void)maxFileCount; (void)compression; return 0; } int smpq_extract(const char * archive, const char * const files[], unsigned int flags, const char * listfile, unsigned int locale, const char * const parchives[]) { (void)archive; (void)files; (void)flags; (void)listfile; (void)locale; (void)parchives; return 0; } int smpq_info(const char * archive, unsigned int flags) { (void)archive; (void)flags; return 0; } int smpq_remove(const char * archive, const char * const files[], unsigned int flags, const char * listfile, unsigned int locale) { (void)archive; (void)files; (void)flags; (void)listfile; (void)locale; return 0; } int smpq_rename(const char * archive, const char * oldName, const char * newName, unsigned int flags, const char * listfile, unsigned int locale) { (void)archive; (void)oldName; (void)newName; (void)newName; (void)flags; (void)listfile; (void)locale; return 0; } #include #include #define prints(s, e) do { const char * _c; for ( _c = s; _c < e; ++_c ) putchar(*_c); } while (0) int main(void) { const char * start = HELP; const char * end = start; const char * len = start + strlen(HELP) + 1; printf("'\\\" t -*- coding: UTF-8 -*-\n"); printf(".TH SMPQ 1 \"" __DATE__ "\" \"SMPQ - StormLib MPQ archiving utility, version " VERSION "\"\n"); while ( start < len && ( end = strchr(start, '\n') ) != NULL ) { if ( strncmp(start, "Usage:", 6) == 0 ) { const char * next = strstr(start+6, "smpq"); if ( next == NULL || next > end ) next = start+6; else next += strlen("smpq"); printf("\n.SH SYNOPSIS\n.B smpq\n.I "); prints(next, end); putchar('\n'); } else if ( strncmp(start, "SMPQ", 4) == 0 ) { printf("\n.SH NAME\n"); prints(start, end); putchar('\n'); } else if ( *(end - 1) == ':' ) { printf("\n.SH "); prints(start, end - 1); putchar('\n'); } else if ( strncmp(start, " ", 7) == 0 ) { const char * next = start; while ( *(++next) == ' ' && next < end ); putchar('\n'); prints(next, end); putchar('\n'); } else if ( *start == ' ' ) { const char * next; const char * next2; const char * next3; next = start; while ( *(++next) == ' ' && next < end ); next2 = strstr(next, " "); if ( next2 == NULL || next2 > end ) next2 = next; next3 = next2-1; while ( *(++next3) == ' ' && next3 < end ); printf(".TP\n.B "); prints(next, next2); putchar('\n'); prints(next3, end); putchar('\n'); } else { prints(start, end); putchar('\n'); } start = end + 2; } printf("\n.SH AUTHOR\nSMPQ is written by Pali Rohár \n\n.SH LICENSE\nSMPQ is distributed under GNU GPL v3\n"); return 0; } smpq-1.6/main.c0000664000175000017500000004021513014423420013321 0ustar palipali00000000000000/* main.c - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #if defined(WIN32) || defined(_MSC_VER) #define strcasecmp _stricmp #endif #ifdef _MSC_VER #define S_ISDIR(x) ((x) & _S_IFDIR) #endif #include "common.h" #define HELP \ "Usage: smpq [action] [options] [archive] [files]\n" \ "\n" \ "SMPQ - StormLib MPQ archiving utility, version " VERSION "\n" \ "\n" \ "Action:\n" \ " -c, --create Create new archive with file(s)\n" \ " -a, --append, --add Append file(s) to archive\n" \ " -d, -r, --delete, --remove Remove file(s) from archive\n" \ " -R, --rename Rename file in archive\n" \ " -l, --list List file(s) of archive\n" \ " -e, -x, --extract Extract file(s) from archive\n" \ " -i, --info Show info about archive\n" \ "\n" \ " -h, -u, --help, --usage Show this help/usage information\n" \ " -V, --license, --version Show version license information\n" \ "\n" \ "Options:\n" \ " -L, --listfile Additional external listfile (not used when appending file)\n" \ " -n, --no-system-listfiles Do not load system listfile(s) (not used when appending file)\n" \ " -N, --no-archive-listfile Do not use/create archive listfile (file names will not be read/stored)\n" \ " -A, --no-attributes Do not allow using file attributes (time, checksum, hash)\n" \ " -M, --mpq-version Specify MPQ archive version: (default: use new version 4)\n" \ " 1 support up to 4GB size of archive \n" \ " 2 support greater then 4GB size of archive (Introduced in World of Warcraft: The Burning Crusade)\n" \ " 3 (Introduced in World of Warcraft: Cataclysm Beta)\n" \ " 4 (Introduced in World of Warcraft: Cataclysm)\n" \ " -S, --sector-crc Store/Check CRC for each sector, ignored if file has none compression or is single unit\n" \ " -q, --quiet Be quiet, do not show any output\n" \ " -f, -o, --force, --overwrite Enable overwrite file(s)\n" \ " -v, --verbose Enable verbose output\n" \ " -O, --locale Set locale id (default: neutral=0)\n" \ " For all locale id see: http://msdn.microsoft.com/en-us/library/ms912047(WinEmbedded.10).aspx\n" \ "\n" \ "Options for appending file(s) to archive:\n" \ " -m, --max-file-count Set maximum file count of archive (power of 2, 0 - autodetect) (default: 0)\n" \ " -E, --encrypt Store as encrypted\n" \ " -F, --fix-key Encryption key will be adjusted according to file size in the archive (need -E)\n" \ " -D, --deletion-marker Set deletion marker\n" \ " -U, --single-unit Add file as single unit, cannot be encrypted\n" \ " -C, --compression Compression method: (default: ZLIB)\n" \ " none None compression\n" \ " IMPLODE Pkware Data Compression IMPLODE method - OBSOLETE (It was used only in Diablo I)\n" \ " PKWARE Pkware Data compression\n" \ " HUFFMANN Huffmann compression (Introduced in Starcraft I)\n" \ " ADPCM_MONO IMA ADPCM compression for 1-channel (mono) WAVE files - Lossy compression, only for WAVE files (Now it is not used)\n" \ " ADPCM_STEREO IMA ADPCM compression for 2-channel (stereo) WAVE files - Lossy compression, only for WAVE files (Now it is not used)\n" \ " ZLIB ZLIB compression (Introduced in Warcraft III)\n" \ " BZIP2 BZIP2 compression (Introduced in World of Warcraft: The Burning Crusade)\n" \ " SPARSE SPARSE compression (Introduced in Starcraft II)\n" \ " LZMA LZMA compression (Introduced in Starcraft II)\n" \ "\n" \ " HUFFMANN+ADPCM_MONO Together Huffmann and IMA ADPCM compression for 1-channel (mono) WAVE files\n" \ " HUFFMANN+ADPCM_STEREO Together Huffmann and IMA ADPCM compression for 2-channel (stereo) WAVE files\n" \ " ZLIB+PKWARE Together ZLIB and Pkware Data compression\n" \ " BZIP2+PKWARE Together BZIP2 and Pkware Data compression\n" \ " SPARSE+ZLIB Together SPARSE and ZLIB compression\n" \ " SPARSE+PKWARE Together SPARSE and Pkware Data compression\n" \ " SPARSE+BZIP2 Together SPARSE and BZIP2 compression\n" \ " SPARSE+ZLIB+PKWARE Together SPARSE, ZLIB and Pkware Data compression\n" \ " SPARSE+BZIP2+PKWARE Together SPARSE, BZIP2 and Pkware Data compression\n" \ "\n" \ "Options for extracting file(s) from archive:\n" \ " -P, --partial Archive is partial (default: autodetect) (Partial archives were used by trial version of World of Warcraft)\n" \ " -X, --not-encrypted Archive is not encrypted (default: autodetect) (Encrypted archives have Starcraft II installation)\n" \ " -p Open more (patched) archives with directory prefix (prefix:archive), when file is in more archives, will be extracted from last\n" \ " Usage with more (patched) archives:\n" \ " smpq -l|-x [options] [archive] -p [prefix1:archive1] [prefix2:archive2] ... -- [files]\n" \ "\n" \ "Examples:\n" \ " Create empty archive `archive.mpq'\n" \ " smpq -c archive.mpq\n" \ " Create archive `archive.mpq' with two files `file1.txt' and `file2.txt'\n" \ " smpq -c archive.mpq file1.txt file2.txt\n" \ " Extract all files from archive `archive.mpq' to current directory\n" \ " smpq -x archive.mpq\n" \ " Extract files with extension .txt from archive `archive.mpq'\n" \ " smpq -x archive.mpq '*.txt'\n" \ " Show information about archive `archive.mpq'\n" \ " smpq -i archive.mpq\n" \ "" #define LICENSE \ "SMPQ - StormLib MPQ archiving utility, version " VERSION "\n" \ "Copyright (C) 2010 - 2016 Pali Rohar \n" \ "\n" \ "This program is free software: you can redistribute it and/or modify\n" \ "it under the terms of the GNU General Public License as published by\n" \ "the Free Software Foundation, either version 3 of the License, or\n" \ "(at your option) any later version.\n" \ "\n" \ "This program is distributed in the hope that it will be useful,\n" \ "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" \ "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" \ "GNU General Public License for more details.\n" \ "\n" \ "You should have received a copy of the GNU General Public License\n" \ "along with this program. If not, see .\n" \ "" extern char StormLibCopyright[]; const char * app; static char action = 0; static unsigned int flags = 0; static unsigned int skip = 0; static void parse(char c) { switch ( c ) { case 'L': flags |= LISTFILE; skip = LISTFILE_ARG; break; case 'n': flags |= NO_SYSTEM_LF; break; case 'N': flags |= NO_LISTFILE; break; case 'A': flags |= NO_ATTRIBUTES; break; case 'M': flags |= MPQ_VERSION; skip = MPQ_VERSION_ARG; break; case 'S': flags |= SECTOR_CRC; break; case 'q': flags |= QUIET; break; case 'f': case 'o': flags |= OVERWRITE; break; case 'v': flags |= VERBOSE; break; case 'O': flags |= LOCALE; skip = LOCALE_ARG; break; case 'm': flags |= MAX_FILE_COUNT; skip = MAX_FILE_COUNT_ARG; break; case 'E': flags |= ENCRYPT; break; case 'F': flags |= FIX_KEY; break; case 'D': flags |= DELETE_MARKER; break; case 'U': flags |= SINGLE_UNIT; break; case 'C': flags |= COMPRESSION; skip = COMPRESSION_ARG; case 'p': flags |= MPQ_PATCHED; break; case 'P': flags |= MPQ_PARTIAL; break; case 'X': flags |= MPQ_NOT_ENCRYPTED; break; case 'c': case 'a': case 'd': case 'r': case 'R': case 'l': case 'e': case 'x': case 'i': if ( action != 0 ) { fprintf(stderr, "%s: Error: More then one action specified\n", app); exit(-1); } action = c; if ( action == 'l' ) { flags |= LIST; action = 'x'; } if ( action == 'c' ) { flags |= CREATE; action = 'a'; } if ( action == 'd' ) action = 'r'; if ( action == 'e' ) action = 'x'; break; case 'h': case 'u': printf(HELP); exit(0); case 'V': printf(LICENSE "\n\nSMPQ use %s\n", StormLibCopyright); exit(0); default: fprintf(stderr, "%s: Error: unknown option/action -%c specified\n", app, c); exit(-1); } } int main(int argc, char * argv[]) { int ret, i, j; int skipArg[10] = { 0 }; unsigned int mpq_version = 4; const char * listfile = NULL; unsigned int locale = 0; unsigned int maxFileCount = 0; const char * compression = "ZLIB"; const char * archive; int parchivesc; const char ** parchives; int filesc; const char ** files; app = argv[0]; for ( i = 1; i < argc; ++i ) { if ( skip ) { skipArg[skip] = i; skip = 0; continue; } if ( argv[i][0] != '-' ) break; if ( argv[i][1] == '-' ) { if ( strcmp(argv[i], "--create") == 0 ) parse('c'); else if ( strcmp(argv[i], "--append") == 0 || strcmp(argv[i], "--add") == 0 ) parse('a'); else if ( strcmp(argv[i], "--delete") == 0 || strcmp(argv[i], "--remove") == 0 ) parse('r'); else if ( strcmp(argv[i], "--rename") == 0 ) parse('R'); else if ( strcmp(argv[i], "--list") == 0 ) parse('l'); else if ( strcmp(argv[i], "--extract") == 0 ) parse('x'); else if ( strcmp(argv[i], "--info") == 0 ) parse('i'); else if ( strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "--usage") == 0 ) parse('h'); else if ( strcmp(argv[i], "--license") == 0 || strcmp(argv[i], "--version") == 0 ) parse('V'); else if ( strcmp(argv[i], "--listfile") == 0 ) parse('L'); else if ( strcmp(argv[i], "--no-system-listfiles") == 0 ) parse('n'); else if ( strcmp(argv[i], "--no-archive-listfile") == 0 ) parse('N'); else if ( strcmp(argv[i], "--no-attributes") == 0 ) parse('A'); else if ( strcmp(argv[i], "--mpq-version") == 0 ) parse('M'); else if ( strcmp(argv[i], "--sector-crc") == 0 ) parse('S'); else if ( strcmp(argv[i], "--quiet") == 0 ) parse('q'); else if ( strcmp(argv[i], "--force") == 0 || strcmp(argv[i], "--overwrite") == 0 ) parse('f'); else if ( strcmp(argv[i], "--verbose") == 0 ) parse('v'); else if ( strcmp(argv[i], "--locale") == 0 ) parse('O'); else if ( strcmp(argv[i], "--max-file-count") == 0 ) parse('m'); else if ( strcmp(argv[i], "--encrypt") == 0 ) parse('E'); else if ( strcmp(argv[i], "--fix-key") == 0 ) parse('F'); else if ( strcmp(argv[i], "--delete-marker") == 0 ) parse('D'); else if ( strcmp(argv[i], "--single-unit") == 0 ) parse('U'); else if ( strcmp(argv[i], "--compression") == 0 ) parse('C'); else if ( strcmp(argv[i], "--partial") == 0 ) parse('P'); else if ( strcmp(argv[i], "--not-encrypted") == 0 ) parse('X'); else { fprintf(stderr, "%s Error: unknown option/action %s specified\n", app, argv[i]); return -1; } continue; } for ( j = 1; j < (int)strlen(argv[i]); ++j ) parse(argv[i][j]); } if ( action == 0 ) { fprintf(stderr, "%s Error: No action specified\n", app); return -1; } if ( argc - i <= 0 ) { fprintf(stderr, "%s Error: No archive specified\n", app); return -1; } if ( flags & MPQ_VERSION ) { if ( skipArg[MPQ_VERSION_ARG] > argc-1 || skipArg[MPQ_VERSION_ARG] == 0 ) { fprintf(stderr, "%s Error: No MPQ archive version specified\n", app); return -1; } mpq_version = atoi(argv[skipArg[MPQ_VERSION_ARG]]); if ( mpq_version < 1 || mpq_version > 4 ) { fprintf(stderr, "%s Error: Unsupported MPQ archive version specified\n", app); return -1; } } if ( mpq_version == 1 ) flags |= MPQ_VERSION_1; else if ( mpq_version == 2 ) flags |= MPQ_VERSION_2; else if ( mpq_version == 3 ) flags |= MPQ_VERSION_3; else if ( mpq_version == 4 ) flags |= MPQ_VERSION_4; if ( flags & LISTFILE ) { struct stat st; if ( skipArg[LISTFILE_ARG] > argc-1 || skipArg[LISTFILE_ARG] == 0 ) { fprintf(stderr, "%s Error: No listfile specified\n", app); return -1; } listfile = argv[skipArg[LISTFILE_ARG]]; if ( stat(listfile, &st) == -1 ) { fprintf(stderr, "%s Error: Cannot stat listfile `%s': %s\n", app, listfile, strerror(errno)); return -1; } if ( S_ISDIR(st.st_mode) ) { fprintf(stderr, "%s Error: Cannot open listfile `%s': It is directory\n", app, listfile); return -1; } } if ( flags & LOCALE ) { if ( skipArg[LOCALE_ARG] > argc-1 || skipArg[LOCALE_ARG] == 0 ) { fprintf(stderr, "%s Error: No locale specified\n", app); return -1; } locale = atoi(argv[skipArg[LOCALE_ARG]]); } if ( flags & MAX_FILE_COUNT ) { if ( skipArg[MAX_FILE_COUNT_ARG] > argc-1 || skipArg[MAX_FILE_COUNT_ARG] == 0 ) { fprintf(stderr, "%s Error: No maximum file count specified\n", app); return -1; } maxFileCount = atoi(argv[skipArg[MAX_FILE_COUNT_ARG]]); } if ( flags & COMPRESSION ) { if ( skipArg[COMPRESSION_ARG] > argc-1 || skipArg[COMPRESSION_ARG] == 0 ) { fprintf(stderr, "%s Error: No MPQ compression method specified\n", app); return -1; } compression = argv[skipArg[COMPRESSION_ARG]]; } archive = argv[i++]; if ( ! ( flags & MPQ_NOT_ENCRYPTED ) && strlen(archive) > 5 && strcasecmp(archive+strlen(archive)-5, ".mpqe") == 0 ) flags |= MPQ_ENCRYPTED; if ( action == 'i' ) { if ( i < argc-1 ) { fprintf(stderr, "%s Error: Info need only one archive\n", app); return -1; } return smpq_info(archive, flags); } if ( action == 'R' ) { if ( i+1 < argc-1 ) { fprintf(stderr, "%s Error: Cannot rename more then one file\n", app); return -1; } return smpq_rename(archive, argv[i], argv[i+1], flags, listfile, locale); } parchivesc = argc - i - 1; parchives = (const char **)malloc(argc * sizeof(const char *)); if ( action == 'x' && i < argc && strcmp(argv[i], "-p") == 0 ) { while ( i < argc ) { if ( strcmp(argv[i], "--") == 0 ) break; ++i; parchives[parchivesc - argc + i] = argv[i]; } } if ( parchivesc - argc + i <= 0 ) { parchives[0] = NULL; } else { parchives[parchivesc - argc + i] = NULL; if ( i < argc ) ++i; } filesc = argc - i; files = (const char **)malloc(argc * sizeof(const char *)); for ( ; i < argc; ++i ) files[filesc - argc + i] = argv[i]; if ( action == 'x' ) { if ( filesc == 0 ) { filesc = 1; files[0] = "*"; } } else if ( action != 'a' || ! ( flags & CREATE ) ) { if ( filesc == 0 ) { fprintf(stderr, "%s Error: No file(s) specified\n", app); free((void *)parchives); free((void *)files); return -1; } } files[filesc] = NULL; switch ( action ) { case 'a': ret = smpq_append(archive, files, flags, locale, maxFileCount, compression); break; case 'x': ret = smpq_extract(archive, files, flags, listfile, locale, parchives); break; case 'r': ret = smpq_remove(archive, files, flags, listfile, locale); break; default: ret = 1; break; } free((void *)parchives); free((void *)files); return ret; } smpq-1.6/listfiles.c0000664000175000017500000000544712676030205014413 0ustar palipali00000000000000/* listfiles.cpp - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #if defined(WIN32) || defined(_MSC_VER) #define strcasecmp _stricmp #endif #ifdef _MSC_VER char * dirname(char *); #else #include #include #endif #include "common.h" void smpq_systemlistfiles(void * SArchive, const char * archive, unsigned int flags) { #if defined(WIN32) || defined(_MSC_VER) char processPath[512]; char * listfile; const char * LISTPATH; WIN32_FIND_DATA FindFileData; HANDLE hFind; GetModuleFileName(GetModuleHandle(NULL), processPath, sizeof(processPath)); LISTPATH = dirname(processPath); hFind = FindFirstFile(LISTPATH, &FindFileData); if ( hFind == INVALID_HANDLE_VALUE ) return; do { if ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) continue; listfile = (char *)malloc(strlen(LISTPATH) + strlen(FindFileData.cFileName) + 2); if ( ! listfile ) continue; strcpy(listfile, LISTPATH); strcpy(listfile+strlen(LISTPATH) + 1, FindFileData.cFileName); listfile[strlen(LISTPATH)] = '\\'; if ( flags & VERBOSE ) printVerbose(archive, "Loading system listfile", listfile); SFileAddListFile((HANDLE)SArchive, listfile); free(listfile); } while ( FindNextFile(hFind, &FindFileData) ); FindClose(hFind); #else #define LISTPATH "/usr/share/stormlib" struct dirent * ent; DIR * dir = opendir(LISTPATH); if ( ! dir ) return; while ( ( ent = readdir(dir) ) ) { struct stat st; char listfile[1024]; if ( strlen(LISTPATH)+strlen(ent->d_name)+2 > 1024 ) continue; if ( strcasecmp(ent->d_name+strlen(ent->d_name)-4, ".txt") != 0 ) continue; strcpy(listfile, LISTPATH); strcpy(listfile+strlen(LISTPATH)+1, ent->d_name); listfile[strlen(LISTPATH)] = '/'; if ( stat(listfile, &st) == -1 ) continue; if ( S_ISDIR(st.st_mode) ) continue; if ( flags & VERBOSE ) printVerbose(archive, "Loading system listfile", listfile); SFileAddListFile((HANDLE)SArchive, listfile); } closedir(dir); #undef LISTPATH #endif } smpq-1.6/kio_smpq.h0000664000175000017500000000437212676030205014240 0ustar palipali00000000000000/* kio_smpq.h - KDE4 KIO plugin for StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #ifndef KIO_SMPQ_H #define KIO_SMPQ_H #define KIO_SMPQ 0 #include #include struct SMPQSlavePrivate; class SMPQSlave : public KIO::SlaveBase { private: SMPQSlavePrivate * p; bool openArchive(const QString &archive, unsigned int flags = 0); void closeArchive(); bool parseUrl(const KUrl &url, QString &fileName, QByteArray &archivePath); void toArchivePath(QByteArray &to, const QString &from); void fromArchivePath(QString &to, const QByteArray &from); void toFileTime(quint64 &to, const quint64 &from); bool fromFileTime(quint64 &to, const quint64 &from); public: SMPQSlave(const QByteArray &protocol, const QByteArray &pool_socket, const QByteArray &app_socket); virtual ~SMPQSlave(); // virtual void openConnection(); // virtual void closeConnection(); virtual void get(const KUrl &url); virtual void put(const KUrl &url, int permissions, KIO::JobFlags flags); virtual void del(const KUrl &url, bool isfile); virtual void rename(const KUrl &src, const KUrl &dest, KIO::JobFlags flags); virtual void listDir(const KUrl &url); virtual void stat(const KUrl &url); virtual void mkdir(const KUrl &url, int permissions); virtual void slave_status(); // KIO::FileJob interface virtual void open(const KUrl &url, QIODevice::OpenMode mode); virtual void close(); virtual void read(KIO::filesize_t size); //virtual void write(const QByteArray &data); virtual void seek(KIO::filesize_t offset); }; #endif //KIO_SMPQ_H smpq-1.6/kio_smpq.cpp0000664000175000017500000005277312676030205014603 0ustar palipali00000000000000/* kio_smpq.cpp - KDE4 KIO plugin for StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kio_smpq.h" #ifdef Q_OS_UNIX #define LISTPATH "/usr/share/stormlib" #else #define LISTPATH KDEDIR "/share/stormlib" #endif //Q_OS_UNIX extern "C" { int KDE_EXPORT kdemain(int argc, char * argv[]) { kDebug(KIO_SMPQ); QCoreApplication app(argc, argv); KComponentData componentData("kio_smpq"); if ( argc != 4 ) { kDebug(KIO_SMPQ) << "Usage: kio_smpq protocol domain-socket1 domain-socket2"; return -1; } SMPQSlave slave(argv[1], argv[2], argv[3]); slave.dispatchLoop(); return 0; } } struct SMPQSlavePrivate { SMPQSlavePrivate() : SArchive(NULL), flags(0), SFile(NULL) { } HANDLE SArchive; QString archive; unsigned int flags; QDateTime modified; HANDLE SFile; QByteArray file; KUrl url; }; SMPQSlave::SMPQSlave(const QByteArray &protocol, const QByteArray &pool_socket, const QByteArray &app_socket) : KIO::SlaveBase(protocol, pool_socket, app_socket) { kDebug(KIO_SMPQ); p = new SMPQSlavePrivate; } SMPQSlave::~SMPQSlave() { kDebug(KIO_SMPQ); delete p; } bool SMPQSlave::parseUrl(const KUrl &url, QString &fileName, QByteArray &archivePath) { kDebug(KIO_SMPQ); QString path = url.path(); bool appended = false; if ( path.at(path.size() - 1) != KDIR_SEPARATOR ) { path.append(KDIR_SEPARATOR); appended = true; } int pos = 0; int nextPos = 0; while ( ( nextPos = path.indexOf(KDIR_SEPARATOR, pos + 1) ) != -1 ) { if ( ! QFileInfo(QFile::encodeName(path.left(nextPos))).exists() ) break; pos = nextPos; } if ( pos == 0 ) return false; if ( appended ) path.chop(1); fileName = QFile::encodeName(path.left(pos)); if ( ! QFileInfo(fileName).isFile() ) return false; toArchivePath(archivePath, path.mid(pos+1, -1)); return true; } bool SMPQSlave::openArchive(const QString &archive, unsigned int flags) { kDebug(KIO_SMPQ); if ( p->archive != archive || p->flags != flags || ! p->SArchive || QFileInfo(archive).lastModified() > p->modified ) { closeArchive(); if ( archive.endsWith(".mpqe", Qt::CaseInsensitive) ) flags |= STREAM_PROVIDER_MPQE; if ( ! SFileOpenArchive(archive.toUtf8(), 0, flags, &p->SArchive) ) return false; p->archive = archive; p->flags = flags; p->modified = QFileInfo(archive).lastModified(); QDir dir(LISTPATH); dir.setFilter(QDir::Files | QDir::Hidden); dir.setNameFilters(QStringList() << "*.txt" << "*.TXT"); QStringList files = dir.entryList(); for ( QStringList::Iterator it = files.begin(); it != files.end(); ++it ) SFileAddListFile(p->SArchive, dir.absoluteFilePath(*it).toUtf8()); SFileAddListFile(p->SArchive, NULL); } return true; } void SMPQSlave::closeArchive() { kDebug(KIO_SMPQ); if ( p->SArchive ) SFileCloseArchive(p->SArchive); p->archive.clear(); p->SArchive = NULL; p->flags = 0; p->file.clear(); p->SFile = NULL; } void SMPQSlave::toArchivePath(QByteArray &to, const QString &from) { #if KDIR_SEPARATOR == '\\' to = from.toUtf8(); #else to = from.toUtf8().replace(KDIR_SEPARATOR, '\\'); #endif // KDIR_SEPARATOR == '\\' } void SMPQSlave::fromArchivePath(QString &to, const QByteArray &from) { #if KDIR_SEPARATOR == '\\' to = QString::fromUtf8(from); #else to = QString::fromUtf8(from).replace('\\', KDIR_SEPARATOR); #endif // KDIR_SEPARATOR == '\\' } #define OFFSET 116444736000000000ULL // Number of 100 ns units between 01/01/1601 and 01/01/1970 #define NSEC 10000000ULL // Convert 100 ns to sec void SMPQSlave::toFileTime(quint64 &to, const quint64 &from) { if ( from == 0 ) to = 0; else to = from * NSEC + OFFSET; } bool SMPQSlave::fromFileTime(quint64 &to, const quint64 &from) { if ( from < OFFSET ) return false; to = ( from - OFFSET ) / NSEC; return true; } #undef OFFSET #undef NSEC /// //void SMPQSlave::openConnection() {} //void SMPQSlave::closeConnection() {} /// void SMPQSlave::get(const KUrl &url) { kDebug(KIO_SMPQ); QString fileName; QByteArray archivePath; if ( ! parseUrl(url, fileName, archivePath) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } if ( ! openArchive(fileName, STREAM_FLAG_READ_ONLY) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } HANDLE SFile = NULL; if ( ! SFileOpenFileEx(p->SArchive, archivePath, SFILE_OPEN_FROM_MPQ, &SFile) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } unsigned int low; unsigned int high; low = SFileGetFileSize(p->SFile, &high); totalSize(((KIO::filesize_t)high << 31) | low); bool eof = false; unsigned int bytes = 1024; QVarLengthArray buffer(bytes); if ( QString::fromUtf8(archivePath).endsWith(".mpq", Qt::CaseInsensitive) ) mimeType("application/x-mpq"); else if ( QString::fromUtf8(archivePath).endsWith(".mpqe", Qt::CaseInsensitive) ) mimeType("application/x-mpqe"); else { SFileReadFile(SFile, buffer.data(), buffer.size(), &bytes, NULL); QByteArray fileData = QByteArray::fromRawData(buffer.data(), bytes); KMimeType::Ptr fileMimeType = KMimeType::findByNameAndContent(url.fileName(), fileData); mimeType(fileMimeType->name()); } int dummy = 0; SFileSetFilePointer(SFile, 0, &dummy, FILE_BEGIN); buffer.resize(0x10000); KIO::filesize_t processedBytes = 0; while ( true ) { if ( ! SFileReadFile(SFile, buffer.data(), buffer.size(), &bytes, NULL) ) { eof = GetLastError() == ERROR_HANDLE_EOF; if ( ! eof ) { SFileCloseFile(SFile); error(KIO::ERR_COULD_NOT_READ, url.prettyUrl()); return; } } processedBytes += bytes; data(QByteArray::fromRawData(buffer.data(), bytes)); processedSize(processedBytes); if ( eof ) break; } SFileCloseFile(SFile); data(QByteArray()); finished(); } void SMPQSlave::put(const KUrl &url, int, KIO::JobFlags flags) { kDebug(KIO_SMPQ); QString fileName; QByteArray archivePath; if ( ! parseUrl(url, fileName, archivePath) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } if ( ! openArchive(fileName) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } if ( archivePath.size() == 16 && archivePath.left(4) == "File" && archivePath.at(12) == '.' ) { error(KIO::ERR_WRITE_ACCESS_DENIED, url.prettyUrl()); return; } if ( archivePath == "(listfile)" || archivePath == "(signature)" || archivePath == "(attributes)" || archivePath.contains("(patch_metadata)") ) { error(KIO::ERR_WRITE_ACCESS_DENIED, url.prettyUrl()); return; } QTemporaryFile file; if ( ! file.open() ) { error(KIO::ERR_DISK_FULL, QString()); return; } qint64 bytes; KIO::filesize_t totalBytes = 0; QByteArray buffer; while ( true ) { dataReq(); bytes = readData(buffer); if ( bytes <= 0 ) break; file.write(buffer); totalBytes += bytes; processedSize(totalBytes/2); } quint64 fileSize = file.size(); quint64 SFileTime = 0; quint64 fileTime = 0; const QString metaDataTime = metaData("modified"); if ( ! metaDataTime.isEmpty() ) fileTime = QDateTime::fromString(metaDataTime, Qt::ISODate).toTime_t(); toFileTime(SFileTime, fileTime); unsigned int SFlags = MPQ_FILE_COMPRESS; if ( flags & KIO::Overwrite ) SFlags |= MPQ_FILE_REPLACEEXISTING; HANDLE SFile; if ( ! SFileCreateFile(p->SArchive, archivePath, SFileTime, fileSize, 0, SFlags, &SFile) ) { if ( GetLastError() == ERROR_ALREADY_EXISTS ) error(KIO::ERR_FILE_ALREADY_EXIST, url.prettyUrl()); else error(KIO::ERR_COULD_NOT_WRITE, url.prettyUrl()); return; } file.seek(0); totalBytes = 0; while ( ( buffer = file.read(0x10000) ).size() > 0 ) { if ( ! SFileWriteFile(SFile, buffer, buffer.size(), MPQ_COMPRESSION_ZLIB) ) { error(KIO::ERR_COULD_NOT_WRITE, url.prettyUrl()); return; } totalBytes += buffer.size(); processedSize(fileSize/2+totalBytes/2); } processedSize(fileSize); SFileFinishFile(SFile); SFileFlushArchive(p->SArchive); p->modified = QFileInfo(p->archive).lastModified(); finished(); } void SMPQSlave::del(const KUrl &url, bool isfile) { kDebug(KIO_SMPQ); QString fileName; QByteArray archivePath; if ( ! parseUrl(url, fileName, archivePath) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } if ( ! openArchive(fileName) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } // Skip internal files in MPQ archive if ( archivePath == "(listfile)" || archivePath == "(signature)" || archivePath == "(attributes)" || archivePath.contains("(patch_metadata)") ) { error(KIO::ERR_WRITE_ACCESS_DENIED, url.prettyUrl()); return; } if ( ! isfile ) { QByteArray mask = archivePath; if ( mask.at(mask.size()-1) != '\\' ) mask.append("\\*"); else mask.append("*"); SFILE_FIND_DATA SFileFindData; HANDLE SFileFind = SFileFindFirstFile(p->SArchive, mask, &SFileFindData, NULL); // MPQ archives does not support directory structure // There are no files in this directory, so directory is empty // Only simulate deleting directory if ( ! SFileFind ) { finished(); return; } SFileFindClose(SFileFind); // TODO: KIO::ERR_COULD_NOT_RMDIR or KIO::ERR_CANNOT_DELETE ? error(KIO::ERR_CANNOT_DELETE, url.prettyUrl()); return; } if ( ! SFileRemoveFile(p->SArchive, archivePath, SFILE_OPEN_FROM_MPQ) ) { error(KIO::ERR_CANNOT_DELETE, url.prettyUrl()); return; } SFileCompactArchive(p->SArchive, NULL, 0); SFileFlushArchive(p->SArchive); p->modified = QFileInfo(p->archive).lastModified(); finished(); } void SMPQSlave::rename(const KUrl &src, const KUrl &dest, KIO::JobFlags flags) { kDebug(KIO_SMPQ); QString srcFileName; QByteArray srcArchivePath; QString destFileName; QByteArray destArchivePath; if ( ! parseUrl(src, srcFileName, srcArchivePath) ) { error(KIO::ERR_DOES_NOT_EXIST, src.prettyUrl()); return; } if ( ! parseUrl(dest, destFileName, destArchivePath) ) { error(KIO::ERR_DOES_NOT_EXIST, dest.prettyUrl()); return; } if ( srcFileName != destFileName ) { error(KIO::ERR_UNSUPPORTED_ACTION, QString()); return; } if ( srcArchivePath.isEmpty() || srcArchivePath.at(srcArchivePath.size() - 1) == '\\' ) { error(KIO::ERR_UNSUPPORTED_ACTION, QString()); return; } if ( ! openArchive(srcFileName) ) { error(KIO::ERR_DOES_NOT_EXIST, src.prettyUrl()); return; } // Skip internal files in MPQ archive if ( destArchivePath == "(listfile)" || destArchivePath == "(signature)" || destArchivePath == "(attributes)" || destArchivePath.contains("(patch_metadata)") ) { error(KIO::ERR_DOES_NOT_EXIST, dest.prettyUrl()); return; } HANDLE SFile; bool found; if ( ( found = SFileOpenFileEx(p->SArchive, destArchivePath, SFILE_OPEN_FROM_MPQ, &SFile) ) ) SFileCloseFile(SFile); if ( found && ! ( flags & KIO::Overwrite ) ) { error(KIO::ERR_FILE_ALREADY_EXIST, dest.prettyUrl()); return; } if ( found && ( flags & KIO::Overwrite ) ) { if ( ! SFileRemoveFile(p->SArchive, destArchivePath, SFILE_OPEN_FROM_MPQ) ) { error(KIO::ERR_CANNOT_RENAME, src.prettyUrl()); return; } SFileCompactArchive(p->SArchive, NULL, 0); SFileFlushArchive(p->SArchive); p->modified = QFileInfo(p->archive).lastModified(); } if ( ! SFileRenameFile(p->SArchive, srcArchivePath, destArchivePath) ) { error(KIO::ERR_CANNOT_RENAME, src.prettyUrl()); return; } SFileFlushArchive(p->SArchive); p->modified = QFileInfo(p->archive).lastModified(); finished(); } void SMPQSlave::listDir(const KUrl &url) { kDebug(KIO_SMPQ); QString fileName; QByteArray archivePath; if ( ! parseUrl(url, fileName, archivePath) ) { if ( QFileInfo(url.path()).exists() ) { redirection(KUrl(url.path())); finished(); return; } error(KIO::ERR_CANNOT_ENTER_DIRECTORY, url.prettyUrl()); return; } if ( ! archivePath.isEmpty() && archivePath.at(archivePath.size() - 1) != '\\' ) archivePath.append('\\'); if ( ! openArchive(fileName) ) { error(KIO::ERR_CANNOT_ENTER_DIRECTORY, url.prettyUrl()); return; } if ( archivePath.isEmpty() ) { KIO::UDSEntry entry; entry.insert(KIO::UDSEntry::UDS_NAME, "."); entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); entry.insert(KIO::UDSEntry::UDS_ACCESS, (S_IRWXU | S_IRWXG | S_IRWXO)); listEntry(entry, false); } QSet directories; SFILE_FIND_DATA SFileFindData; HANDLE SFileFind = SFileFindFirstFile(p->SArchive, archivePath + '*', &SFileFindData, NULL); if ( ! SFileFind ) { error(KIO::ERR_CANNOT_ENTER_DIRECTORY, url.prettyUrl()); return; } while ( true ) { QByteArray filePath = SFileFindData.cFileName; QByteArray fileName; if ( archivePath.isEmpty() ) fileName = filePath; else fileName = filePath.mid(archivePath.size(), -1); if ( fileName.contains('\\') ) { QByteArray dirName = fileName.split('\\').first(); if ( ! directories.contains(dirName) ) { KIO::UDSEntry entry; entry.insert(KIO::UDSEntry::UDS_NAME, QFile::decodeName(dirName)); entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); entry.insert(KIO::UDSEntry::UDS_ACCESS, (S_IRWXU | S_IRWXG | S_IRWXO)); listEntry(entry, false); directories.insert(dirName); } } else { quint64 fileTime = 0; quint64 SFileTime = SFileFindData.dwFileTimeLo | ( (quint64)SFileFindData.dwFileTimeHi << 32 ); fromFileTime(fileTime, SFileTime); KIO::UDSEntry entry; entry.insert(KIO::UDSEntry::UDS_NAME, QFile::decodeName(fileName)); entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG); entry.insert(KIO::UDSEntry::UDS_SIZE, SFileFindData.dwFileSize); entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, fileTime); entry.insert(KIO::UDSEntry::UDS_ACCESS, (S_IRWXU | S_IRWXG | S_IRWXO)); if ( QFile::decodeName(fileName).endsWith(".mpq", Qt::CaseInsensitive) ) entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "application/x-mpq"); else if ( QFile::decodeName(fileName).endsWith(".mpqe", Qt::CaseInsensitive) ) entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "application/x-mpqe"); listEntry(entry, false); } if ( ! SFileFindNextFile(SFileFind, &SFileFindData) ) break; } SFileFindClose(SFileFind); listEntry(KIO::UDSEntry(), true); finished(); } void SMPQSlave::stat(const KUrl &url) { kDebug(KIO_SMPQ); QString fileName; QByteArray archivePath; if ( ! parseUrl(url, fileName, archivePath) ) { if ( QFileInfo(url.path()).exists() ) { redirection(KUrl(url.path())); finished(); return; } error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } if ( archivePath.isEmpty() ) archivePath = "*"; if ( archivePath.at(archivePath.size() - 1) == '\\' ) archivePath.append('*'); if ( ! openArchive(fileName) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } SFILE_FIND_DATA SFileFindData; HANDLE SFileFind; HANDLE SFile; bool found = false; bool dir = false; if ( ! found ) { SFileFind = SFileFindFirstFile(p->SArchive, archivePath, &SFileFindData, NULL); if ( SFileFind ) { found = true; dir = false; SFileFindClose(SFileFind); } } if ( ! found ) { QByteArray mask = archivePath; if ( mask.at(mask.size()-1) != '\\' ) mask.append("\\*"); else mask.append("*"); SFileFind = SFileFindFirstFile(p->SArchive, mask, &SFileFindData, NULL); if ( SFileFind ) { found = true; dir = true; SFileFindClose(SFileFind); } } if ( ! found ) { if ( SFileOpenFileEx(p->SArchive, archivePath, SFILE_OPEN_FROM_MPQ, &SFile) ) { found = true; dir = false; SFileFindData.dwFileTimeLo = 0; SFileFindData.dwFileTimeHi = 0; unsigned int high = 0; unsigned int low = SFileGetFileSize(SFile, &high); SFileFindData.dwFileSize = low | ( (quint64)high << 32 ); SFileCloseFile(SFile); } } if ( ! found ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } KIO::UDSEntry entry; entry.insert(KIO::UDSEntry::UDS_NAME, url.path()); entry.insert(KIO::UDSEntry::UDS_ACCESS, (S_IRWXU | S_IRWXG | S_IRWXO)); if ( ! dir ) { quint64 fileTime = 0; quint64 SFileTime = SFileFindData.dwFileTimeLo | ( (quint64)SFileFindData.dwFileTimeHi << 32 ); fromFileTime(fileTime, SFileTime); entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFREG); entry.insert(KIO::UDSEntry::UDS_SIZE, SFileFindData.dwFileSize); entry.insert(KIO::UDSEntry::UDS_MODIFICATION_TIME, fileTime); if ( QString::fromUtf8(archivePath).endsWith(".mpq", Qt::CaseInsensitive) ) entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "application/x-mpq"); else if ( QString::fromUtf8(archivePath).endsWith(".mpqe", Qt::CaseInsensitive) ) entry.insert(KIO::UDSEntry::UDS_MIME_TYPE, "application/x-mpqe"); } else { entry.insert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); } statEntry(entry); finished(); } void SMPQSlave::mkdir(const KUrl &, int) { kDebug(KIO_SMPQ); // MPQ archives does not support directory structure // Only simulate creating directory finished(); } /// void SMPQSlave::slave_status() { kDebug(KIO_SMPQ); slaveStatus(QString(), (bool)p->SArchive); } /// // KIO::FileJob interface void SMPQSlave::open(const KUrl &url, QIODevice::OpenMode mode) { kDebug(KIO_SMPQ); QString fileName; QByteArray archivePath; if ( ! parseUrl(url, fileName, archivePath) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } unsigned int flags = 0; // 0 - read only // 1 - write only // 2 - append // 3 - read + write unsigned int myMode = -1; if ( mode & QIODevice::ReadWrite ) myMode = 3; else if ( mode & QIODevice::Append ) myMode = 2; else if ( mode & QIODevice::ReadOnly ) myMode = 0; else if ( mode & QIODevice::WriteOnly ) myMode = 1; if ( myMode == 0 ) { flags |= STREAM_FLAG_READ_ONLY; } else if ( myMode == 1 ) { // TODO: Add support for write only mode error(KIO::ERR_CANNOT_OPEN_FOR_WRITING, url.prettyUrl()); return; } else if ( myMode == 2 ) { // TODO: Add support for append mode error(KIO::ERR_CANNOT_OPEN_FOR_WRITING, url.prettyUrl()); return; } else if ( myMode == 3 ) { // TODO: Add support for read + write mode // Currently read mode is used flags |= STREAM_FLAG_READ_ONLY; } else { error(KIO::ERR_UNSUPPORTED_ACTION, url.prettyUrl()); return; } if ( ! openArchive(fileName, flags) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } // Skip internal files in MPQ archive if ( myMode != 0 ) { if ( archivePath == "(listfile)" || archivePath == "(signature)" || archivePath == "(attributes)" || archivePath.contains("(patch_metadata)") || ( archivePath.size() == 16 && archivePath.left(4) == "File" && archivePath.at(12) == '.' ) ) { error(KIO::ERR_WRITE_ACCESS_DENIED, url.prettyUrl()); return; } } if ( myMode == 0 ) { if ( ! SFileOpenFileEx(p->SArchive, archivePath, SFILE_OPEN_FROM_MPQ, &p->SFile) ) { error(KIO::ERR_DOES_NOT_EXIST, url.prettyUrl()); return; } } // TODO: open file for writing p->file = archivePath; p->url = url; if ( myMode == 0 || myMode == 3 ) { if ( QString::fromUtf8(archivePath).endsWith(".mpq", Qt::CaseInsensitive) ) mimeType("application/x-mpq"); else if ( QString::fromUtf8(archivePath).endsWith(".mpqe", Qt::CaseInsensitive) ) mimeType("application/x-mpqe"); else { unsigned int bytes = 1024; QVarLengthArray buffer(bytes); SFileReadFile(p->SFile, buffer.data(), buffer.size(), &bytes, NULL); QByteArray fileData = QByteArray::fromRawData(buffer.data(), bytes); KMimeType::Ptr fileMimeType = KMimeType::findByNameAndContent(url.fileName(), fileData); mimeType(fileMimeType->name()); int dummy = 0; SFileSetFilePointer(p->SFile, 0, &dummy, FILE_BEGIN); } } unsigned int low; unsigned int high; low = SFileGetFileSize(p->SFile, &high); totalSize(((KIO::filesize_t)high << 31) | low); position(0); opened(); } void SMPQSlave::close() { kDebug(KIO_SMPQ); SFileCloseFile(p->SFile); if ( p->SFile ) p->SFile = NULL; p->file.clear(); p->url.clear(); } void SMPQSlave::read(KIO::filesize_t size) { kDebug(KIO_SMPQ); bool eof = false; unsigned int bytes = size; QVarLengthArray buffer(bytes); if ( ! SFileReadFile(p->SFile, buffer.data(), buffer.size(), &bytes, NULL) ) { eof = GetLastError() == ERROR_HANDLE_EOF; if ( ! eof ) { close(); error(KIO::ERR_COULD_NOT_READ, p->url.prettyUrl()); return; } } data(QByteArray::fromRawData(buffer.data(), bytes)); if ( eof ) data(QByteArray()); } /*void SMPQSlave::write(const QByteArray &data) { kDebug(KIO_SMPQ); // TODO }*/ void SMPQSlave::seek(KIO::filesize_t offset) { kDebug(KIO_SMPQ); int low = offset & ( ( 1ULL << 32 ) - 1 ); int high = offset >> 32; unsigned int ret; if ( ( ret = SFileSetFilePointer(p->SFile, low, &high, FILE_BEGIN) ) == SFILE_INVALID_SIZE ) { error(KIO::ERR_COULD_NOT_SEEK, p->url.prettyUrl()); return; } position(((KIO::filesize_t)high << 32) | ret); } smpq-1.6/info.c0000664000175000017500000000604712676030205013345 0ustar palipali00000000000000/* info.cpp - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include "common.h" static inline unsigned int GetInfo(HANDLE SArchive, SFileInfoClass info) { unsigned int ret; if ( SFileGetFileInfo(SArchive, info, &ret, sizeof(ret), NULL) ) return ret; else return 0; } int smpq_info(const char * archive, unsigned int flags) { HANDLE SArchive = NULL; unsigned int streamFlags; unsigned int verify; unsigned int SFlags = STREAM_FLAG_READ_ONLY; if ( flags & MPQ_VERSION_1 ) SFlags |= MPQ_OPEN_FORCE_MPQ_V1; if ( flags & MPQ_ENCRYPTED ) SFlags |= STREAM_PROVIDER_MPQE; if ( ! SFileOpenArchive(archive, 0, SFlags, &SArchive) ) { printError(archive, "Cannot open archive", archive, GetLastError()); return -1; } printMessage("Archive name: %s", archive); printMessage("Archive size: %u", GetInfo(SArchive, SFileMpqArchiveSize)); printMessage("Number of files in archive: %u", GetInfo(SArchive, SFileMpqNumberOfFiles)); printMessage("Maximum file count of archive: %u", GetInfo(SArchive, SFileMpqMaxFileCount)); printMessage("Hash table size: %u", GetInfo(SArchive, SFileMpqHashTableSize)); printMessage("Block table size: %u", GetInfo(SArchive, SFileMpqBlockTableSize)); printMessage("Sector size: %u", GetInfo(SArchive, SFileMpqSectorSize)); streamFlags = GetInfo(SArchive, SFileMpqStreamFlags); if ( streamFlags & STREAM_PROVIDER_PARTIAL ) printMessage("Archive partial: Yes"); else printMessage("Archive partial: No"); if ( streamFlags & STREAM_PROVIDER_MPQE ) printMessage("Archive encryped: Yes"); else printMessage("Archive encryped: No"); verify = SFileVerifyArchive(SArchive); if ( verify == ERROR_NO_SIGNATURE ) printMessage("Archive signature: No signature"); else if ( verify == ERROR_VERIFY_FAILED ) printMessage("Archive signature: Verification failed"); else if ( verify == ERROR_WEAK_SIGNATURE_OK ) printMessage("Archive signature: Weak digital signature - Valid"); else if ( verify == ERROR_WEAK_SIGNATURE_ERROR ) printMessage("Archive signature: Weak digital signature - Invalid"); else if ( verify == ERROR_STRONG_SIGNATURE_OK ) printMessage("Archive signature: Strong digital signature - Valid"); else if ( verify == ERROR_STRONG_SIGNATURE_ERROR ) printMessage("Archive signature: Strong digital signature - Invalid or No public key"); SFileCloseArchive(SArchive); return 0; } smpq-1.6/extract.c0000664000175000017500000002163012676030205014057 0ustar palipali00000000000000/* extract.cpp - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #include #include #include #if defined(WIN32) || defined(_MSC_VER) #include #include #include #define mkdir _mkdir #define stat _stat #define utime _utime #define utimbuf _utimbuf #endif #ifdef _MSC_VER #define S_ISDIR(x) ((x) & _S_IFDIR) char * dirname(char *); #else #include #include #endif #include "common.h" static int mkpath(const char * s) { char * q = NULL; char * r = NULL; char * path = NULL; char * up = NULL; int rv = -1; #if defined(WIN32) || defined(_MSC_VER) if ( strcmp(s, "\\") == 0 ) return 0; #endif if ( strcmp(s, ".") == 0 || strcmp(s, "/") == 0 ) return 0; if ( ( path = strdup(s) ) == NULL ) return -1; if ( ( q = strdup(s) ) == NULL ) return -1; if ( ( r = dirname(q) ) == NULL ) goto out; if ( ( up = strdup(r) ) == NULL ) return -1; if ( ( mkpath(up) == -1 ) && ( errno != EEXIST ) ) goto out; #if defined(WIN32) || defined(_MSC_VER) if ( ( mkdir(path) != -1 ) || ( errno == EEXIST ) ) #else if ( ( mkdir(path, S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) != -1 ) || ( errno == EEXIST ) ) #endif rv = 0; out: if ( up != NULL ) free(up); free(q); free(path); return rv; } struct trie { struct trie * t[255]; int end; }; static const struct trie * trie_alloc(void) { struct trie * t = (struct trie *)calloc(1, sizeof(struct trie)); return t; } static void trie_free(const struct trie * t) { unsigned int i; if ( ! t ) return; for ( i = 0; i < 255; ++i ) if ( t->t[i] ) trie_free(t->t[i]); free((struct trie *)t); } static void trie_add(const struct trie * tr, const char * str) { unsigned int i; unsigned int len = strlen(str); struct trie * t = (struct trie *)tr; for ( i = 0; i < len; ++i ) { if ( ! t->t[(int)str[i]] ) t->t[(int)str[i]] = (struct trie *)trie_alloc(); t = t->t[(int)str[i]]; } t->end = 1; } static int trie_find(const struct trie * tr, const char * str) { unsigned int i; unsigned int len = strlen(str); struct trie * t = (struct trie *)tr; for ( i = 0; i < len; ++i ) { t = t->t[(int)str[i]]; if ( ! t ) return 0; } return t->end; } int smpq_extract(const char * archive, const char * const files[], unsigned int flags, const char * listfile, unsigned int locale, const char * const parchives[]) { int i, j; HANDLE SArchive = NULL; unsigned int SFlags = STREAM_FLAG_READ_ONLY; if ( flags & NO_LISTFILE ) SFlags |= MPQ_OPEN_NO_LISTFILE; if ( flags & NO_ATTRIBUTES ) SFlags |= MPQ_OPEN_NO_ATTRIBUTES; if ( flags & MPQ_VERSION_1 ) SFlags |= MPQ_OPEN_FORCE_MPQ_V1; if ( flags & SECTOR_CRC ) SFlags |= MPQ_OPEN_CHECK_SECTOR_CRC; if ( flags & MPQ_PARTIAL ) SFlags |= STREAM_PROVIDER_PARTIAL; if ( flags & MPQ_ENCRYPTED ) SFlags |= STREAM_PROVIDER_MPQE; if ( ! SFileOpenArchive(archive, 0, SFlags, &SArchive) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot open archive", archive, GetLastError()); return -1; } for ( i = 0; parchives[i]; ++i ) { char * parchive; const char * prefix; if ( ( parchive = strchr((char *)parchives[i], ':') ) ) { *parchive = 0; ++parchive; prefix = parchives[i]; } else { parchive = (char *)parchives[i]; prefix = ""; } if ( flags & VERBOSE ) printVerbose(archive, "Opening patched archive", parchive); if ( ! SFileOpenPatchArchive(SArchive, parchive, prefix, 0) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot open patched archive", parchive, GetLastError()); SFileCloseArchive(SArchive); return -1; } } if ( ! ( flags & NO_SYSTEM_LF ) ) smpq_systemlistfiles(SArchive, archive, flags); if ( ! ( flags & NO_LISTFILE ) ) SFileAddListFile(SArchive, NULL); SFileSetLocale(locale); SFlags = SFILE_OPEN_FROM_MPQ; for ( i = 0; files[i]; ++i ) { const struct trie * t; char mask[512]; SFILE_FIND_DATA SFileFindData; HANDLE SFileFind = NULL; toArchivePath(mask, files[i]); SFileFind = SFileFindFirstFile(SArchive, mask, &SFileFindData, listfile); if ( ! SFileFind ) { HANDLE SFile; SFileFind = (HANDLE)0xFFFFFFFF; SFileFindData.dwFileTimeLo = 0; SFileFindData.dwFileTimeHi = 0; strcpy(SFileFindData.cFileName, mask); if ( SFileOpenFileEx(SArchive, mask, SFlags, &SFile) ) { unsigned int high = 0; unsigned int low = SFileGetFileSize(SFile, (DWORD*)&high); SFileGetFileName(SFile, mask); SFileFindData.dwFileSize = low | ( (unsigned long long int)high << 32 ); SFileCloseFile(SFile); } } t = trie_alloc(); while ( SFileFind ) { struct stat st; FILE * file = NULL; char fileName[1024]; char fileDir[1024]; unsigned int fileSize = SFileFindData.dwFileSize; time_t fileTime = 0; HANDLE SFile = NULL; const char * SFileName = SFileFindData.cFileName; unsigned long long int SFileTime = SFileFindData.dwFileTimeLo | ( ((unsigned long long int)SFileFindData.dwFileTimeHi) << 32 ); int last = 0; char buffer[0x10000]; size_t bytes = 1; if ( strlen(SFileFindData.cFileName)+1 > 1024 ) goto next; if ( strcmp(SFileName, "(listfile)") == 0 || strcmp(SFileName, "(signature)") == 0 || strcmp(SFileName, "(attributes)") == 0 || strstr(SFileName, "(patch_metadata)") != NULL ) goto next; fromArchivePath(fileName, SFileName); if ( trie_find(t, SFileName) ) goto next; else trie_add(t, SFileName); if ( ! fromFileTime(&fileTime, SFileTime) ) fileTime = 0; if ( ! SFileOpenFileEx(SArchive, SFileName, SFlags, &SFile) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot open file in archive", SFileName, GetLastError()); goto next; } j = -1; while ( SFileName[++j] ) if ( SFileName[j] == '\\' ) last = j; if ( ( flags & VERBOSE ) && ! ( flags & LIST ) ) printVerbose(archive, "Extract", fileName); if ( ( flags & LIST ) ) { char strtime[80]; strftime(strtime, 80, "%Y-%m-%d %H:%M", localtime(&fileTime)); printMessage("%12u %s %s", fileSize, strtime, fileName); } if ( flags & LIST ) goto next; memcpy(fileDir, fileName, last); fileDir[last] = 0; if ( last != 0 ) { if ( mkpath(fileDir) != 0 ) { if ( ! ( flags & QUIET ) ) { printError(archive, "Cannot create directory", fileDir, errno); printError(archive, "Cannot extract file", fileName, ENOENT); } goto next; } } if ( stat(fileName, &st) != -1 ) { if ( ! ( flags & OVERWRITE ) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot extract file", fileName, EEXIST); goto next; } if ( S_ISDIR(st.st_mode) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot extract file", fileName, EISDIR); goto next; } if ( flags & VERBOSE ) printVerbose(archive, "Remove old file", fileName); if ( unlink(fileName) != 0 ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot remove existing file", fileName, errno); goto next; } } file = fopen(fileName, "wb"); if ( ! file ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot open file", fileName, errno); goto next; } while ( 1 ) { int eof = 0; if ( ! SFileReadFile(SFile, buffer, sizeof(buffer), (DWORD *)&bytes, NULL) ) { eof = ( GetLastError() == ERROR_HANDLE_EOF ); if ( ! eof ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot read file", SFileName, GetLastError()); break; } } if ( fwrite(buffer, 1, bytes, file) != bytes ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot write file", fileName, errno); break; } if ( eof ) break; } fclose(file); { struct utimbuf fileTimeBuf = { fileTime, fileTime }; utime(fileName, &fileTimeBuf); } next: if ( SFile ) SFileCloseFile(SFile); if ( SFileFind == (HANDLE)0xFFFFFFFF ) break; if ( ! SFileFindNextFile(SFileFind, &SFileFindData) ) break; } trie_free(t); if ( SFileFind != (HANDLE)0xFFFFFFFF ) SFileFindClose(SFileFind); } SFileCloseArchive(SArchive); return 0; } smpq-1.6/dirname.c0000664000175000017500000001543112676030205014026 0ustar palipali00000000000000/* dirname.c * * $Id: dirname.c,v 1.2 2007/03/08 23:15:58 keithmarshall Exp $ * * Provides an implementation of the "dirname" function, conforming * to SUSv3, with extensions to accommodate Win32 drive designators, * and suitable for use on native Microsoft(R) Win32 platforms. * * Written by Keith Marshall * * This is free software. You may redistribute and/or modify it as you * see fit, without restriction of copyright. * * This software is provided "as is", in the hope that it may be useful, * but WITHOUT WARRANTY OF ANY KIND, not even any implied warranty of * MERCHANTABILITY, nor of FITNESS FOR ANY PARTICULAR PURPOSE. At no * time will the author accept any form of liability for any damages, * however caused, resulting from the use of this software. * */ #include #include #include //#include #include #ifndef __cdecl /* If compiling on any non-Win32 platform ... */ #define __cdecl /* this may not be defined. */ #endif char * __cdecl dirname(char *path) { static char *retfail = NULL; size_t len; /* to handle path names for files in multibyte character locales, * we need to set up LC_CTYPE to match the host file system locale. */ char *locale = setlocale (LC_CTYPE, NULL); if (locale != NULL) locale = strdup (locale); setlocale (LC_CTYPE, ""); if (path && *path) { /* allocate sufficient local storage space, * in which to create a wide character reference copy of path. */ wchar_t *refcopy, *refpath; len = mbstowcs (NULL, path, 0); refcopy = (wchar_t *) malloc (1+len); if (!refcopy) return NULL; /* create the wide character reference copy of path */ refpath = refcopy; len = mbstowcs (refpath, path, len); refcopy[len] = L'\0'; /* SUSv3 identifies a special case, where path is exactly equal to "//"; * (we will also accept "\\" in the Win32 context, but not "/\" or "\/", * and neither will we consider paths with an initial drive designator). * For this special case, SUSv3 allows the implementation to choose to * return "/" or "//", (or "\" or "\\", since this is Win32); we will * simply return the path unchanged, (i.e. "//" or "\\"). */ if (len > 1 && (refpath[0] == L'/' || refpath[0] == L'\\')) { if (refpath[1] == refpath[0] && refpath[2] == L'\0') { setlocale (LC_CTYPE, locale); free (refcopy); free (locale); return path; } } /* For all other cases ... * step over the drive designator, if present ... */ else if (len > 1 && refpath[1] == L':') { /* FIXME: maybe should confirm *refpath is a valid drive designator. */ refpath += 2; } /* check again, just to ensure we still have a non-empty path name ... */ if (*refpath) { # undef basename # define basename __the_basename /* avoid shadowing. */ /* reproduce the scanning logic of the "basename" function * to locate the basename component of the current path string, * (but also remember where the dirname component starts). */ wchar_t *refname, *basename; for (refname = basename = refpath; *refpath; ++refpath) { if (*refpath == L'/' || *refpath == L'\\') { /* we found a dir separator ... * step over it, and any others which immediately follow it. */ while (*refpath == L'/' || *refpath == L'\\') ++refpath; /* if we didn't reach the end of the path string ... */ if (*refpath) /* then we have a new candidate for the base name. */ basename = refpath; else /* we struck an early termination of the path string, * with trailing dir separators following the base name, * so break out of the for loop, to avoid overrun. */ break; } } /* now check, * to confirm that we have distinct dirname and basename components. */ if (basename > refname) { /* and, when we do ... * backtrack over all trailing separators on the dirname component, * (but preserve exactly two initial dirname separators, if identical), * and add a NUL terminator in their place. */ do --basename; while (basename > refname && (*basename == L'/' || *basename == L'\\')); if (basename == refname && (refname[0] == L'/' || refname[0] == L'\\') && refname[1] == refname[0] && refname[2] != L'/' && refname[2] != L'\\') ++basename; *++basename = L'\0'; /* if the resultant dirname begins with EXACTLY two dir separators, * AND both are identical, then we preserve them. */ refpath = refcopy; while ((*refpath == L'/' || *refpath == L'\\')) ++refpath; if ((refpath - refcopy) > 2 || refcopy[1] != refcopy[0]) refpath = refcopy; /* and finally ... * we remove any residual, redundantly duplicated separators from the dirname, * reterminate, and return it. */ refname = refpath; while (*refpath) { if ((*refname++ = *refpath) == L'/' || *refpath++ == L'\\') { while (*refpath == L'/' || *refpath == L'\\') ++refpath; } } *refname = L'\0'; /* finally ... * transform the resolved dirname back into the multibyte char domain, * restore the caller's locale, and return the resultant dirname. */ if ((len = wcstombs( path, refcopy, len )) != (size_t)(-1)) path[len] = '\0'; } else { /* either there were no dirname separators in the path name, * or there was nothing else ... */ if (*refname == L'/' || *refname == L'\\') { /* it was all separators, so return one. */ ++refname; } else { /* there were no separators, so return '.'. */ *refname++ = L'.'; } /* add a NUL terminator, in either case, * then transform to the multibyte char domain, * using our own buffer. */ *refname = L'\0'; retfail = realloc (retfail, len = 1 + wcstombs (NULL, refcopy, 0)); wcstombs (path = retfail, refcopy, len); } /* restore caller's locale, clean up, and return the resolved dirname. */ setlocale (LC_CTYPE, locale); free (refcopy); free (locale); return path; } # undef basename free (refcopy); } /* path is NULL, or an empty string; default return value is "." ... * return this in our own buffer, regenerated by wide char transform, * in case the caller trashed it after a previous call. */ retfail = realloc (retfail, len = 1 + wcstombs (NULL, L".", 0)); wcstombs (retfail, L".", len); /* restore caller's locale, clean up, and return the default dirname. */ setlocale (LC_CTYPE, locale); free (locale); return retfail; } smpq-1.6/common.h0000664000175000017500000001715313023633623013707 0ustar palipali00000000000000/* common.h - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #if defined(_MSC_VER) #define inline __inline #elif defined(__STRICT_ANSI__) #define inline __inline__ #endif /********* * Flags * *********/ #define CREATE 1 << 0 #define LIST 1 << 0 /* Options - program */ #define QUIET 1 << 1 #define OVERWRITE 1 << 2 #define VERBOSE 1 << 3 /* Options - archive types */ #define MPQ_VERSION 1 << 4 #define MPQ_VERSION_1 1 << 5 #define MPQ_VERSION_2 1 << 6 #define MPQ_VERSION_3 1 << 7 #define MPQ_VERSION_4 1 << 8 #define MPQ_PATCHED 1 << 9 #define MPQ_PARTIAL 1 << 10 #define MPQ_ENCRYPTED 1 << 11 #define MPQ_NOT_ENCRYPTED 1 << 12 /* Options - archive open/create */ #define NO_SYSTEM_LF 1 << 14 #define NO_LISTFILE 1 << 15 #define LISTFILE 1 << 16 #define NO_ATTRIBUTES 1 << 17 #define SECTOR_CRC 1 << 18 #define MAX_FILE_COUNT 1 << 19 /* Options - file */ #define LOCALE 1 << 20 #define ENCRYPT 1 << 21 #define FIX_KEY 1 << 22 #define DELETE_MARKER 1 << 23 #define SINGLE_UNIT 1 << 24 #define COMPRESSION 1 << 25 /* Options - with arguments */ #define MPQ_VERSION_ARG 1 #define LISTFILE_ARG 2 #define MAX_FILE_COUNT_ARG 3 #define LOCALE_ARG 4 #define COMPRESSION_ARG 5 /************* * Variables * *************/ /* Application name */ extern const char * app; /*********************************************** * Functions for manipulating with MPQ archive * ***********************************************/ /** * Create new archive and/or append file(s) to archive * * Internaly this function calls SFileCreateArchive or SFileOpenArchive for getting access to archive. * For each file check if it has correct name and calls SFileCreateFile. Next it uses SFileWriteFile for writing file data to archive. */ int smpq_append(const char * archive, const char * const files[], unsigned int flags, unsigned int locale, unsigned int maxFileCount, const char * compression); /** * Extract or print list files from archive * * Internaly this function open archive throw SFileOpenArchive and append all patched archives to memmory by calling SFileOpenPatchArchive * For each file mask it calls SFileFindFirstFile. Is return first (and then continue searching) valid file with mask and then it try * extract using functions SFileOpenFileEx and SFileReadFile. MPQ archives does not have stored real filenames (only hashes) so original * file names must be stored in other list text file (MPQ archives does not support directory structures, so for this is used standard * windows separator = char backslash '\'). So SFileFindFirstFile only tries check if file witch given name from list is correct * for stored hashes. When we use more patched archives it is normal that file with same name is in more patched archives (so search * function return one file name more times). To prevent extracting one file more times, smpq remember extracted files. For this is used * dictionary struct trie, which spend linear time (of path) for remeber file and linear time too for check if file is in this structre * (if file was extracted). When is needed to extract file with long path and subdirs does not exist, smpq will use function mkpath, * which recursive create needed directories (find separator '/'). */ int smpq_extract(const char * archive, const char * const files[], unsigned int flags, const char * listfile, unsigned int locale, const char * const parchives[]); /** * Show info about archive * * Internaly this function only calls StormLib GetInfo function. */ int smpq_info(const char * archive, unsigned int flags); /** * Remove file(s) from archive * * Internaly this function only calls for each specified file SFileRemoveFile if exist. */ int smpq_remove(const char * archive, const char * const files[], unsigned int flags, const char * listfile, unsigned int locale); /** * Rename file in archive * * Internaly this function only calls for each specified file SFileRenameFile if exist. */ int smpq_rename(const char * archive, const char * oldName, const char * newName, unsigned int flags, const char * listfile, unsigned int locale); /** * Load system listfiles for archive to memory * * Internaly this function looks for all *.txt files in system StormLib directory and tries load all text list files to memory * by calling SFileAddListFile. On Windows is this directory same with directory where are smpq executable. */ void smpq_systemlistfiles(void * SArchive, const char * archive, unsigned int flags); /************************ * Functions for output * ************************/ /* Print formatted error message */ void printError(const char * archive, const char * file, const char * message, int errnum); /* Print verbose message */ void printVerbose(const char * archive, const char * message, const char * file); /* Print normal message */ void printMessage(const char * message, ...); /************************************* * Functions for FILETIME conversion * *************************************/ /** * MPQ archives stores modification time of files in FILETIME format. * These function convert FILETIME to/from Unix timestamp which is default format */ #define OFFSET 116444736000000000ULL /* Number of 100 ns units between 01/01/1601 and 01/01/1970 */ #define NSEC 10000000ULL /* Convert 100 ns to sec */ #define TYPE_SIGNED(TYPE) ( (TYPE) 0 > (TYPE) -1 ) #define TYPE_SHIFT(TYPE) ( sizeof(TYPE) * CHAR_BIT - TYPE_SIGNED(TYPE) - 1 ) #define TYPE_MAX(TYPE) ( (TYPE)( ~( 1ULL << TYPE_SHIFT(TYPE) ) << 1 ) + 1 ) /* Convert time_t to FILETIME */ static inline void toFileTime(unsigned long long int * to, time_t from) { if ( from == 0 ) *to = 0; else *to = from * NSEC + OFFSET; } /* Convert FILETIME to time_t */ static inline int fromFileTime(time_t * to, unsigned long long int from) { if ( from < OFFSET ) return 0; if ( ( from - OFFSET ) / NSEC > TYPE_MAX(time_t) ) return 1; *to = ( from - OFFSET ) / NSEC; return 1; } #undef TYPE_SIGNED #undef TYPE_LEN #undef TYPE_MAX #undef OFFSET #undef NSEC /********************************************** * Functions for path conversation in archive * **********************************************/ /** * MPQ archives does not support directory structures. Instead it store full path to file in file name * As default MPQ archives are designed for Windows, so dir separator is backslash character. * These functions convert Windows file path to/from Unix */ /* Replace all chars '/' in path to '\\' */ static inline void toArchivePath(char * to, const char * from) { int i = -1; while ( from[++i] ) { if ( from[i] == '/' ) to[i] = '\\'; else to[i] = from[i]; } to[i] = 0; } /* Replace all chars '\\' in path to '/' on other OS than Windows */ static inline void fromArchivePath(char * to, const char * from) { #if defined(WIN32) || defined(_MSC_VER) strcpy(to, from); #else int i = -1; while ( from[++i] ) { if ( from[i] == '\\' ) to[i] = '/'; else to[i] = from[i]; } to[i] = 0; #endif } smpq-1.6/check.c0000664000175000017500000000016412735737002013466 0ustar palipali00000000000000#include #if STORMLIB_VERSION < 0x0914 #error You have old Stormlib version #endif int main(void) {} smpq-1.6/append.c0000664000175000017500000002176613023637001013660 0ustar palipali00000000000000/* append.cpp - StormLib MPQ archiving utility Copyright (C) 2010 - 2016 Pali Rohár This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include #include #include #include #include #if defined(WIN32) || defined(_MSC_VER) #define strcasecmp _stricmp #define strncasecmp _strnicmp #endif #include "common.h" int smpq_append(const char * archive, const char * const files[], unsigned int flags, unsigned int locale, unsigned int maxFileCount, const char * compression) { unsigned int SFlags = 0; unsigned int SCompFlags = 0; int i; HANDLE SArchive = NULL; if ( flags & ENCRYPT ) SFlags |= MPQ_FILE_ENCRYPTED; if ( flags & FIX_KEY ) SFlags |= MPQ_FILE_FIX_KEY; if ( flags & DELETE_MARKER ) SFlags |= MPQ_FILE_DELETE_MARKER; if ( flags & SECTOR_CRC ) SFlags |= MPQ_FILE_SECTOR_CRC; if ( flags & SINGLE_UNIT ) SFlags |= MPQ_FILE_SINGLE_UNIT; if ( flags & OVERWRITE ) SFlags |= MPQ_FILE_REPLACEEXISTING; if ( compression != NULL ) { if ( strcmp(compression, "none") == 0 ) { } else if ( strcasecmp(compression, "IMPLODE") == 0 ) { SFlags |= MPQ_FILE_IMPLODE; } else { SFlags |= MPQ_FILE_COMPRESS; if ( strcasecmp(compression, "HUFFMANN") == 0 ) SCompFlags |= MPQ_COMPRESSION_HUFFMANN; else if ( strcasecmp(compression, "ADPCM_MONO") == 0 ) SCompFlags |= MPQ_COMPRESSION_ADPCM_MONO; else if ( strcasecmp(compression, "ADPCM_STEREO") == 0 ) SCompFlags |= MPQ_COMPRESSION_ADPCM_STEREO; else if ( strcasecmp(compression, "ZLIB") == 0 ) SCompFlags |= MPQ_COMPRESSION_ZLIB; else if ( strcasecmp(compression, "PKWARE") == 0 ) SCompFlags |= MPQ_COMPRESSION_PKWARE; else if ( strcasecmp(compression, "BZIP2") == 0 ) SCompFlags |= MPQ_COMPRESSION_BZIP2; else if ( strcasecmp(compression, "SPARSE") == 0 ) SCompFlags |= MPQ_COMPRESSION_SPARSE; else if ( strcasecmp(compression, "LZMA") == 0 ) SCompFlags |= MPQ_COMPRESSION_LZMA; else if ( strcasecmp(compression, "HUFFMANN+ADPCM_MONO") == 0 ) SCompFlags |= MPQ_COMPRESSION_HUFFMANN | MPQ_COMPRESSION_ADPCM_MONO; else if ( strcasecmp(compression, "HUFFMANN+ADPCM_STEREO") == 0 ) SCompFlags |= MPQ_COMPRESSION_HUFFMANN | MPQ_COMPRESSION_ADPCM_STEREO; else if ( strcasecmp(compression, "ZLIB+PKWARE") == 0 ) SCompFlags |= MPQ_COMPRESSION_ZLIB | MPQ_COMPRESSION_PKWARE; else if ( strcasecmp(compression, "BZIP2+PKWARE") == 0 ) SCompFlags |= MPQ_COMPRESSION_BZIP2 | MPQ_COMPRESSION_PKWARE; else if ( strcasecmp(compression, "SPARSE+ZLIB") == 0 ) SCompFlags |= MPQ_COMPRESSION_SPARSE | MPQ_COMPRESSION_ZLIB; else if ( strcasecmp(compression, "SPARSE+PKWARE") == 0 ) SCompFlags |= MPQ_COMPRESSION_SPARSE | MPQ_COMPRESSION_PKWARE; else if ( strcasecmp(compression, "SPARSE+BZIP2") == 0 ) SCompFlags |= MPQ_COMPRESSION_SPARSE | MPQ_COMPRESSION_BZIP2; else if ( strcasecmp(compression, "SPARSE+ZLIB+PKWARE") == 0 ) SCompFlags |= MPQ_COMPRESSION_SPARSE | MPQ_COMPRESSION_ZLIB | MPQ_COMPRESSION_PKWARE; else if ( strcasecmp(compression, "SPARSE+BZIP2+PKWARE") == 0 ) SCompFlags |= MPQ_COMPRESSION_SPARSE | MPQ_COMPRESSION_BZIP2 | MPQ_COMPRESSION_PKWARE; else if ( strcasecmp(compression, "choose") == 0 ) { if ( ! ( flags & QUIET ) ) printError(archive, "Choose the best compression is not implemented yet", compression, EINVAL); return -1; } else { if ( ! ( flags & QUIET ) ) printError(archive, "Specified unknown compression method", compression, EINVAL); return -1; } } } if ( flags & CREATE ) { struct stat st; unsigned int SOpenFlags = 0; if ( ( flags & OVERWRITE ) && stat(archive, &st) == 0 ) { if ( flags & VERBOSE ) printVerbose(archive, "Remove old archive", archive); if ( unlink(archive) != 0 ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot remove existing archive", archive, errno); return -1; } } if ( flags & VERBOSE ) printVerbose(archive, "Create new archive", archive); if ( flags & MPQ_VERSION_1 ) SOpenFlags |= MPQ_CREATE_ARCHIVE_V1; else if ( flags & MPQ_VERSION_2 ) SOpenFlags |= MPQ_CREATE_ARCHIVE_V2; else if ( flags & MPQ_VERSION_3 ) SOpenFlags |= MPQ_CREATE_ARCHIVE_V3; else SOpenFlags |= MPQ_CREATE_ARCHIVE_V4; if ( ! ( flags & NO_ATTRIBUTES ) ) SOpenFlags |= MPQ_CREATE_ATTRIBUTES; if ( maxFileCount == 0 ) for ( i = 0; files[i]; ++i ) ++maxFileCount; if ( maxFileCount < 4 ) maxFileCount = 4; if ( ! SFileCreateArchive(archive, SOpenFlags, maxFileCount, &SArchive) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot create archive", archive, GetLastError()); return -1; } } else { unsigned int SOpenFlags = 0; if ( flags & NO_LISTFILE ) SOpenFlags |= MPQ_OPEN_NO_LISTFILE; if ( flags & NO_ATTRIBUTES ) SOpenFlags |= MPQ_OPEN_NO_ATTRIBUTES; if ( flags & MPQ_VERSION_1 ) SOpenFlags |= MPQ_OPEN_FORCE_MPQ_V1; if ( ! SFileOpenArchive(archive, 0, SOpenFlags, &SArchive) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot open archive", archive, GetLastError()); return -1; } if ( maxFileCount == 0 ) { unsigned int fileCount; if ( ! SFileGetFileInfo(SArchive, SFileMpqNumberOfFiles, &fileCount, sizeof(fileCount), 0) ) fileCount = 0; for ( i = 0; files[i]; ++i ) ++fileCount; if ( ! SFileGetFileInfo(SArchive, SFileMpqMaxFileCount, &maxFileCount, sizeof(maxFileCount), 0) ) maxFileCount = 0; if ( maxFileCount < fileCount ) maxFileCount = fileCount; else maxFileCount = 0; } if ( maxFileCount != 0 ) { if ( flags & VERBOSE ) printVerbose(archive, "Change maximum file count", archive); if ( ! SFileSetMaxFileCount(SArchive, maxFileCount) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot change maximum file count", archive, GetLastError()); SFileCloseArchive(SArchive); return -1; } } } SFileSetLocale(locale); for ( i = 0; files[i]; ++i ) { struct stat st; FILE * file = NULL; const char * fileName = files[i]; size_t fileSize = 0; HANDLE SFile = NULL; char SFileName[1024]; unsigned long long int SFileTime = 0; char buffer[0x10000]; size_t bytes = 0; if ( strlen(fileName) + 1 > 1024 ) { if ( ! ( flags & QUIET ) ) printError(archive, "File `%s' has too long path. Cannot create new file", SFileName, EPERM); continue; } toArchivePath(SFileName, fileName); if ( strlen(SFileName) == 16 && strncasecmp(SFileName, "File", 4) == 0 && SFileName[12] == '.' ) { if ( ! ( flags & QUIET ) ) printError(archive, "File with mask `File????????.???\' is not allowed. Cannot create new file", SFileName, EPERM); continue; } if ( strcmp(SFileName, "(listfile)") == 0 || strcmp(SFileName, "(signature)") == 0 || strcmp(SFileName, "(attributes)") == 0 || strstr(SFileName, "(patch_metadata)") != NULL ) { if ( ! ( flags & QUIET ) ) printError(archive, "Files `(listfile)' `(signature)' `(attributes)' `(patch_metadata)' are for internal usage. Cannot create new file", SFileName, EPERM); continue; } file = fopen(fileName, "rb"); if ( ! file ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot open file", fileName, errno); continue; } fseek(file, 0, SEEK_END); fileSize = ftell(file); rewind(file); if ( flags & VERBOSE ) printVerbose(archive, "Append file", SFileName); if ( stat(fileName, &st) == -1 ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot stat file", fileName, errno); fclose(file); continue; } toFileTime(&SFileTime, st.st_mtime); if ( ! SFileCreateFile(SArchive, SFileName, SFileTime, fileSize, locale, SFlags, &SFile) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot create new file", SFileName, GetLastError()); fclose(file); continue; } while ( 1 ) { bytes = fread(buffer, 1, sizeof(buffer), file); if ( ferror(file) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot read file", fileName, errno); break; } if ( ! SFileWriteFile(SFile, buffer, bytes, SCompFlags) ) { if ( ! ( flags & QUIET ) ) printError(archive, "Cannot write file new", SFileName, GetLastError()); break; } if ( feof(file) ) break; } fclose(file); SFileFinishFile(SFile); SFileFlushArchive(SArchive); } if ( flags & OVERWRITE ) SFileCompactArchive(SArchive, NULL, 0); SFileCloseArchive(SArchive); return 0; } smpq-1.6/README0000664000175000017500000000765013023622471013126 0ustar palipali00000000000000================ About ================ SMPQ is StormLib MPQ archiving utility. This utility is designed for full manipulating with Blizzard MPQ archives. It supports extracting, appending, renaming and deleting files in MPQ archives. It also can create MPQ archive. SMPQ can access to different type of MPQ archives and version. It support encrypted, compressed, partial and patched MPQ archives with version 1-4. SMPQ is free open source command line utility written in C/C++ which use multiplatform C++ StormLib library. Part of SMPQ is KDE4 KIO plugin which add support for all KDE4 applications (e.g. Konqueror, Dolphin, Kate, ... and all KDE4 open/save dialogs) access to MPQ archives like to directory or network drive (or FTP). This is simple way how to integrate MPQ support on KDE4 desktop (There is no need to use some MPQ viewer/editor. All KDE4 application can open MPQ archives in read/write mode). Author: Pali Rohár Version: 1.6 License: GNU GPL v3 Homepage: https://launchpad.net/smpq ================ How to build ================ Dependencies for SMPQ: * ANSI C90 compiler (gcc works fine) * StormLib (minimal version 9.20) from http://www.zezula.net/en/mpq/download.html#StormLib * CMake (minimal version 2.6) from http://www.cmake.org/cmake/resources/software.html Additional dependencies for KDE4 KIO plugin: * C++ 98 compiler (g++ works fine) * KDE4 libs headers (part of kdelibs package) from http://www.kde.org/download/ Additional dependencies for Windows NSIS Installer: * NSIS from http://nsis.sourceforge.net/ * UPX from http://upx.sourceforge.net/ Building on Debian/*buntu and Debian like Linux distributions: $ sudo apt-get install fakeroot debhelper cmake libstorm-dev libstorm-listfiles kdelibs5-dev $ dpkg-buildpackage -b -rfakeroot $ sudo dpkg -i ../*.deb Ubuntu packages are built in SMPQ PPA on https://launchpad.net/~pali/+archive/smpq Building on other *nix: Commands to build only SMPQ command line utility (without KDE4 KIO plugin): $ rm -rf build && mkdir -p build && cd build $ cmake -DWITH_KDE=OFF -DCMAKE_INSTALL_PREFIX=/usr .. $ make $ sudo make install Commands to build SMPQ with KDE4 KIO plugin: $ rm -rf build && mkdir -p build && cd build $ cmake -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` .. $ make $ sudo make install Commands to build only KDE4 KIO plugin: $ rm -rf build && mkdir -p build && cd build $ cmake -DWITH_CMD=OFF -DCMAKE_INSTALL_PREFIX=`kde4-config --prefix` .. $ make $ sudo make install Building on Windows: Commands to build only SMPQ command line utility: Download and unpack SMPQ to C:\smpq. Open command line in folder C:\smpq C:\smpq> del /r /q build && md build && cd build C:\smpq\build> cmake -DWITH_KDE=OFF .. C:\smpq\build> make This will build executable C:\smpq\build\smpq.exe Commands to build SMPQ command line utility into Windows NSIS Installer: Download and unpack SMPQ to C:\smpq. Open command line in folder C:\smpq C:\smpq> del /r /q build && md build && cd build C:\smpq\build> cmake -DWITH_KDE=OFF -DWITH_NSIS=ON .. C:\smpq\build> make This will build installer executable C:\smpq\build\SMPQ-.exe Note: Sometimes after (re)installing KDE4 KIO plugin is needed to restart KDE4. ================ How to use ================ SMPQ command line utility: For detailed info see * user manpage: $ man 1 smpq * runtime help: $ smpq --help KDE4 KIO plugin: Open Konqueror, Dolphin or other KDE4 file manager and simply open MPQ archive ================ Changelog ================ See file CHANGELOG ================ Links ================ SMPQ Homepage: https://launchpad.net/smpq CMake homepage: http://www.cmake.org KDE homepage: http://www.kde.org NSIS homepage: http://nsis.sourceforge.net UPX homepage: http://upx.sourceforge.net StormLib library: http://www.zezula.net/en/mpq/stormlib.html MPQ documentation: http://wiki.devklog.net/index.php?title=The_MoPaQ_Archive_Format smpq-1.6/COPYING0000664000175000017500000010451312065607370013303 0ustar palipali00000000000000 GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . smpq-1.6/CMakeLists.txt0000664000175000017500000001245313023622462015003 0ustar palipali00000000000000# # CMakeLists.txt - cmake for StormLib MPQ archiving utility # Copyright (C) 2010 - 2012 Pali Rohár # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # project(SMPQ) set(VERSION 1.6) cmake_minimum_required(VERSION 2.6) option(WITH_CMD "Enable smpq console application" ON) option(WITH_KDE "Enable KDE4 kio_smpq plugin" ON) if(WIN32) option(WITH_NSIS "Create Windows NSIS Installer" OFF) endif(WIN32) if(NOT STORMLIB_INCLUDE_DIR OR NOT STORMLIB_LIBRARY) find_path(STORMLIB_INCLUDE_DIR StormLib.h) find_library(STORMLIB_LIBRARY NAMES StormLib storm) if(NOT STORMLIB_INCLUDE_DIR) message(FATAL_ERROR "StormLib.h header file not found") endif(NOT STORMLIB_INCLUDE_DIR) if(NOT STORMLIB_LIBRARY) message(FATAL_ERROR "StormLib or storm library not found") endif(NOT STORMLIB_LIBRARY) try_compile(CHECK ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/check.c COMPILE_DEFINITIONS -I${STORMLIB_INCLUDE_DIR}) if(NOT CHECK) message(FATAL_ERROR "Found old StormLib version") endif(NOT CHECK) message(STATUS "Found StormLib header: ${STORMLIB_INCLUDE_DIR}/StormLib.h") message(STATUS "Found StormLib library: ${STORMLIB_LIBRARY}") mark_as_advanced(STORMLIB_INCLUDE_DIR STORMLIB_LIBRARY) endif(NOT STORMLIB_INCLUDE_DIR OR NOT STORMLIB_LIBRARY) include_directories(${STORMLIB_INCLUDE_DIR}) add_definitions(-DVERSION="${VERSION}") set(SMPQ_SRCS append.c extract.c info.c listfiles.c main.c print.c remove.c rename.c ) if(MSVC) set(SMPQ_SRCS ${SMPQ_SRCS} dirname.c ) endif(MSVC) set(MANGEN_SRCS mangen.c ) set(KIO_SMPQ_SRCS kio_smpq.cpp ) set(SMPQ_NSIS ${CMAKE_CURRENT_SOURCE_DIR}/smpq.nsi ) if(WITH_CMD) add_executable(smpq ${SMPQ_SRCS}) target_link_libraries(smpq ${STORMLIB_LIBRARY}) if(WIN32 AND NOT MSVC) set_target_properties(smpq PROPERTIES LINK_FLAGS -static) target_link_libraries(smpq wininet stdc++) endif(WIN32 AND NOT MSVC) install(TARGETS smpq DESTINATION bin) if(NOT CMAKE_CROSSCOMPILING) add_executable(mangen ${MANGEN_SRCS}) add_custom_command(OUTPUT smpq.1 COMMAND mangen > smpq.1 DEPENDS mangen) add_custom_target(man ALL DEPENDS smpq.1) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/smpq.1 DESTINATION share/man/man1) endif(NOT CMAKE_CROSSCOMPILING) if(WIN32 AND WITH_NSIS) find_package(SelfPackers REQUIRED) if(NOT MAKENSIS) find_program(MAKENSIS makensis) if(NOT MAKENSIS) message(FATAL_ERROR "makensis not found") else(NOT MAKENSIS) message(STATUS "Found makensis: ${MAKENSIS}") endif(NOT MAKENSIS) mark_as_advanced(MAKENSIS) endif(NOT MAKENSIS) if(CMAKE_SIZEOF_VOID_P STREQUAL 4) set(MAKENSIS_OUTPUT SMPQ-${VERSION}.exe) else(CMAKE_SIZEOF_VOID_P STREQUAL 4) set(MAKENSIS_FLAGS -DX86_64 ${MAKENSIS_FLAGS}) set(MAKENSIS_OUTPUT SMPQ-${VERSION}-x86_64.exe) endif(CMAKE_SIZEOF_VOID_P STREQUAL 4) if(NOT CMAKE_VERBOSE_MAKEFILE) set(MAKENSIS_FLAGS -V2 -DQUIET ${MAKENSIS_FLAGS}) endif(NOT CMAKE_VERBOSE_MAKEFILE) set(MAKENSIS_FLAGS ${MAKENSIS_FLAGS} -DUPX="${SELF_PACKER_FOR_EXECUTABLE}" -DVERSION="${VERSION}" -NOCD) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/COPYING DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/README DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) if(CMAKE_SIZEOF_VOID_P STREQUAL 4) add_custom_command(TARGET smpq POST_BUILD COMMAND ${SELF_PACKER_FOR_EXECUTABLE} ARGS ${SELF_PACKER_FOR_EXECUTABLE_FLAGS} -qq -9 smpq${CMAKE_EXECUTABLE_SUFFIX} ) endif(CMAKE_SIZEOF_VOID_P STREQUAL 4) add_custom_command(OUTPUT ${MAKENSIS_OUTPUT} COMMAND ${MAKENSIS} ARGS ${MAKENSIS_FLAGS} ${SMPQ_NSIS} DEPENDS smpq smpq.nsi COPYING README CHANGELOG) add_custom_target(installer ALL DEPENDS ${MAKENSIS_OUTPUT}) endif(WIN32 AND WITH_NSIS) endif(WITH_CMD) if(WITH_KDE) find_package(KDE4 REQUIRED) include(KDE4Defaults) set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}) set_target_properties(KDE4__kdecore PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES_DEBIAN "Qt4::QtCore") set_target_properties(KDE4__kio PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES_DEBIAN "KDE4__kdecore") include_directories(${KDE4_INCLUDES}) set(CMAKE_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES};${QT_INCLUDE_DIR}") check_symbol_exists(Q_OS_UNIX "QtCore/qglobal.h" Q_OS_UNIX) if(NOT Q_OS_UNIX) add_definitions(-DKDEDIR=${CMAKE_INSTALL_PREFIX}) endif(NOT Q_OS_UNIX) kde4_add_plugin(kio_smpq ${KIO_SMPQ_SRCS}) target_link_libraries(kio_smpq ${STORMLIB_LIBRARY} ${KDE4_KIO_LIBS}) install(TARGETS kio_smpq DESTINATION ${PLUGIN_INSTALL_DIR}) install(FILES smpq.protocol DESTINATION ${SERVICES_INSTALL_DIR}) install(FILES smpq.xml DESTINATION ${XDG_MIME_INSTALL_DIR}) endif(WITH_KDE) smpq-1.6/CHANGELOG0000664000175000017500000000316713023636115013457 0ustar palipali00000000000000smpq 1.6 * Fix spelling * Check for StromLib version before building * Show StormLibCopyright in --version and --license * Use only ASCII characters on console * Set correct manpage encoding (UTF-8) * Replace no-break space by normal space * Fix TYPE_MAX macro smpq 1.5 * Use archive list file if -N is not specified * Added support to only create empty mpq archive without any files * Use strcasecmp only where is needed (winapi alternative is _stricmp) * Added support for partial archives, Add examples to help * Rewrite smpq to C - StormLib 8.20 has finally C compatible header files * Use build date instead hardcoded in man page * Do not use variable length arrays and anonymous variadic macros * Set max file count to at least 6 * Better support for Windows and MSVC compiler * kio_smpq - Do not ignore internal listfile * Use StormLib 9.20 smpq 1.4 * Remove option -I (--index) - not used in new version of stormlib library * Some minor and code style fixes * Update debian files, fixed lintian warnings/errors smpq 1.3 * Cleaned CMakeLists.txt * Fixed printing verbose message * Fixed multiplatform using size_t * Decrease MPQ max file count after deleting file * Depends on StormLib version 8.02 smpq 1.2 * Fixed using signed/unsigned integers * Replaced option for setting hash table size by setting maximum file count * Rewrited hash table size to maximum file count (deleted from StromLib) * Autodetect maximum file count of archive when appending files smpq 1.1 * Fixed compilation on target x86_64 * Fixed default value of Hash Table Size smpq 1.0 * Final release 1.0 smpq-1.6/AUTHORS0000664000175000017500000000004312065607370013311 0ustar palipali00000000000000Pali Rohár