From 034aa81895b201164004d79aa090e882e3e66945 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 10 Apr 2022 15:24:32 +0200 Subject: Moved archives list from static part of impl to loader member Including Archive.h in DataLoader.h created name conflicts and created an error due to missing types from Types.h in the Archive.h itself. --- StarsEx/Archive.cpp | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'StarsEx/Archive.cpp') diff --git a/StarsEx/Archive.cpp b/StarsEx/Archive.cpp index 9d859c2..ca73ec5 100644 --- a/StarsEx/Archive.cpp +++ b/StarsEx/Archive.cpp @@ -55,7 +55,7 @@ void DataArchive::WriteEntry(int index, BYTE* buf) int f = _open(datafile, _O_RDWR|_O_CREAT|_O_BINARY, _S_IREAD|_S_IWRITE); if (f != -1) { - header.dir_size_comp = DirBlocks() * BLOCK_SIZE; + header.dir_size_comp = DirBlocks() * Archive::BLOCK_SIZE; dirbuf = new BYTE[header.dir_size_comp]; if (!dirbuf) { @@ -67,7 +67,7 @@ void DataArchive::WriteEntry(int index, BYTE* buf) (BYTE*) directory, header.nfiles * sizeof(DataEntry)); CHECK_ERR(err, "compress"); - header.dir_blocks = Blocks(header.dir_size_comp) * BLOCK_SIZE; + header.dir_blocks = Blocks(header.dir_size_comp) * Archive::BLOCK_SIZE; _lseek(f, 0, SEEK_SET); _write(f, &header, sizeof(DataHeader)); @@ -92,8 +92,8 @@ void DataArchive::WriteEntry(int index, BYTE* buf) DWORD DataArchive::Blocks(DWORD raw_size) { - int full_blocks = raw_size / BLOCK_SIZE; - int part_blocks = (raw_size % BLOCK_SIZE) > 0; + int full_blocks = raw_size / Archive::BLOCK_SIZE; + int part_blocks = (raw_size % Archive::BLOCK_SIZE) > 0; return full_blocks + part_blocks; } @@ -123,16 +123,16 @@ void DataArchive::CreateBlockMap() if (header.nfiles == 0) return; DWORD i,j; - DWORD dir_usage = header.dir_offset + DirBlocks() * BLOCK_SIZE; + DWORD dir_usage = header.dir_offset + DirBlocks() * Archive::BLOCK_SIZE; DWORD max_usage = dir_usage; for (i = 0; i < header.nfiles; i++) { - DWORD last_block = directory[i].offset + FileBlocks(i) * BLOCK_SIZE; + DWORD last_block = directory[i].offset + FileBlocks(i) * Archive::BLOCK_SIZE; if (last_block > max_usage) max_usage = last_block; } - nblocks = max_usage/BLOCK_SIZE; + nblocks = max_usage/Archive::BLOCK_SIZE; block_map = new DWORD[nblocks]; if (!block_map) { @@ -142,15 +142,15 @@ void DataArchive::CreateBlockMap() else { ZeroMemory(block_map, nblocks*sizeof(DWORD)); - DWORD first_block = header.dir_offset/BLOCK_SIZE + - (header.dir_offset%BLOCK_SIZE > 0); + DWORD first_block = header.dir_offset/Archive::BLOCK_SIZE + + (header.dir_offset%Archive::BLOCK_SIZE > 0); for (j = 0; j < DirBlocks(); j++) block_map[first_block+j] = 1; for (i = 0; i < header.nfiles; i++) { - DWORD first_block = directory[i].offset/BLOCK_SIZE + - (directory[i].offset%BLOCK_SIZE > 0); + DWORD first_block = directory[i].offset/Archive::BLOCK_SIZE + + (directory[i].offset%Archive::BLOCK_SIZE > 0); for (j = 0; j < FileBlocks(i); j++) block_map[first_block+j] = i+2; @@ -169,13 +169,13 @@ int DataArchive::FindDataBlocks(int need) for (start = 0; start < nblocks-need; start++) { for (i = 0; block_map[start+i] == 0 && i < need; i++); - if (i == need) return start*BLOCK_SIZE; + if (i == need) return start*Archive::BLOCK_SIZE; start += i; } } - return nblocks*BLOCK_SIZE; + return nblocks*Archive::BLOCK_SIZE; } // +--------------------------------------------------------------------+ @@ -188,14 +188,14 @@ void DataArchive::LoadDatafile(const char* name) delete [] block_map; ZeroMemory(this, sizeof(DataArchive)); - strncpy_s(datafile, name, NAMELEN-1); + strncpy_s(datafile, name, Archive::NAMELEN-1); FILE* f; fopen_s(&f, datafile, "rb"); if (f) { fread(&header, sizeof(DataHeader), 1, f); - if (header.version != VERSION) { + if (header.version != Archive::VERSION) { Print("ERROR: datafile '%s' invalid version '%d'\n", datafile, header.version); fclose(f); @@ -203,7 +203,7 @@ void DataArchive::LoadDatafile(const char* name) return; } - DWORD len = DirBlocks() * BLOCK_SIZE; + DWORD len = DirBlocks() * Archive::BLOCK_SIZE; DWORD dirsize = header.nfiles + 64; dirbuf = new BYTE[len]; @@ -234,7 +234,7 @@ void DataArchive::LoadDatafile(const char* name) else { Print("Creating Archive '%s'...\n", datafile); - header.version = VERSION; + header.version = Archive::VERSION; header.nfiles = 0; header.dir_blocks = 0; header.dir_size_comp = 0; @@ -398,9 +398,9 @@ int DataArchive::InsertEntry(const char* name) if (directory && dirsize) { for (int i = 0; i < dirsize; i++) { if (directory[i].size_orig == 0) { - ZeroMemory(directory[i].name, NAMELEN); - strncpy_s(directory[i].name, path, NAMELEN); - directory[i].name[NAMELEN-1] = '\0'; + ZeroMemory(directory[i].name, Archive::NAMELEN); + strncpy_s(directory[i].name, path, Archive::NAMELEN); + directory[i].name[Archive::NAMELEN-1] = '\0'; directory[i].size_orig = 1; return i; @@ -420,9 +420,9 @@ int DataArchive::InsertEntry(const char* name) header.nfiles = dirsize + 64; directory = dir; - ZeroMemory(directory[dirsize].name, NAMELEN); - strncpy_s(directory[dirsize].name, path, NAMELEN); - directory[dirsize].name[NAMELEN-1] = '\0'; + ZeroMemory(directory[dirsize].name, Archive::NAMELEN); + strncpy_s(directory[dirsize].name, path, Archive::NAMELEN); + directory[dirsize].name[Archive::NAMELEN-1] = '\0'; directory[dirsize].size_orig = 1; return dirsize; -- cgit v1.1