Workaround for StringFromFormat-under-linux problem, random cleanup.
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1491 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
61392ba692
commit
0ad52a4fee
|
@ -137,7 +137,7 @@ public:
|
||||||
template<class T>
|
template<class T>
|
||||||
void DoLinkedList(LinkedListItem<T> **list_start) {
|
void DoLinkedList(LinkedListItem<T> **list_start) {
|
||||||
// TODO
|
// TODO
|
||||||
PanicAlert("Do(vector<>) does not yet work.");
|
PanicAlert("Do(linked list<>) does not yet work.");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,10 @@ void PanicAlert(const char* format, ...)
|
||||||
|
|
||||||
if (panic_handler)
|
if (panic_handler)
|
||||||
{
|
{
|
||||||
std::string msg;
|
char buffer[2048];
|
||||||
StringFromFormatV(&msg, format, args);
|
CharArrayFromFormatV(buffer, 2048, format, args);
|
||||||
LOG(MASTER_LOG, "PANIC: %s", msg.c_str());
|
LOG(MASTER_LOG, "PANIC: %s", buffer);
|
||||||
panic_handler(msg.c_str(), false);
|
panic_handler(buffer, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,19 +85,23 @@ bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list ar
|
||||||
|
|
||||||
|
|
||||||
// Expensive!
|
// Expensive!
|
||||||
void StringFromFormatV(std::string* out, const char* format, va_list args)
|
void ToStringFromFormat(std::string* out, const char* format, ...)
|
||||||
{
|
{
|
||||||
int writtenCount = -1;
|
int writtenCount = -1;
|
||||||
size_t newSize = strlen(format) + 16;
|
int newSize = (int)strlen(format) + 4;
|
||||||
char* buf = 0;
|
char *buf = 0;
|
||||||
|
va_list args;
|
||||||
while (writtenCount < 0)
|
while (writtenCount < 0)
|
||||||
{
|
{
|
||||||
delete [] buf;
|
delete [] buf;
|
||||||
buf = new char[newSize + 1];
|
buf = new char[newSize + 1];
|
||||||
|
|
||||||
|
va_start(args, format);
|
||||||
writtenCount = vsnprintf(buf, newSize, format, args);
|
writtenCount = vsnprintf(buf, newSize, format, args);
|
||||||
if (writtenCount > (int)newSize)
|
va_end(args);
|
||||||
|
if (writtenCount >= (int)newSize) {
|
||||||
writtenCount = -1;
|
writtenCount = -1;
|
||||||
|
}
|
||||||
// ARGH! vsnprintf does no longer return -1 on truncation in newer libc!
|
// ARGH! vsnprintf does no longer return -1 on truncation in newer libc!
|
||||||
// WORKAROUND! let's fake the old behaviour (even though it's less efficient).
|
// WORKAROUND! let's fake the old behaviour (even though it's less efficient).
|
||||||
// TODO: figure out why the fix causes an invalid read in strlen called from vsnprintf :(
|
// TODO: figure out why the fix causes an invalid read in strlen called from vsnprintf :(
|
||||||
|
@ -114,12 +118,32 @@ void StringFromFormatV(std::string* out, const char* format, va_list args)
|
||||||
|
|
||||||
std::string StringFromFormat(const char* format, ...)
|
std::string StringFromFormat(const char* format, ...)
|
||||||
{
|
{
|
||||||
std::string temp;
|
int writtenCount = -1;
|
||||||
|
int newSize = (int)strlen(format) + 4;
|
||||||
|
char *buf = 0;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
while (writtenCount < 0)
|
||||||
|
{
|
||||||
|
delete [] buf;
|
||||||
|
buf = new char[newSize + 1];
|
||||||
|
|
||||||
va_start(args, format);
|
va_start(args, format);
|
||||||
StringFromFormatV(&temp, format, args);
|
writtenCount = vsnprintf(buf, newSize, format, args);
|
||||||
va_end(args);
|
va_end(args);
|
||||||
return(temp);
|
if (writtenCount >= (int)newSize) {
|
||||||
|
writtenCount = -1;
|
||||||
|
}
|
||||||
|
// ARGH! vsnprintf does no longer return -1 on truncation in newer libc!
|
||||||
|
// WORKAROUND! let's fake the old behaviour (even though it's less efficient).
|
||||||
|
// TODO: figure out why the fix causes an invalid read in strlen called from vsnprintf :(
|
||||||
|
// if (writtenCount >= (int)newSize)
|
||||||
|
// writtenCount = -1;
|
||||||
|
newSize *= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[writtenCount] = '\0';
|
||||||
|
std::string temp = buf;
|
||||||
|
return temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,15 +166,6 @@ std::string ArrayToString(const u8 *data, u32 size, u32 offset, int line_len)
|
||||||
// ================
|
// ================
|
||||||
|
|
||||||
|
|
||||||
void ToStringFromFormat(std::string* out, const char* format, ...)
|
|
||||||
{
|
|
||||||
va_list args;
|
|
||||||
va_start(args, format);
|
|
||||||
StringFromFormatV(out, format, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Turns " hej " into "hej". Also handles tabs.
|
// Turns " hej " into "hej". Also handles tabs.
|
||||||
std::string StripSpaces(const std::string &str)
|
std::string StripSpaces(const std::string &str)
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,10 +28,8 @@
|
||||||
std::string StringFromFormat(const char* format, ...);
|
std::string StringFromFormat(const char* format, ...);
|
||||||
void ToStringFromFormat(std::string* out, const char* format, ...);
|
void ToStringFromFormat(std::string* out, const char* format, ...);
|
||||||
|
|
||||||
|
// WARNING - only call once with a set of args!
|
||||||
// Expensive!
|
|
||||||
void StringFromFormatV(std::string* out, const char* format, va_list args);
|
void StringFromFormatV(std::string* out, const char* format, va_list args);
|
||||||
|
|
||||||
// Cheap!
|
// Cheap!
|
||||||
bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args);
|
bool CharArrayFromFormatV(char* out, int outsize, const char* format, va_list args);
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ void CEXIMemoryCard::FlushCallback(u64 userdata, int cyclesLate)
|
||||||
}
|
}
|
||||||
|
|
||||||
CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rFilename, int _card_index) :
|
CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rFilename, int _card_index) :
|
||||||
m_strFilename(_rFilename)
|
m_strFilename(_rFilename),
|
||||||
|
card_index(_card_index)
|
||||||
{
|
{
|
||||||
this->card_index = _card_index;
|
|
||||||
cards[_card_index] = this;
|
cards[_card_index] = this;
|
||||||
et_this_card = CoreTiming::RegisterEvent(_rName.c_str(), FlushCallback);
|
et_this_card = CoreTiming::RegisterEvent(_rName.c_str(), FlushCallback);
|
||||||
|
|
||||||
|
@ -71,10 +71,12 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF
|
||||||
pFile = fopen(m_strFilename.c_str(), "rb");
|
pFile = fopen(m_strFilename.c_str(), "rb");
|
||||||
if (pFile)
|
if (pFile)
|
||||||
{
|
{
|
||||||
fseek( pFile, 0L, SEEK_END );
|
// Measure size of the memcard file.
|
||||||
u64 MemFileSize = ftell( pFile );
|
fseek(pFile, 0L, SEEK_END);
|
||||||
|
u64 MemFileSize = ftell(pFile);
|
||||||
|
fseek(pFile, 0L, SEEK_SET);
|
||||||
|
|
||||||
switch ((MemFileSize / (8 * 1024))-5) // Convert the filesize in bytes to the "nintendo-size"
|
switch ((MemFileSize / (8 * 1024)) - 5) // Convert the filesize in bytes to the "nintendo-size"
|
||||||
{
|
{
|
||||||
case 59:
|
case 59:
|
||||||
nintendo_card_id = 0x00000004;
|
nintendo_card_id = 0x00000004;
|
||||||
|
@ -103,9 +105,6 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return to start otherwise the mem card is "corrupt"
|
|
||||||
fseek( pFile,0L,SEEK_SET);
|
|
||||||
|
|
||||||
memory_card_content = new u8[memory_card_size];
|
memory_card_content = new u8[memory_card_size];
|
||||||
memset(memory_card_content, 0xFF, memory_card_size);
|
memset(memory_card_content, 0xFF, memory_card_size);
|
||||||
|
|
||||||
|
@ -124,7 +123,7 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF
|
||||||
|
|
||||||
LOG(EXPANSIONINTERFACE, "No memory card found. Will create new.");
|
LOG(EXPANSIONINTERFACE, "No memory card found. Will create new.");
|
||||||
Flush();
|
Flush();
|
||||||
Core::DisplayMessage(StringFromFormat("Wrote memory card contents to %s", m_strFilename.c_str()), 4000);
|
Core::DisplayMessage(StringFromFormat("Wrote memory card %i contents to %s.", card_index + 1, m_strFilename.c_str()), 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -149,8 +148,9 @@ void CEXIMemoryCard::Flush(bool exiting)
|
||||||
}
|
}
|
||||||
fwrite(memory_card_content, memory_card_size, 1, pFile);
|
fwrite(memory_card_content, memory_card_size, 1, pFile);
|
||||||
fclose(pFile);
|
fclose(pFile);
|
||||||
if (!exiting)
|
if (!exiting) {
|
||||||
Core::DisplayMessage(StringFromFormat("Wrote memory card contents to %s", GetFileName().c_str()), 4000);
|
Core::DisplayMessage(StringFromFormat("Wrote memory card %i contents to %s.", card_index, m_strFilename.c_str()).c_str(), 4000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,14 @@ using namespace Common;
|
||||||
namespace PatchEngine
|
namespace PatchEngine
|
||||||
{
|
{
|
||||||
|
|
||||||
|
const char *PatchTypeStrings[] =
|
||||||
|
{
|
||||||
|
"byte",
|
||||||
|
"word",
|
||||||
|
"dword",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
std::vector<Patch> onFrame;
|
std::vector<Patch> onFrame;
|
||||||
std::map<u32, int> speedHacks;
|
std::map<u32, int> speedHacks;
|
||||||
|
|
||||||
|
|
|
@ -30,13 +30,7 @@ enum PatchType
|
||||||
PATCH_32BIT,
|
PATCH_32BIT,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char *PatchTypeStrings[] =
|
extern const char *PatchTypeStrings[];
|
||||||
{
|
|
||||||
"byte",
|
|
||||||
"word",
|
|
||||||
"dword",
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
struct PatchEntry
|
struct PatchEntry
|
||||||
{
|
{
|
||||||
|
|
|
@ -628,7 +628,7 @@ void CGameListCtrl::OnProperties(wxCommandEvent& WXUNUSED (event))
|
||||||
|
|
||||||
void CGameListCtrl::MultiCompressCB(const char* text, float percent, void* arg)
|
void CGameListCtrl::MultiCompressCB(const char* text, float percent, void* arg)
|
||||||
{
|
{
|
||||||
wxString textString(wxString::Format(wxT("%s (%i/%i) - %s"), m_currentFilename.c_str(), m_currentItem+1, m_numberItem, text));
|
wxString textString(wxString::Format(wxT("%s (%i/%i) - %s"), m_currentFilename.c_str(), (int)m_currentItem+1, (int)m_numberItem, text));
|
||||||
|
|
||||||
percent = (((float)m_currentItem) + percent) / (float)m_numberItem;
|
percent = (((float)m_currentItem) + percent) / (float)m_numberItem;
|
||||||
wxProgressDialog* pDialog = (wxProgressDialog*)arg;
|
wxProgressDialog* pDialog = (wxProgressDialog*)arg;
|
||||||
|
|
Loading…
Reference in New Issue