A bunch of minor tweaks from cppcheck

This commit is contained in:
Pk11
2021-03-26 06:01:37 -05:00
parent e06d475131
commit c95d66f0e4
19 changed files with 110 additions and 204 deletions
+1 -1
View File
@@ -436,7 +436,7 @@ Result downloadFromRelease(const std::string &url, const std::string &asset, con
@return True if Wi-Fi is connected; false if not.
*/
bool checkWifiStatus(void) {
//return true; // For citra.
// return true; // For citra.
u32 wifiStatus;
bool res = false;
-1
View File
@@ -68,7 +68,6 @@ Result extractArchive(const std::string &archivePath, const std::string &wantedF
archive *a = archive_read_new();
archive_entry *entry;
a = archive_read_new();
archive_read_support_format_all(a);
if (archive_read_open_filename(a, archivePath.c_str(), 0x4000) != ARCHIVE_OK) {
+14 -50
View File
@@ -87,19 +87,6 @@ void getDirectoryContents(std::vector<DirEntry> &dirContents) {
getDirectoryContents(dirContents, {});
}
std::vector<std::string> getContents(const std::string &name, const std::vector<std::string> &extensionList) {
std::vector<std::string> dirContents;
DIR *pdir = opendir(name.c_str());
struct dirent *pent;
while ((pent = readdir(pdir)) != NULL) {
if (nameEndsWith(pent->d_name, extensionList)) dirContents.push_back(pent->d_name);
}
closedir(pdir);
return dirContents;
}
/*
Return UniStore info.
@@ -188,17 +175,20 @@ u32 copyBuf[copyBufSize];
/*
Copy a directory.
DirEntry *entry: Pointer to a DirEntry.
DirEntry &entry: A DirEntry reference.
const char *destinationPath: Pointer to the destination path.
const char *sourcePath: Pointer to the source path.
*/
void dirCopy(DirEntry *entry, const char *destinationPath, const char *sourcePath) {
void dirCopy(const DirEntry &entry, const char *destinationPath, const char *sourcePath) {
std::vector<DirEntry> dirContents;
dirContents.clear();
if (entry->isDirectory) chdir((sourcePath + ("/" + entry->name)).c_str());
if (entry.isDirectory)
chdir((sourcePath + ("/" + entry.name)).c_str());
getDirectoryContents(dirContents);
if (((int)dirContents.size()) == 1) mkdir((destinationPath + ("/" + entry->name)).c_str(), 0777);
if (((int)dirContents.size()) != 1) fcopy((sourcePath + ("/" + entry->name)).c_str(), (destinationPath + ("/" + entry->name)).c_str());
if (((int)dirContents.size()) == 1)
mkdir((destinationPath + ("/" + entry.name)).c_str(), 0777);
if (((int)dirContents.size()) != 1)
fcopy((sourcePath + ("/" + entry.name)).c_str(), (destinationPath + ("/" + entry.name)).c_str());
}
u32 copyOffset = 0, copySize = 0;
@@ -220,13 +210,11 @@ int fcopy(const char *sourcePath, const char *destinationPath) {
chdir(sourcePath);
std::vector<DirEntry> dirContents;
getDirectoryContents(dirContents);
DirEntry *entry = &dirContents.at(1);
mkdir(destinationPath, 0777);
for(int i = 1; i < ((int)dirContents.size()); i++) {
chdir(sourcePath);
entry = &dirContents.at(i);
dirCopy(entry, destinationPath, sourcePath);
dirCopy(dirContents[i], destinationPath, sourcePath);
}
chdir(destinationPath);
@@ -244,51 +232,27 @@ int fcopy(const char *sourcePath, const char *destinationPath) {
fseek(sourceFile, 0, SEEK_END);
copySize = ftell(sourceFile); // Get source file's size.
fseek(sourceFile, 0, SEEK_SET);
} else {
fclose(sourceFile);
return -1;
}
FILE *destinationFile = fopen(destinationPath, "wb");
//if (destinationFile) {
fseek(destinationFile, 0, SEEK_SET);
/*} else {
if (!destinationFile) {
fclose(sourceFile);
fclose(destinationFile);
return -1;
}*/
}
int numr;
while(1) {
scanKeys();
if (keysHeld() & KEY_B) {
/* Cancel copying. */
fclose(sourceFile);
fclose(destinationFile);
return -1;
break;
}
printf("\x1b[16;0H");
printf("Progress:\n");
printf("%i/%i Bytes ", (int)copyOffset, (int)copySize);
/* Copy file to destination path. */
numr = fread(copyBuf, 2, copyBufSize, sourceFile);
fwrite(copyBuf, 2, numr, destinationFile);
copyOffset += copyBufSize;
int numr = fread(copyBuf, sizeof(u32), copyBufSize, sourceFile);
fwrite(copyBuf, sizeof(u32), numr, destinationFile);
copyOffset += copyBufSize * sizeof(u32);
if (copyOffset > copySize) {
fclose(sourceFile);
fclose(destinationFile);
printf("\x1b[17;0H");
printf("%i/%i Bytes ", (int)copyOffset, (int)copySize);
for(int i = 0; i < 30; i++) gspWaitForVBlank();
return 1;
break;
}
}
-3
View File
@@ -105,9 +105,6 @@ void QueueSystem::QueueHandle() {
while(QueueRuns) {
Result ret = NONE; // No Error as of yet.
queueEntries[0]->total = queueEntries[0]->obj.size();
queueEntries[0]->current = QueueSystem::LastElement;
for(int i = QueueSystem::LastElement; ret == NONE && i < queueEntries[0]->total && !QueueSystem::CancelCallback; i++) {
queueEntries[0]->current++;
+1 -1
View File
@@ -32,7 +32,7 @@ C2D_Image Screenshot::Convert(const std::string &filename) {
std::vector<u8> ImageBuffer;
unsigned width, height;
C2D_Image img;
lodepng::decode(ImageBuffer, width, height, filename.c_str());
lodepng::decode(ImageBuffer, width, height, filename);
img.tex = new C3D_Tex;
img.subtex = new Tex3DS_SubTexture({(u16)width, (u16)height, 0.0f, 1.0f, width / 512.0f, 1.0f - (height / 512.0f)});
+2 -2
View File
@@ -107,11 +107,11 @@ std::string StringUtils::GetMarkString(int marks) {
return out;
}
std::string StringUtils::format(const std::string &fmt_str, ...) {
std::string StringUtils::format(const char *fmt_str, ...) {
va_list ap;
char *fp = nullptr;
va_start(ap, fmt_str);
vasprintf(&fp, fmt_str.c_str(), ap);
vasprintf(&fp, fmt_str, ap);
va_end(ap);
std::unique_ptr<char, decltype(free) *> formatted(fp, free);