Skip to content

Commit

Permalink
RAII pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
hozuki committed Oct 4, 2018
1 parent e2ac87f commit 0913d5c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/apps/acbunpack/acbunpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,20 @@ int main(int argc, const char *argv[]) {
return -1;
}

auto *fileStream = new CFileStream(filePath, FileMode::OpenExisting, FileAccess::Read);
auto *acb = new CAcbFile(fileStream, filePath);
CFileStream fileStream(filePath, FileMode::OpenExisting, FileAccess::Read);
CAcbFile acb(&fileStream, filePath);

acb.Initialize();

const std::string fileDir = GetDirectoryFromPath(filePath);
const std::string extractDir = fileDir + "/_acb_" + GetFileNameFromPath(filePath) + "/";

acb->Initialize();

MakeDirectories(extractDir);

const auto &fileNames = acb->GetFileNames();
const auto &fileNames = acb.GetFileNames();

uint32_t i = 0;

for (const auto &fileName : fileNames) {
auto s = fileName;
auto isCueNonEmpty = !s.empty();
Expand All @@ -65,9 +66,9 @@ int main(int argc, const char *argv[]) {
IStream *stream;

if (isCueNonEmpty) {
stream = acb->OpenDataStream(s.c_str());
stream = acb.OpenDataStream(s.c_str());
} else {
stream = acb->OpenDataStream(i);
stream = acb.OpenDataStream(i);
}

if (stream) {
Expand All @@ -82,9 +83,6 @@ int main(int argc, const char *argv[]) {
++i;
}

delete acb;
delete fileStream;

return 0;
}

Expand Down Expand Up @@ -138,7 +136,8 @@ std::string GetFileNameFromPath(const std::string &s) {

void CopyStream(IStream *src, IStream *dst) {
const size_t bufferSize = 10240;
uint8_t buffer[bufferSize] = {0};
uint8_t
buffer[bufferSize] = {0};
uint32_t read = 1;

while (read > 0) {
Expand Down

0 comments on commit 0913d5c

Please sign in to comment.