Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <ostream>
- #include <Windows.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <vector>
- #include <string>
- using namespace std;
- const unsigned char data[24] = {
- 0x18, 0x00, 0x04, 0x01,
- 0x00, 0x00, 0x00, 0x00,
- 0x5E, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00
- };
- struct UpdateFileHeader
- {
- UINT16 HdrSize; // always 0x0018
- BYTE override; // 0x01 => override with new file; 0x04 => update file (bsdiff)
- BYTE version; // always 0x04
- UINT32 unknown3;
- UINT32 OldFileSize; // file size before the update (uncompressed)
- UINT32 NewFileSize; // size of the entire file after the update is applied (uncompressed)
- UINT32 unknown6; // always 0
- UINT32 unknown7; // always 0
- };
- struct SearchFile
- {
- typedef std::vector<std::string> FileNameArray;
- FileNameArray files;
- FileNameArray::iterator begin()
- {
- return files.begin();
- }
- FileNameArray::iterator end()
- {
- return files.end();
- }
- int count() const
- {
- return (int)files.size();
- }
- std::string operator[](int index)
- {
- return files[index];
- }
- void operator()(const std::string &path, const std::string &pattern)
- {
- WIN32_FIND_DATA wfd;
- HANDLE hf;
- std::string findwhat;
- std::vector<std::string> dir;
- findwhat = path + "\\*"; // directory
- hf = FindFirstFile(findwhat.c_str(), &wfd);
- while (hf != INVALID_HANDLE_VALUE)
- {
- if (wfd.cFileName[0] != '.' && (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
- {
- std::string found;
- found = path + "\\" + wfd.cFileName;
- dir.push_back(found);
- }
- if (!FindNextFile(hf, &wfd))
- {
- FindClose(hf);
- hf = INVALID_HANDLE_VALUE;
- }
- }
- findwhat = path + "\\" + pattern; // files
- hf = FindFirstFile(findwhat.c_str(), &wfd);
- while (hf != INVALID_HANDLE_VALUE)
- {
- if (wfd.cFileName[0] != '.' && !(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
- {
- std::string found;
- found = path + "\\" + wfd.cFileName;
- files.push_back(found);
- }
- if (!FindNextFile(hf, &wfd))
- {
- FindClose(hf);
- hf = INVALID_HANDLE_VALUE;
- }
- }
- // continue with directories
- for (std::vector<std::string>::iterator it = dir.begin(); it != dir.end(); ++it)
- this->operator()(*it, pattern);
- }
- };
- int main(void)
- {
- SearchFile sf;
- sf("C:\\Users\\Harry\\Desktop\\test3\\", "*.*");
- for (int i = 0; i != sf.count(); ++i)
- {
- string path(sf[i].c_str());
- string filename;
- size_t pos = path.find_last_of("\\");
- if(pos != string::npos)
- filename.assign(path.begin() + pos + 1, path.end());
- else
- filename = path;
- ofstream OutFile;
- OutFile.open("C:\\Users\\Harry\\Desktop\\test5\\" + filename, ios::binary);
- UpdateFileHeader test;
- test.HdrSize = 18;
- test.NewFileSize = 0;
- test.OldFileSize = 0;
- test.override = 4;
- test.unknown3 = 0;
- test.unknown6 = 0;
- test.unknown7 = 0;
- test.version = 4;
- const char* output = reinterpret_cast<const char*>(data);
- OutFile.write(output, 24);
- ifstream file(sf[i].c_str(), ios::in | ios::binary | ios::ate);
- ifstream::pos_type fileSize;
- char* fileContents;
- if(file.is_open())
- {
- fileSize = file.tellg();
- test.NewFileSize = fileSize;
- fileContents = new char[fileSize];
- file.seekg(0, ios::beg);
- if(!file.read(fileContents, fileSize))
- {
- printf("Failed to read.\n");
- }
- file.close();
- OutFile.write(fileContents, fileSize);
- delete[] fileContents;
- }
- OutFile.close();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment