Kill off replaceable usages of s[n]printf.

This commit is contained in:
Lioncash
2014-06-03 01:08:54 -04:00
parent dccd9ead7d
commit ce54c1e571
29 changed files with 216 additions and 243 deletions

View File

@ -6,6 +6,12 @@
#define __STDC_CONSTANT_MACROS 1
#endif
#include <string>
#include "Common/CommonPaths.h"
#include "Common/FileUtil.h"
#include "Common/Log.h"
#include "Common/StringUtil.h"
#include "Core/HW/VideoInterface.h" //for TargetRefreshRate
#include "VideoCommon/AVIDump.h"
#include "VideoCommon/VideoConfig.h"
@ -19,10 +25,6 @@
#include <vfw.h>
#include <winerror.h>
#include "Common/CommonPaths.h"
#include "Common/FileUtil.h"
#include "Common/Log.h"
HWND m_emuWnd;
LONG m_byteBuffer;
LONG m_frameCount;
@ -53,22 +55,23 @@ bool AVIDump::CreateFile()
{
m_totalBytes = 0;
m_frameCount = 0;
char movie_file_name[255];
sprintf(movie_file_name, "%sframedump%d.avi", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), m_fileCount);
std::string movie_file_name = StringFromFormat("%sframedump%d.avi", File::GetUserPath(D_DUMPFRAMES_IDX).c_str(), m_fileCount);
// Create path
File::CreateFullPath(movie_file_name);
// Ask to delete file
if (File::Exists(movie_file_name))
{
if (AskYesNoT("Delete the existing file '%s'?", movie_file_name))
if (AskYesNoT("Delete the existing file '%s'?", movie_file_name.c_str()))
File::Delete(movie_file_name);
}
AVIFileInit();
NOTICE_LOG(VIDEO, "Opening AVI file (%s) for dumping", movie_file_name);
NOTICE_LOG(VIDEO, "Opening AVI file (%s) for dumping", movie_file_name.c_str());
// TODO: Make this work with AVIFileOpenW without it throwing REGDB_E_CLASSNOTREG
HRESULT hr = AVIFileOpenA(&m_file, movie_file_name, OF_WRITE | OF_CREATE, nullptr);
HRESULT hr = AVIFileOpenA(&m_file, movie_file_name.c_str(), OF_WRITE | OF_CREATE, nullptr);
if (FAILED(hr))
{
if (hr == AVIERR_BADFORMAT) NOTICE_LOG(VIDEO, "The file couldn't be read, indicating a corrupt file or an unrecognized format.");
@ -204,10 +207,6 @@ bool AVIDump::SetVideoFormat()
#else
#include "Common/FileUtil.h"
#include "Common/Log.h"
#include "Common/StringUtil.h"
extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>

View File

@ -3,13 +3,14 @@
// Refer to the license.txt file included.
#include <list>
#include <string>
#include <vector>
#include "png.h"
#include "Common/FileUtil.h"
#include "VideoCommon/ImageWrite.h"
bool SaveData(const char* filename, const char* data)
bool SaveData(const std::string& filename, const char* data)
{
std::ofstream f;
OpenFStream(f, filename, std::ios::binary);

View File

@ -4,7 +4,8 @@
#pragma once
#include <string>
#include "Common/Common.h"
bool SaveData(const char* filename, const char* pdata);
bool SaveData(const std::string& filename, const char* pdata);
bool TextureToPng(u8* data, int row_stride, const std::string& filename, int width, int height, bool saveAlpha = true);

View File

@ -219,22 +219,21 @@ u32 FifoCommandRunnable(u32 &command_size)
else
{
// TODO(Omega): Maybe dump FIFO to file on this error
char szTemp[1024];
sprintf(szTemp, "GFX FIFO: Unknown Opcode (0x%x).\n"
std::string temp = StringFromFormat(
"GFX FIFO: Unknown Opcode (0x%x).\n"
"This means one of the following:\n"
"* The emulated GPU got desynced, disabling dual core can help\n"
"* Command stream corrupted by some spurious memory bug\n"
"* This really is an unknown opcode (unlikely)\n"
"* Some other sort of bug\n\n"
"Dolphin will now likely crash or hang. Enjoy." , cmd_byte);
Host_SysMessage(szTemp);
INFO_LOG(VIDEO, "%s", szTemp);
Host_SysMessage(temp.c_str());
INFO_LOG(VIDEO, "%s", temp.c_str());
{
SCPFifoStruct &fifo = CommandProcessor::fifo;
char szTmp[512];
// sprintf(szTmp, "Illegal command %02x (at %08x)",cmd_byte,g_pDataReader->GetPtr());
sprintf(szTmp, "Illegal command %02x\n"
std::string tmp = StringFromFormat(
"Illegal command %02x\n"
"CPBase: 0x%08x\n"
"CPEnd: 0x%08x\n"
"CPHiWatermark: 0x%08x\n"
@ -252,8 +251,8 @@ u32 FifoCommandRunnable(u32 &command_size)
,fifo.bFF_BPEnable ? "true" : "false" ,fifo.bFF_BPInt ? "true" : "false"
,fifo.bFF_Breakpoint ? "true" : "false");
Host_SysMessage(szTmp);
INFO_LOG(VIDEO, "%s", szTmp);
Host_SysMessage(tmp.c_str());
INFO_LOG(VIDEO, "%s", tmp.c_str());
}
}
break;

View File

@ -12,6 +12,7 @@
#include <vector>
#include "Common/CommonTypes.h"
#include "Common/StringUtil.h"
#include "VideoCommon/VideoCommon.h"
/**
@ -179,14 +180,12 @@ public:
{
static int num_failures = 0;
char szTemp[MAX_PATH];
sprintf(szTemp, "%s%ssuid_mismatch_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(),
dump_prefix,
++num_failures);
std::string temp = StringFromFormat("%s%ssuid_mismatch_%04i.txt", File::GetUserPath(D_DUMP_IDX).c_str(),
dump_prefix, ++num_failures);
// TODO: Should also dump uids
std::ofstream file;
OpenFStream(file, szTemp, std::ios_base::out);
OpenFStream(file, temp, std::ios_base::out);
file << "Old shader code:\n" << old_code;
file << "\n\nNew shader code:\n" << new_code.GetBuffer();
file << "\n\nShader uid:\n";
@ -206,9 +205,8 @@ public:
else
file << std::endl;
}
file.close();
ERROR_LOG(VIDEO, "%s shader uid mismatch! See %s for details", shader_type, szTemp);
ERROR_LOG(VIDEO, "%s shader uid mismatch! See %s for details", shader_type, temp.c_str());
}
}
}

View File

@ -3,9 +3,11 @@
// Refer to the license.txt file included.
#include <algorithm>
#include <string>
#include "Common/FileUtil.h"
#include "Common/MemoryUtil.h"
#include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "Core/HW/Memmap.h"
@ -227,36 +229,34 @@ bool TextureCache::CheckForCustomTextureLODs(u64 tex_hash, int texformat, unsign
return false;
// Just checking if the necessary files exist, if they can't be loaded or have incorrect dimensions LODs will be black
char texBasePathTemp[MAX_PATH];
char texPathTemp[MAX_PATH];
sprintf(texBasePathTemp, "%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32) (tex_hash & 0x00000000FFFFFFFFLL), texformat);
std::string texBasePathTemp = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), (u32) (tex_hash & 0x00000000FFFFFFFFLL), texformat);
for (unsigned int level = 1; level < levels; ++level)
{
sprintf(texPathTemp, "%s_mip%u", texBasePathTemp, level);
std::string texPathTemp = StringFromFormat("%s_mip%u", texBasePathTemp.c_str(), level);
if (!HiresTextures::HiresTexExists(texPathTemp))
{
if (level > 1)
WARN_LOG(VIDEO, "Couldn't find custom texture LOD with index %u (filename: %s), disabling custom LODs for this texture", level, texPathTemp);
WARN_LOG(VIDEO, "Couldn't find custom texture LOD with index %u (filename: %s), disabling custom LODs for this texture", level, texPathTemp.c_str());
return false;
}
}
return true;
}
PC_TexFormat TextureCache::LoadCustomTexture(u64 tex_hash, int texformat, unsigned int level, unsigned int& width, unsigned int& height)
{
char texPathTemp[MAX_PATH];
std::string texPathTemp;
unsigned int newWidth = 0;
unsigned int newHeight = 0;
u32 tex_hash_u32 = tex_hash & 0x00000000FFFFFFFFLL;
if (level == 0)
sprintf(texPathTemp, "%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), tex_hash_u32, texformat);
texPathTemp = StringFromFormat("%s_%08x_%i", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), tex_hash_u32, texformat);
else
sprintf(texPathTemp, "%s_%08x_%i_mip%u", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), tex_hash_u32, texformat, level);
texPathTemp = StringFromFormat("%s_%08x_%i_mip%u", SConfig::GetInstance().m_LocalCoreStartupParameter.m_strUniqueID.c_str(), tex_hash_u32, texformat, level);
unsigned int required_size = 0;
PC_TexFormat ret = HiresTextures::GetHiresTex(texPathTemp, &newWidth, &newHeight, &required_size, texformat, temp_size, temp);
@ -273,11 +273,11 @@ PC_TexFormat TextureCache::LoadCustomTexture(u64 tex_hash, int texformat, unsign
if (ret != PC_TEX_FMT_NONE)
{
if (level > 0 && (newWidth != width || newHeight != height))
ERROR_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. This mipmap layer _must_ be %dx%d.", newWidth, newHeight, texPathTemp, width, height);
ERROR_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. This mipmap layer _must_ be %dx%d.", newWidth, newHeight, texPathTemp.c_str(), width, height);
if (newWidth * height != newHeight * width)
ERROR_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. The aspect differs from the native size %dx%d.", newWidth, newHeight, texPathTemp, width, height);
ERROR_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. The aspect differs from the native size %dx%d.", newWidth, newHeight, texPathTemp.c_str(), width, height);
if (newWidth % width || newHeight % height)
WARN_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. Please use an integer upscaling factor based on the native size %dx%d.", newWidth, newHeight, texPathTemp, width, height);
WARN_LOG(VIDEO, "Invalid custom texture size %dx%d for texture %s. Please use an integer upscaling factor based on the native size %dx%d.", newWidth, newHeight, texPathTemp.c_str(), width, height);
width = newWidth;
height = newHeight;