示例#1
0
void CRIFFChunkTreeDlg::OnSave() 
{
	OPENFILENAME ofn;

	PrepareSimpleDialog(&ofn, *this, "*.txt");
	ofn.lpstrFilter = "Text files (*.txt)|*.txt||";
	ofn.Flags |= OFN_OVERWRITEPROMPT;
	if (!GetOpenSaveFileNameUTF8(&ofn, false)) 
		return;

	CFileStream* destFile = new CFileStream();
	if (STREAM_OK == destFile->Open(ofn.lpstrFile, StreamMode::Write))
	{
		CACHE* cache = new CACHE(4, 1<<18);
		cache->Open(destFile, CACHE_OPEN_WRITE);
		cache->Write(cUTF8Hdr, 3);

		RenderItem(cache, m_Tree.GetRootItem(), 0);

		cache->Close();
		delete cache;
		destFile->Close();
		delete destFile;
	}
	else
	{
		MessageBoxHelper::CouldNotOpenFileForWrite(ofn.lpstrFile);
	}
}
示例#2
0
文件: Shader.cpp 项目: soerendd/xbmc
bool CShader::InsertSource(const std::string& filename, const std::string& loc)
{
  if(filename.empty())
    return true;

  CFileStream file;
  std::string temp;

  std::string path = "special://xbmc/system/shaders/";
  path += CServiceBroker::GetRenderSystem()->GetShaderPath(filename);
  path += filename;
  if(!file.Open(path))
  {
    CLog::Log(LOGERROR, "CShader::InsertSource - failed to open file %s", filename.c_str());
    return false;
  }
  getline(file, temp, '\0');

  size_t locPos = m_source.find(loc);
  if (locPos == std::string::npos)
  {
    CLog::Log(LOGERROR, "CShader::InsertSource - could not find location %s", loc.c_str());
    return false;
  }

  m_source.insert(locPos, temp);

  return true;
}
示例#3
0
文件: Shader.cpp 项目: soerendd/xbmc
//////////////////////////////////////////////////////////////////////
// CShader
//////////////////////////////////////////////////////////////////////
bool CShader::LoadSource(const std::string& filename, const std::string& prefix)
{
  if(filename.empty())
    return true;

  CFileStream file;

  std::string path = "special://xbmc/system/shaders/";
  path += CServiceBroker::GetRenderSystem()->GetShaderPath(filename);
  path += filename;
  if(!file.Open(path))
  {
    CLog::Log(LOGERROR, "CYUVShaderGLSL::CYUVShaderGLSL - failed to open file %s", filename.c_str());
    return false;
  }
  getline(file, m_source, '\0');

  size_t pos = 0;
  size_t versionPos = m_source.find("#version");
  if (versionPos != std::string::npos)
  {
    versionPos = m_source.find("\n", versionPos);
    if (versionPos != std::string::npos)
      pos = versionPos + 1;
  }
  m_source.insert(pos, prefix);
  return true;
}
示例#4
0
文件: Stream.cpp 项目: 109383670/Scut
	void CBaseMemoryStream::SaveTo( const char* lpszFileName )
	{
		CFileStream* fs = new CFileStream();
#ifdef SCUT_UPHONE
		if (fs->Open(lpszFileName, PO_CREAT | PO_RDWR | PO_BINARY, PS_IREAD | PS_IWRITE) == 0)
		{
			this->SaveTo(fs);
			delete fs;
		}
#else
		if (fs->Open(lpszFileName, 0, 0, "wb+") == 0)
		{
			this->SaveTo(fs);
			delete fs;
		}
#endif
	}
示例#5
0
文件: Stream.cpp 项目: 109383670/Scut
	void CMemoryStream::LoadFrom( const char* lpszFileName )
	{
		CFileStream* pStream = new CFileStream();
#ifdef SCUT_UPHONE
		if (pStream->Open(lpszFileName, PO_CREAT | PO_RDWR | PO_BINARY, PS_IREAD | PS_IWRITE) == 0)
		{
			this->LoadFrom(pStream);
			delete pStream;
		}
#else
		if (pStream->Open(lpszFileName, 0, 0, "rb") == 0)
		{
			this->LoadFrom(pStream);
			delete pStream;
		}
#endif
	}
