BOOL ConfigFile::LoadFile(DWORD dwOpenMode) { XFile file; if(!file.Open(strFileName, XFILE_READ, dwOpenMode)) { //Log(TEXT("Couldn't load config file: \"%s\""), (TSTR)strFileName); return 0; } if(bOpen) Close(); dwLength = (DWORD)file.GetFileSize(); LPSTR lpTempFileData = (LPSTR)Allocate(dwLength+5); file.Read(&lpTempFileData[2], dwLength); lpTempFileData[0] = lpTempFileData[dwLength+2] = 13; lpTempFileData[1] = lpTempFileData[dwLength+3] = 10; lpTempFileData[dwLength+4] = 0; file.Close(); lpFileData = utf8_createTstr(lpTempFileData); dwLength = slen(lpFileData); Free(lpTempFileData); bOpen = 1; return 1; }
BOOL ConfigFile::LoadFile(DWORD dwOpenMode) { XFile file; if(!file.Open(strFileName, XFILE_READ, dwOpenMode)) { //Log(TEXT("Couldn't load config file: \"%s\""), (TSTR)strFileName); return 0; } if(bOpen) Close(); dwLength = (DWORD)file.GetFileSize(); if (dwLength >= 3) // remove BOM if present { char buff[3]; file.Read(&buff, 3); if (memcmp(buff, "\xEF\xBB\xBF", 3)) file.SetPos(0, XFILE_BEGIN); else dwLength -= 3; } LPSTR lpTempFileData = (LPSTR)Allocate(dwLength+5); file.Read(&lpTempFileData[2], dwLength); lpTempFileData[0] = lpTempFileData[dwLength+2] = 13; lpTempFileData[1] = lpTempFileData[dwLength+3] = 10; lpTempFileData[dwLength+4] = 0; file.Close(); lpFileData = utf8_createTstr(lpTempFileData); dwLength = slen(lpFileData); Free(lpTempFileData); bOpen = 1; return 1; }
bool XConfig::Open(CTSTR lpFile) { if(RootElement) { if(strFileName.CompareI(lpFile)) return true; Close(); } //------------------------------------- XFile file; if(!file.Open(lpFile, XFILE_READ, XFILE_OPENALWAYS)) return false; RootElement = new XElement(this, NULL, TEXT("Root")); strFileName = lpFile; DWORD dwFileSize = (DWORD)file.GetFileSize(); LPSTR lpFileDataUTF8 = (LPSTR)Allocate(dwFileSize+1); zero(lpFileDataUTF8, dwFileSize+1); file.Read(lpFileDataUTF8, dwFileSize); TSTR lpFileData = utf8_createTstr(lpFileDataUTF8); Free(lpFileDataUTF8); //------------------------------------- // remove comments TSTR lpComment, lpEndComment; while(lpComment = sstr(lpFileData, TEXT("/*"))) { lpEndComment = sstr(lpFileData, TEXT("*/")); assert(lpEndComment); assert(lpComment < lpEndComment); if(!lpEndComment || (lpComment > lpEndComment)) { file.Close(); Close(false); Free(lpFileData); CrashError(TEXT("Error parsing X file '%s'"), strFileName.Array()); } mcpy(lpComment, lpEndComment+3, slen(lpEndComment+3)+1); } //------------------------------------- TSTR lpTemp = lpFileData; if(!ReadFileData(RootElement, 0, lpTemp)) { for(DWORD i=0; i<RootElement->SubItems.Num(); i++) delete RootElement->SubItems[i]; CrashError(TEXT("Error parsing X file '%s'"), strFileName.Array()); Free(lpFileData); Close(false); file.Close(); } Free(lpFileData); file.Close(); return true; }
bool UploadLogGitHub(String filename, String logData, LogUploadResult &result) { String description = FormattedString(OBS_VERSION_STRING L" log file uploaded at %s (local time).", CurrentDateTimeString().Array()); String age = LogFileAge(filename); if (age.IsValid()) description << FormattedString(L" The log file was approximately %s old at the time it was uploaded.", age.Array()); StringEscapeJson(description); StringEscapeJson(filename); StringEscapeJson(logData); String json = FormattedString(L"{ \"public\": false, \"description\": \"%s\", \"files\": { \"%s\": { \"content\": \"%s\" } } }", description.Array(), filename.Array(), logData.Array()); int response = 0; List<BYTE> body; if (!HTTPPostData(String(L"https://api.github.com/gists"), json, response, &body)) { result.errors << Str("LogUpload.CommunicationError"); return false; } if (response != 201) { result.errors << FormattedString(Str("LogUpload.ServiceReturnedError"), response) << FormattedString(Str("LogUpload.ServiceExpectedResponse"), 201); return false; } auto invalid_response = [&]() -> bool { result.errors << Str("LogUpload.ServiceReturnedInvalidResponse"); return false; }; if (body.Num() < 1) return invalid_response(); //make sure it's null terminated since we run string ops on it below body.Add (0); TSTR wideBody = utf8_createTstr((char const*)body.Array()); String bodyStr(wideBody); Free(wideBody); TSTR pos = sstr(bodyStr.Array(), L"\"html_url\""); if (!pos) return invalid_response(); pos = schr(pos + slen(L"\"html_url\""), '"'); if (!pos) return invalid_response(); pos += 1; TSTR end = schr(pos, '"'); if (!end) return invalid_response(); if ((end - pos) < 4) return invalid_response(); result.url = bodyStr.Mid((UINT)(pos - bodyStr.Array()), (UINT)(end - bodyStr.Array())); if (!HTTPFindRedirect(result.url, result.analyzerURL)) //the basic url doesn't work with the analyzer, so query the fully redirected url result.analyzerURL = result.url; return true; }