Files
wagic/projects/mtg/include/utils.h
wagic.the.homebrew e27cf56fa2 - Support for Zip Filesystem. It is now possible to zip the entire Res folder ("store" method preferred, zip so that the root of the zip has ai, player, etc...) in one single file for read only. Write access is done in another folder (hardcoded to be User/ for now, can be updated depending on platforms, etc...
-- zipFS has several limitations...
--- in a general way, seekg doesn't work... so getting a file's size needs to be done through JFileSystem.
--- getLine on files open with zipFS doesn't work so great. Not sure if it is a normal issue because files are open in binary or not... JFileSystem therefore offers a "readIntoString" function that needs to be used instead of the usual "getline" technique. However getLine can then be used on a stream connected to the string.

-- tested on Windows and PSP, I also made sure android still works, but haven't tested zip support on Android.
-- I tried to maintain backwards compatibility, but this might break on some platforms, if I broke some platforms and you can't find a way to fix them, please contact me and we'll figure something out
-- This removes wagic::ifstream. I didn't reimplement the securities that were involved in this, apologies for that. Might be useful to reimplement such securities in JFileSystem
-- I haven't tested options/profiles in a deep way, it is possible I broke that.
2011-08-21 09:04:59 +00:00

103 lines
2.7 KiB
C++

#ifndef _UTILS_H_
#define _UTILS_H_
#include <JGE.h>
#if defined (PSP)
#include <pspkernel.h>
#include <pspdisplay.h>
#include <pspctrl.h>
#include <pspiofilemgr.h>
#include <pspdebug.h>
#include <psputility.h>
#include <pspgu.h>
#include <psprtc.h>
#include <psptypes.h>
#include <malloc.h>
#endif
#include <math.h>
#include <stdio.h>
#include <string>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include "DebugRoutines.h"
using std::string;
//string manipulation methods
string& trim(string& str);
string& ltrim(string& str);
string& rtrim(string& str);
inline string trim(const string& str)
{
string value(str);
return trim(value);
}
std::string join(vector<string>& v, string delim = " ");
std::vector<std::string>& split(const std::string& s, char delim, std::vector<std::string>& elems);
std::vector<std::string> split(const std::string& s, char delim); //splits a string with "delim" and returns a vector of strings.
// A simple parsing function
// splits string s by finding the first occurence of start, and the first occurence of stop, and returning
// a vector of 3 strings. The first string is everything before the first occurence of start, the second string is everything between start and stop
// the third string is everything after stop.
// for example, parseBetween ("this is a function(foo) call", "function(", ")") will return: ["this is a ", "foo", " call"];
//If an error occurs, returns an empty vector.
// if "stopRequired" is set to false, the function will return a vector of 3 strings even if "stop" is not found in the string.
std::vector<std::string>& parseBetween(const std::string& s, string start, string stop, bool stopRequired, std::vector<std::string>& elems);
std::vector<std::string> parseBetween(const std::string& s, string start, string stop, bool stopRequired = true);
std::string wordWrap(const std::string& s, float width, int fontId);
//basic hash function
unsigned long hash_djb2(const char *str);
int loadRandValues(string s);
int filesize(const char * filename);
int WRand();
#ifdef LINUX
void dumpStack();
#endif
/* RAM simple check functions header */
// *** DEFINES ***
#if defined (WIN32) || defined (LINUX) || defined (IOS)
#define RAM_BLOCK (100 * 1024 * 1024)
#else
#define RAM_BLOCK (1024 * 1024)
#endif
// *** FUNCTIONS DECLARATIONS ***
u32 ramAvailableLineareMax(void);
u32 ramAvailable(void);
#ifdef WIN32
#include <direct.h>
#define MAKEDIR(name) _mkdir(name)
#else
#include <sys/stat.h>
#define MAKEDIR(name) mkdir(name, 0777)
#endif
bool fileExists(const char * filename);
bool FileExists(const string & filename);
std::string buildFilePath(const vector<string> & folders, const string & filename);
#endif