void CGlobalMshLoader::SaveMeshToFile(const CMesh::TMeshContainer &mesh, const nstring &file)
{
	CFileStream sfile;

	sfile.Open(file, true, false);
	SaveMeshToStream(mesh, &sfile);

	sfile.Close();
}
示例#7
0
//???remove from here? make user use readers/writers directly?
void CDataServer::SavePRM(const nString& FileName, PParams Content)
{
	if (!Content.isvalid()) return;

	CFileStream File;
	if (!File.Open(FileName, SAM_WRITE)) return;
	CBinaryWriter Writer(File);
	Writer.WriteParams(*Content);
}
CMesh::TMeshContainer &CGlobalMshLoader::LoadMeshFromFile(const nstring &file)
{
	CFileStream sfile;
	
	sfile.Open(file);
	LoadMeshFromStream(&sfile);

	sfile.Close();

	return gMeshBuffer;
}
示例#9
0
文件: Shader.cpp 项目: 2BReality/xbmc
//////////////////////////////////////////////////////////////////////
// CShader
//////////////////////////////////////////////////////////////////////
bool CShader::LoadSource(const string& filename, const string& prefix)
{
  if(filename.empty())
    return true;

  CFileStream file;

  if(!file.Open("special://xbmc/system/shaders/" + filename))
  {
    CLog::Log(LOGERROR, "CYUVShaderGLSL::CYUVShaderGLSL - failed to open file %s", filename.c_str());
    return false;
  }
  getline(file, m_source, '\0');
  m_source.insert(0, prefix);
  return true;
}
示例#10
0
bool CPlayList::Load(const std::string& strFileName)
{
  Clear();
  m_strBasePath = URIUtils::GetDirectory(strFileName);

  CFileStream file;
  if (!file.Open(strFileName))
    return false;

  if (file.GetLength() > 1024*1024)
  {
    CLog::Log(LOGWARNING, "%s - File is larger than 1 MB, most likely not a playlist", __FUNCTION__);
    return false;
  }

  return LoadData(file);
}
示例#11
0
文件: Shader.cpp 项目: beermix/xbmc
bool CShader::AppendSource(const string& filename)
{
  if(filename.empty())
    return true;

  CFileStream file;
  string temp;

  if(!file.Open("special://xbmc/system/shaders/" + filename))
  {
    CLog::Log(LOGERROR, "CShader::AppendSource - failed to open file %s", filename.c_str());
    return false;
  }
  getline(file, temp, '\0');
  m_source.append(temp);
  return true;
}
示例#12
0
TiXmlElement *CSmartPlaylist::OpenAndReadName(const CStdString &path)
{
  CFileStream file;
  if (!file.Open(path))
  {
    CLog::Log(LOGERROR, "Error loading Smart playlist %s (failed to read file)", path.c_str());
    return NULL;
  }

  m_xmlDoc.Clear();
  file >> m_xmlDoc;

  if (m_xmlDoc.Error())
  {
    CLog::Log(LOGERROR, "Error loading Smart playlist (failed to parse xml: %s)", m_xmlDoc.ErrorDesc());
    return NULL;
  }

  TiXmlElement *root = m_xmlDoc.RootElement();
  if (!root || strcmpi(root->Value(),"smartplaylist") != 0)
  {
    CLog::Log(LOGERROR, "Error loading Smart playlist %s", path.c_str());
    return NULL;
  }
  // load the playlist type
  const char* type = root->Attribute("type");
  if (type)
    m_playlistType = type;
  // backward compatibility:
  if (m_playlistType == "music")
    m_playlistType = "songs";
  if (m_playlistType == "video")
    m_playlistType = "musicvideos";

  // load the playlist name
  TiXmlHandle name = ((TiXmlHandle)root->FirstChild("name")).FirstChild();
  if (name.Node())
    m_playlistName = name.Node()->Value();
  else
  {
    m_playlistName = CUtil::GetTitleFromPath(path);
    if (URIUtils::GetExtension(m_playlistName) == ".xsp")
      URIUtils::RemoveExtension(m_playlistName);
  }
  return root;
}
示例#13
0
文件: Shader.cpp 项目: soerendd/xbmc
bool CShader::AppendSource(const std::string& filename)
{
  if(filename.empty())
    return true;

  CFileStream file;
  std::string temp;

  std::string path = "special://xbmc/system/shaders/";
  path += CServiceBroker::GetRenderSystem()->GetShaderPath(filename);
  path += filename;
  if(!file.Open(path))
  {
    CLog::Log(LOGERROR, "CShader::AppendSource - failed to open file %s", filename.c_str());
    return false;
  }
  getline(file, temp, '\0');
  m_source.append(temp);
  return true;
}
void CNumberFileStreamDlg::OnPackFileStream() 
{
	char szPath[MAX_PATH];
	CFileStream fileStream;
	GetCurrentDirectory(sizeof(szPath),szPath);
	strcat(szPath,"\\moesky.dat");
	if(fileStream.Open(szPath))
	{
		fileStream.LoadFromStream();

		memory_tree_t * tree = fileStream.GetFile("/exit_nomal.bmp");
		if(tree)
		{
			FILE* f = fopen("c:\\test.bmp","wb+");
			fwrite((void*)tree->dataOffset,tree->dataSize,1,f);
			fclose(f);
			
			MessageBox(fileStream.GetName(tree->nStringIdx));
		}
	}
}
示例#15
0
TiXmlElement *CSmartPlaylist::OpenAndReadName(const CStdString &path)
{
  CFileStream file;
  if (!file.Open(path))
  {
    CLog::Log(LOGERROR, "Error loading Smart playlist %s (failed to read file)", path.c_str());
    return NULL;
  }

  m_xmlDoc.Clear();
  file >> m_xmlDoc;

  TiXmlElement *root = readName();
  if (m_playlistName.empty())
  {
    m_playlistName = CUtil::GetTitleFromPath(path);
    if (URIUtils::GetExtension(m_playlistName) == ".xsp")
      URIUtils::RemoveExtension(m_playlistName);
  }
  return root;
}
示例#16
0
文件: Shader.cpp 项目: mbolhuis/xbmc
//////////////////////////////////////////////////////////////////////
// CShader
//////////////////////////////////////////////////////////////////////
bool CShader::LoadSource(const string& filename, const string& prefix)
{
  if(filename.empty())
    return true;

  CFileStream file;

  if(!file.Open("special://xbmc/system/shaders/" + filename))
  {
    CLog::Log(LOGERROR, "CYUVShaderGLSL::CYUVShaderGLSL - failed to open file %s", filename.c_str());
    return false;
  }
#ifdef _ARMEL
  CLog::Log(LOGDEBUG, "Shader - Loading shader file %s", filename.c_str());
  m_source.assign(file.ReadFile());
#else
  getline(file, m_source, '\0');
#endif
  m_source.insert(0, prefix);
  return true;
}
示例#17
0
PParams CDataServer::ReloadPRM(const nString& FileName, bool Cache)
{
	CFileStream File;
	if (!File.Open(FileName, SAM_READ)) return NULL;
	CBinaryReader Reader(File);

	PParams Params;
	Params.Create();
	if (Reader.ReadParams(*Params))
	{
		if (Cache) HRDCache.Add(FileName.Get(), Params); //!!!???mangle path to avoid duplicates?
		n_printf("FileIO: PRM \"%s\" successfully loaded from HDD\n", FileName.Get());
	}
	else
	{
		Params = NULL;
		n_printf("FileIO: PRM loading from \"%s\" failed\n", FileName.Get());
	}

	return Params;
}
示例#18
0
DWORD CDataServer::LoadFileToBuffer(const nString& FileName, char*& Buffer)
{
	CFileStream File;

	int BytesRead;

	if (File.Open(FileName, SAM_READ, SAP_SEQUENTIAL))
	{
		int FileSize = File.GetSize();
		Buffer = (char*)n_malloc(FileSize);
		BytesRead = File.Read(Buffer, FileSize);
		File.Close();
	}
	else
	{
		Buffer = NULL;
		BytesRead = 0;
	}

	return BytesRead;
}
示例#19
0
bool CDX10Shader::LoadEffect(const std::string& filename, DefinesMap* defines)
{
	LOGDEBUG(" loading shader %s", filename.c_str());

	CFileStream file;

	if (!file.Open(filename)) 
	{
		LOGERR(" failed to open file %s", filename.c_str());
		return false;
	}

	//Get whole file to string
	std::string pStrEffect;
	getline(file, pStrEffect, '\0');

	if (!m_effect.Create(pStrEffect, defines))
	{
		LOGERR(" failed to create effect", pStrEffect.c_str());
		return false;
	}
	return true;
}
示例#20
0
// Main entry point
int _tmain(int argc, _TCHAR* argv[])
{
	// Add command line alias'
	cl.AddAlias(L"h", L"?");
	cl.AddAlias(L"help", L"?");
	cl.AddAlias(L"x", L"extract");
	cl.AddAlias(L"o", L"out");

	// Parse command line
	cl.Parse(GetCommandLine(), true);

	// Display logo...
	if (!cl.GetSwitch(L"nologo"))
	{
		wprintf(L"Structured Ini File Compiler v1.1\nCopyright (C) 2007 Topten Software.  All Rights Reserved\n\n");
	}

	// Display help
	if (cl.GetSwitch(L"?"))
	{
		cl.BuildHelp(L"nologo", L"Suppress display of copyright and version info", NULL, clOptional);
		cl.BuildHelp(L"?|h|help", L"Display help information", NULL, clOptional);
		cl.BuildHelp(L"i", L"Include path", L"path", clMulti|clValue|clOptional);
		cl.BuildHelp(L"x|extract", L"Extract (decompile)", NULL, clOptional);
		cl.BuildHelp(L"unicode", L"Decompile to unicode", NULL, clOptional);
		cl.BuildHelp(L"flat", L"Decompile to flat", NULL, clOptional);
		cl.BuildHelp(L"o|out", L"Output File", NULL, clOptional);
		cl.BuildHelp(L"InputFile", L"File to be processed", NULL, clPlaced);
		cl.BuildHelp(L"crcstamp", L"CRC Stamp Module", NULL, clOptional);
		cl.BuildHelp(L"crcverify", L"Check Module CRC Stamp", NULL, clOptional);
		wprintf(cl.GetHelp(L"Sinic"));
		return 7;
	}

	// Get input value
	CUniString strInputFile;
	cl.GetPlacedValue(0, L"InputFile", strInputFile);
	strInputFile=QualifyPath(strInputFile);

	if (cl.GetSwitch(L"crcverify"))
	{
		if (!DoesFileExist(strInputFile))
		{
			wprintf(L"Verifying %s... file doesn't exist, ignoring\n", strInputFile);
			return 0;
		}
		else
		{
			if (!CheckModuleCRC(strInputFile))
			{
				CheckModuleCRCWithErrors(strInputFile);
				wprintf(L"************************************************************\n");
				wprintf(L" Verifying %s... FAILED\n", strInputFile);
				wprintf(L"************************************************************\n");
				return 7;
			}
			else
			{
				wprintf(L"Verifying %s... OK\n", strInputFile);
				return 0;
			}
		}
	}

	// Module CRC Stamp?
	if (cl.GetSwitch(L"crcstamp"))
	{
		// Work out output file
		CUniString strOutputFile;
		cl.GetValue(L"out", strOutputFile);
		if (strOutputFile.IsEmpty())
			strOutputFile=strInputFile;

		// Error handling...
		cl.CheckNoUnknownArgs();
		if (cl.HasError())
		{
			wprintf(cl.GetErrorMessage());
			wprintf(L"\n\n");
			return 7;
		}

		// Open file for read/write
		FILE* pFile;
		if (_wfopen_s(&pFile, strInputFile, L"rb")!=0)
		{
			wprintf(L"Error: Can't open file '%s'\n", strInputFile);
			return 7;
		}

		// Get file size
		fseek(pFile, 0, SEEK_END);
		DWORD dwLength=ftell(pFile);
		fseek(pFile, 0, SEEK_SET);

		// Check has length
		if (dwLength==0)
		{
			fclose(pFile);
			wprintf(L"Error: Zero length file\n");
			return 7;
		}

		// Load file into memory
		LPBYTE pFileData=(LPBYTE)malloc(dwLength);

		// Read data
		if (fread(pFileData, dwLength, 1, pFile)!=1)
		{
			free(pFileData);
			fclose(pFile);
			wprintf(L"Error: Error reading file\n");
			return 7;
		}

		// Close the file
		fclose(pFile);

		if (CountCRCControlBlocks(pFileData, dwLength)>1)
			{
			free(pFileData);
			fclose(pFile);
			wprintf(L"Error: File contains multiple CRC Control blocks!\n");
			return 7;
			}
			

		// Locate CRC Control block
		CRCCONTROLBLOCK* pCRCBlock=LocateCRCControlBlock(pFileData, dwLength);
		if (!pCRCBlock)
		{
			free(pFileData);
			fclose(pFile);
			wprintf(L"Error: File doesn't contain CRC Control block!\n");
			return 7;
		}

		wprintf(L"CRC Control Block located at offset: 0x%.8x\n", reinterpret_cast<LPBYTE>(pCRCBlock)-pFileData);

		// Calculate the CRC upto start of control block
		pCRCBlock->dwCRC=CalculateModuleCRC(pFileData, dwLength, pCRCBlock);
		pCRCBlock->dwModuleLength=dwLength;

		wprintf(L"Module length: 0x%.8x\n", dwLength);
		wprintf(L"CRC: 0x%.8x\n", pCRCBlock->dwCRC);
				
		pFile=NULL;
		if (_wfopen_s(&pFile, strOutputFile, L"wb")!=0)
		{
			wprintf(L"Error: Can't open output file '%s'\n", strOutputFile);
			return 7;
		}

		if (!CheckModuleCRC(pFileData, dwLength))
		{
			wprintf(L"Error: double check failed\n");
			return 7;
		}

		// Write CRC stamped
		fwrite(pFileData, dwLength, 1, pFile);

		// Clean up
		free(pFileData);

		fclose(pFile);

		if (!CheckModuleCRC(strOutputFile))
		{
			CheckModuleCRCWithErrors(strOutputFile);
			return 7;
		}

		wprintf(L"CRC Stamped %s - OK\n\n", strOutputFile);
		return 0;
	}


	// Compile or decompile
	bool bDecompile=cl.GetSwitch(L"extract");
	bool bUnicode=cl.GetSwitch(L"unicode");
	bool bFlat=cl.GetSwitch(L"flat");

	// Get output file
	CUniString strOutputFile;
	cl.GetValue(L"out", strOutputFile);
	if (strOutputFile.IsEmpty())
	{
		strOutputFile=ChangeFileExtension(strInputFile.IsEmpty() ? L"" : strInputFile, bDecompile ? L"sini" : L"bini");
	}
	strOutputFile=QualifyPath(strOutputFile);


	// Setup file content provider with include paths
	CFileContentProvider fp;
	CVector<CUniString> vecIncludePaths;
	cl.GetMultiValue(L"i", vecIncludePaths);
	for (int i=0; i<vecIncludePaths.GetSize(); i++)
	{
		CUniString str=QualifyPath(vecIncludePaths[i]);
		fp.AddIncludePath(str);
	}

	// Get defines
	CVector<CUniString> vecDefines;
	cl.GetMultiValue(L"d", vecDefines);

	// Error handling...
	cl.CheckNoUnknownArgs();
	if (cl.HasError())
	{
		wprintf(cl.GetErrorMessage());
		wprintf(L"\n\n");
		return 7;
	}

	if (!bDecompile)
	{
		// Load the input file
		CProfileFile file;
		for (int i=0; i<vecDefines.GetSize(); i++)
		{
			CUniString strName, strValue;
			SplitString(vecDefines[i], L"=", strName, strValue);
			wprintf(L"#define %s %s\n", strName, strValue);
			file.Define(strName, strValue);
		}

		if (!file.Load(strInputFile, &fp))
		{
			HRESULT hr=HRESULT_FROM_WIN32(GetLastError());
			wprintf(file.GetParseError());
			return 7;
		}

		// Extract encryption key
		DWORD dwEncryptionKey=0;
		CProfileSection* pSection=file.FindSection(L"Sinic");
		if (pSection)
		{
			// Save the key
			dwEncryptionKey=pSection->GetIntValue(L"EncryptionKey", 0);

			// Remove the "sinic" section
			file.Remove(pSection);
		}

		// Create output file
		CFileStream OutStream;
		if (!OutStream.Create(strOutputFile))
		{
			HRESULT hr=HRESULT_FROM_WIN32(GetLastError());
			wprintf(L"Failed to create '%s' - %s (0x%.8x)\n\n", strOutputFile, FormatError(hr), hr);
			return 7;
		}

		// Save as binary file
		HRESULT hr;
		if (dwEncryptionKey)
		{
			CAutoPtr<IStream, SRefCounted> spEncStream;
			CreateCryptorStream(&OutStream, CCryptorKey(dwEncryptionKey), &spEncStream);
			hr=SaveBinaryProfile(file, spEncStream);
		}
		else
		{
			hr=SaveBinaryProfile(file, &OutStream);
		}
		OutStream.Close();
		if (FAILED(hr))
		{
			HRESULT hr=HRESULT_FROM_WIN32(GetLastError());
			wprintf(L"Failed to save '%s' - %s (0x%.8x)\n\n", strOutputFile, FormatError(hr), hr);
			DeleteFile(strOutputFile);
			return 7;
		}
	}
	else
	{
		// Open stream
		CFileStream InStream;
		if (!InStream.Open(strInputFile))
		{
			HRESULT hr=HRESULT_FROM_WIN32(GetLastError());
			wprintf(L"Failed to open '%s' - %s (0x%.8x)\n\n", strInputFile, FormatError(hr), hr);
			return 7;
		}

		// Load profile
		CProfileFile file;
		HRESULT hr=LoadBinaryProfile(file, &InStream);
		if (FAILED(hr))
		{
			if (hr!=E_UNEXPECTED)
			{
				wprintf(L"Failed to load '%s' - %s (0x%.8x)\n\n", strInputFile, FormatError(hr), hr);
				return 7;
			}
			else
			{
				wprintf(L"Failed to load '%s' - not a binary profile file\n\n", strInputFile);
				return 7;
			}
		}

		// Save as heirarchial
		if (!file.Save(strOutputFile, bUnicode, !bFlat))
		{
			HRESULT hr=HRESULT_FROM_WIN32(GetLastError());
			wprintf(L"Failed to save '%s' - %s (0x%.8x)\n\n", strInputFile, FormatError(hr), hr);
			return 7;
		}
	}

	wprintf(L"%s - OK\n\n", strOutputFile);

	return 0;
}