1
0
mirror of https://foundry.openuru.org/gitblit/r/CWE-ou-minkata.git synced 2025-07-18 11:19:10 +00:00

Implement pfPatcher backend

This commit is contained in:
2013-11-23 14:56:57 -05:00
parent 275f15087c
commit 346b6f8ac8
11 changed files with 775 additions and 0 deletions

View File

@ -96,6 +96,7 @@ public:
virtual hsError Run() = 0; // override this to do your work
virtual void Start(); // initializes stuff and calls your Run() method
virtual void Stop(); // sets fQuit = true and the waits for the thread to stop
virtual void OnQuit() { }
// Static functions
static void* Alloc(size_t size); // does not call operator::new(), may return nil

View File

@ -76,6 +76,7 @@ extern "C" {
pthread_mutex_lock(((hsThread*)param)->GetStartupMutex());
void* ret = (void*)(uintptr_t)((hsThread*)param)->Run();
pthread_mutex_unlock(((hsThread*)param)->GetStartupMutex());
((hsThread*)param)->OnQuit();
pthread_exit(ret);
return ret;
}

View File

@ -68,6 +68,7 @@ static unsigned int __stdcall gEntryPointBT(void* param)
WinThreadParam* wtp = (WinThreadParam*)param;
unsigned int result = wtp->fThread->Run();
::ReleaseSemaphore(wtp->fQuitSemaH, 1, nil); // signal that we've quit
wtp->fThread->OnQuit();
delete param;
return result;
}

View File

@ -570,3 +570,27 @@ plFileName plFileSystem::GetTempFilename(const char *prefix, const plFileName &p
return result;
#endif
}
plString plFileSystem::ConvertFileSize(uint64_t size)
{
const char* labels[] = { "KiB", "MiB", "GiB", "TiB", "PiB", "EiB" };
if (size < 1024)
return plString::Format("%i B");
uint64_t last_div = size;
for (size_t i = 0; i < arrsize(labels); ++i) {
uint64_t my_div = last_div / 1024;
if (my_div < 1024) {
float decimal = static_cast<float>(last_div) / 1024.f;
// Kilobytes are so small that we only care about whole numbers
if (i < 1)
return plString::Format("%.0f %s", decimal, labels[i]);
else
return plString::Format("%.2f %s", decimal, labels[i]);
}
last_div = my_div;
}
// this should never happen
return plString::Format("%i %s", last_div, labels[arrsize(labels) - 1]);
}

View File

@ -338,6 +338,9 @@ namespace plFileSystem
* system temp path is used.
*/
plFileName GetTempFilename(const char *prefix = "tmp", const plFileName &path = "");
/** Convert a file size from bytes to a human readable size. */
plString ConvertFileSize(uint64_t size);
}
#endif // plFileSystem_Defined