mirror of
https://github.com/copyrighttxt/watrbx-game-engine.git
synced 2026-09-05 05:07:48 +00:00
GEEKING
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
// !!!WARNING!!!
|
||||
// Do NOT call back into FASTLOG here, since FASTLOG heavily depends on this,
|
||||
// and we could end up getting a SIGABRT from a lock being set multiple times.
|
||||
#include "util/FileSystem.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "RbxFormat.h"
|
||||
#include "FastLog.h"
|
||||
#include "rbx/Debug.h"
|
||||
|
||||
namespace RBX
|
||||
{
|
||||
namespace JNI
|
||||
{
|
||||
std::string fileSystemFilesDir; // Set in JNIRobloxSettings.cpp.
|
||||
} // namespace JNI
|
||||
} // namespace RBX
|
||||
|
||||
using namespace RBX;
|
||||
using namespace RBX::JNI;
|
||||
|
||||
namespace RBX
|
||||
{
|
||||
namespace FileSystem
|
||||
{
|
||||
|
||||
boost::filesystem::path getUserDirectory(bool create, FileSystemDir dir, const char *subDirectory)
|
||||
{
|
||||
boost::filesystem::path path;
|
||||
|
||||
if (subDirectory)
|
||||
{
|
||||
path /= subDirectory;
|
||||
}
|
||||
|
||||
switch (dir)
|
||||
{
|
||||
case DirAppData:
|
||||
path /= "appData";
|
||||
break;
|
||||
case DirExe:
|
||||
path /= "exe";
|
||||
break;
|
||||
case DirPicture:
|
||||
path /= "picture";
|
||||
break;
|
||||
case DirVideo:
|
||||
path /= "video";
|
||||
break;
|
||||
}
|
||||
return getCacheDirectory(true, path.native().c_str());
|
||||
}
|
||||
|
||||
}}
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "Util/MachineIdUploader.h"
|
||||
|
||||
#include <jni.h>
|
||||
|
||||
using namespace RBX;
|
||||
|
||||
bool MachineIdUploader::fillMachineId(MachineId *out) {
|
||||
// Fetch the device unique id via JNI.
|
||||
// out->macAddresses.push_back("device_id");
|
||||
// return true;
|
||||
|
||||
// some incomplete, possible incorrect example code from the web
|
||||
// JNIEnv &env = ...
|
||||
// jobject activity = ... (android.app.Activity object)
|
||||
// //TelephonyManager telephony_manager =
|
||||
// getSystemService(Context.TELEPHONY_SERVICE);
|
||||
// jmethodID mid = env.GetMethodID(env.GetObjectClass(activity),
|
||||
// "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;");
|
||||
// jobject telephony_manager = env.CallObjectMethod(activity, mid,
|
||||
// env.NewStringUTF("phone"));
|
||||
// //String s_imei = tm.getDeviceId();
|
||||
// mid = env.GetMethodID(env.GetObjectClass(telephony_manager),
|
||||
// "getDeviceId", "()Ljava/lang/String;");
|
||||
// jstring s_imei = (jstring)env.CallObjectMethod(telephony_manager,
|
||||
// mid);
|
||||
// if(env.ExceptionCheck()){
|
||||
// env.ExceptionClear();
|
||||
// return false;
|
||||
// }
|
||||
// const jchar *imei = env.GetStringCritical(s_imei, NULL);
|
||||
// // copy imei string anywhere you need
|
||||
// env.ReleaseStringCritical(s_imei, imei);
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
#include "util/MemoryStats.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <regex>
|
||||
|
||||
namespace RBX
|
||||
{
|
||||
using RBX::MemoryStats::memsize_t;
|
||||
|
||||
class MemInfo
|
||||
{
|
||||
// Next 3 fields summed define how much memory is actually free.
|
||||
memsize_t cacheKB;
|
||||
memsize_t bufferKB;
|
||||
memsize_t memfreeKB;
|
||||
|
||||
memsize_t totalKB;
|
||||
|
||||
bool readLine(const std::string& line, const std::string& target, memsize_t* field)
|
||||
{
|
||||
if (0 == line.find(target))
|
||||
{
|
||||
std::string expr = target + "\\s*(\\d+).*";
|
||||
std::regex e(expr);
|
||||
std::smatch sm;
|
||||
if (std::regex_search(line, sm, e)) {
|
||||
if (sm.size() >= 1) {
|
||||
std::string o = sm[1].str(); // gets the first capture group
|
||||
std::sscanf(o.c_str(), "%llu", field);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public:
|
||||
MemInfo() : cacheKB(1), bufferKB(1), memfreeKB(1), totalKB(3)
|
||||
{
|
||||
std::ifstream fin("/proc/meminfo");
|
||||
|
||||
unsigned fieldsLoaded = 0;
|
||||
while (fin && !fin.eof() && fieldsLoaded < 4)
|
||||
{
|
||||
std::string line;
|
||||
std::getline(fin, line);
|
||||
|
||||
if (readLine(line, "MemTotal:", &totalKB))
|
||||
{
|
||||
++fieldsLoaded;
|
||||
}
|
||||
|
||||
if (readLine(line, "MemFree:", &memfreeKB))
|
||||
{
|
||||
++fieldsLoaded;
|
||||
}
|
||||
|
||||
if (readLine(line, "Buffers:", &bufferKB))
|
||||
{
|
||||
++fieldsLoaded;
|
||||
|
||||
}
|
||||
|
||||
if (readLine(line, "Cached:", &cacheKB))
|
||||
{
|
||||
++fieldsLoaded;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
memsize_t freeBytes() const
|
||||
{
|
||||
return (memfreeKB + bufferKB + cacheKB) * 1024;
|
||||
}
|
||||
|
||||
memsize_t totalBytes() const
|
||||
{
|
||||
return totalKB * 1024;
|
||||
}
|
||||
};
|
||||
} // namespace rbx
|
||||
|
||||
namespace RBX {
|
||||
namespace MemoryStats {
|
||||
|
||||
memsize_t usedMemoryBytes()
|
||||
{
|
||||
MemInfo mi;
|
||||
return mi.totalBytes() - mi.freeBytes();
|
||||
}
|
||||
|
||||
memsize_t freeMemoryBytes()
|
||||
{
|
||||
MemInfo mi;
|
||||
return mi.freeBytes();
|
||||
}
|
||||
|
||||
memsize_t totalMemoryBytes()
|
||||
{
|
||||
MemInfo mi;
|
||||
return mi.totalBytes();
|
||||
}
|
||||
|
||||
} // namespace MemoryStats
|
||||
} // namespace RBX
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "StringConv.h"
|
||||
|
||||
namespace RBX {
|
||||
|
||||
std::string utf8_encode(const std::string &path)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
std::string utf8_decode(const std::string &path)
|
||||
{
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user