Beispiel #1
0
        void Key::writeString( const std::string& sValueName,
                               const std::string& sData )
        {
            HKEY hKey;
            LONG lRtn = RegCreateKeyExW( m_hRootKey, m_wsPath.c_str(), 0, NULL, 0,
                                         KEY_SET_VALUE, NULL, &hKey, NULL );
            if (lRtn != ERROR_SUCCESS) {
                BP_THROW( "RegCreateKeyExW(" + wideToUtf8(m_wsPath)
                          + ") returned: " + bp::conv::toString( lRtn ) );
            }

            std::wstring wData = utf8ToWide( sData );
            std::wstring wValueName = utf8ToWide( sValueName );
            lRtn = RegSetValueExW( hKey, wValueName.c_str(), 0, REG_SZ, 
                                   reinterpret_cast<const BYTE*>(wData.c_str()),
                                   static_cast<DWORD>(wData.length() * sizeof(wchar_t)) );
            if (lRtn != ERROR_SUCCESS) {
                BP_THROW( "RegSetValueExW(" + wideToUtf8(m_wsPath)
                          + ", " + sValueName + ", " + sData
                          + ") returned: " + bp::conv::toString( lRtn ) );
            }

            lRtn = RegCloseKey( hKey );
            if (lRtn != ERROR_SUCCESS) {
                BP_THROW( "RegCloseKey(" + wideToUtf8(m_wsPath)
                          + ") returned: " + bp::conv::toString( lRtn ) );
            }
        }
Beispiel #2
0
static void replaceItemNameParams(T* itm, pugi::xml_node& xmlNode)
{
	const char* name = xmlNode.attribute("name").value();
	const char* desc = xmlNode.attribute("desc").value();
	const char* fname = xmlNode.attribute("fname").value();
	
	// replace description
	if(strcmp(desc, itm->m_Description) != 0)
	{
		free(itm->m_Description);
		free(itm->m_DescriptionW);

		itm->m_Description = strdup(desc);
		itm->m_DescriptionW = wcsdup(utf8ToWide(itm->m_Description));
	}
	
	// replace name
	if(strcmp(name, itm->m_StoreName) != 0)
	{
		free(itm->m_StoreName);
		free(itm->m_StoreNameW);

		itm->m_StoreName = strdup(name);
		itm->m_StoreNameW = wcsdup(utf8ToWide(itm->m_StoreName));
	}
	
	// replace store icon (FNAME)
	char storeIcon[256];
	sprintf(storeIcon, "$Data/Weapons/StoreIcons/%s.dds", fname);
	if(strcmp(storeIcon, itm->m_StoreIcon) != 0)
	{
		free(itm->m_StoreIcon);
		itm->m_StoreIcon = strdup(storeIcon);
	}
}
Beispiel #3
0
        void Key::writeInt( const std::string& sValueName,
                            int nData )
        {
            HKEY hKey;
            LONG lRtn = RegCreateKeyExW( m_hRootKey, m_wsPath.c_str(), 0, NULL, 0,
                                         KEY_SET_VALUE, NULL, &hKey, NULL );
            if (lRtn != ERROR_SUCCESS) {
                BP_THROW( "RegCreateKeyExW(" + wideToUtf8(m_wsPath)
                          + ") returned: " + bp::conv::toString( lRtn ) );
            }

            std::wstring wValueName = utf8ToWide( sValueName );
            lRtn = RegSetValueExW( hKey, wValueName.c_str(), 0, REG_DWORD, 
                                   reinterpret_cast<BYTE*>(&nData), sizeof(nData) );
            if (lRtn != ERROR_SUCCESS) {
                BP_THROW( "RegSetValueExW(" + wideToUtf8(m_wsPath)
                          + ", " + sValueName + ", " 
                          + bp::conv::toString( nData )
                          + ") returned: " + bp::conv::toString( lRtn ) );
            }

            lRtn = RegCloseKey( hKey );
            if (lRtn != ERROR_SUCCESS) {
                BP_THROW( "RegCloseKey(" + wideToUtf8(m_wsPath)
                          + ") returned: " + bp::conv::toString( lRtn ) );
            }
        }
Beispiel #4
0
        std::string Key::readString( const std::string& sValueName ) const
        {
            HKEY hKey;
            LONG lRtn = RegOpenKeyExW( m_hRootKey, m_wsPath.c_str(),
                                       0, KEY_READ, &hKey );
            if (lRtn != ERROR_SUCCESS) {
                BP_THROW( "RegOpenKeyExW(" + wideToUtf8(m_wsPath)
                          + ") returned: " + bp::conv::toString( lRtn ) );
            }

            // TODO: could use RegQueryInfo to get required buf size.
            const int knBufSize = 2000;
            BYTE szBuf[knBufSize];
            DWORD dwBufSize = knBufSize;
            std::wstring wValueName = utf8ToWide( sValueName );
            lRtn = RegQueryValueExW( hKey, wValueName.c_str(),
                                     NULL, NULL, szBuf, &dwBufSize );
            if (lRtn != ERROR_SUCCESS) {
                BP_THROW( "RegQueryValueExW(" + wideToUtf8(m_wsPath)
                          + ", " + sValueName
                          + ") returned: " + bp::conv::toString( lRtn ) );
            }

            lRtn = RegCloseKey( hKey );
            if (lRtn != ERROR_SUCCESS) {
                BP_THROW( "RegCloseKey(" + wideToUtf8(m_wsPath)
                          + ") returned: " + bp::conv::toString( lRtn ) );
            }
            std::wstring wval(reinterpret_cast<wchar_t*>( szBuf ) );
            std::string rval = wideToUtf8( wval );
            return rval;
        }
Beispiel #5
0
 Value::Value( const std::string& sName,
               const Key* pParentKey,
               DWORD dwValueType ) :
     m_pParentKey( pParentKey ),
     m_dwValueType( dwValueType )
 {
     m_wsName = utf8ToWide( sName );
 }
Beispiel #6
0
     Key::Key( const std::string& sPath ) :
         m_wsPath(),
         m_hRootKey()
     {
         // The first part of input path should be root key name.
         size_t nPos = sPath.find( "\\" );
         string sRootKey = sPath.substr( 0, nPos );
         m_hRootKey = rootKeyFromString( sRootKey );
 
         // We'll store our path as everything after the root key and separator.
         m_wsPath= utf8ToWide( sPath.substr( nPos+1 ) );
     }
bool MSWeaponArmory::loadItem(pugi::xml_node& xmlItem)
{
	r3d_assert(!xmlItem.empty());

	uint32_t itemID = xmlItem.attribute("itemID").as_uint();
	for(uint32_t i=0; i<m_NumItemLoaded; ++i) // todo: change to hash table
	{
		if(m_ItemArray[i]->m_itemID == itemID)
		{
			r3dOutToLog("Trying to load an item with id '%d' that is already loaded!", itemID);
			return false;
		}
	}
	if(m_NumItemLoaded > MAX_NUMBER_ITEM-1)
	{
		r3dOutToLog("Trying to load more than maximum number of items. Maximum is '%d'\n", MAX_NUMBER_ITEM);
		return false;
	}

	ItemConfig* item = new ItemConfig(itemID);
	item->category = (STORE_CATEGORIES)xmlItem.attribute("category").as_int();

	const char* desc = xmlItem.child("Store").attribute("desc").value();
	r3d_assert(desc);
	item->m_Description = strdup(desc);
	item->m_StoreIcon = strdup(xmlItem.child("Store").attribute("icon").value());
	item->m_StoreName = strdup(xmlItem.child("Store").attribute("name").value());
	item->m_LevelRequired = xmlItem.child("Store").attribute("LevelRequired").as_int();
	item->m_StoreNameW = wcsdup(utf8ToWide(item->m_StoreName));
	item->m_DescriptionW = wcsdup(utf8ToWide(item->m_Description));

	if(!xmlItem.child("Model").empty())
		item->m_ModelPath = strdup(xmlItem.child("Model").attribute("file").value());

	m_ItemArray[m_NumItemLoaded] = item;
	m_NumItemLoaded++;

	return true;
}
Beispiel #8
0
int main(int argc, char **argv)
{
	if (argc < 2)
	{
		printf("Usage: %s <drive letter>\n", argv[0]);
		return 0;
	}
	
	DOKAN_OPTIONS options;
	DOKAN_OPERATIONS operations;
	
	ZeroMemory(&options, sizeof(DOKAN_OPTIONS));
	options.Version = DOKAN_VERSION;
	options.ThreadCount = 0; // use default
	std::wstring mountPoint = utf8ToWide(argv[1]);
	options.MountPoint = mountPoint.c_str();
	options.Options = DOKAN_OPTION_DEBUG | DOKAN_OPTION_STDERR | DOKAN_OPTION_KEEP_ALIVE;
	
	ZeroMemory(&operations, sizeof(DOKAN_OPERATIONS));
	operations.CreateFile = WendyCreateFile;
	operations.OpenDirectory = WendyOpenDirectory;
	operations.CreateDirectory = WendyCreateDirectory;
	operations.Cleanup = WendyCleanup;
	operations.CloseFile = WendyCloseFile;
	operations.ReadFile = WendyReadFile;
	operations.WriteFile = WendyWriteFile;
	operations.GetFileInformation = WendyGetFileInformation;
	operations.FindFiles = WendyFindFiles;
	operations.DeleteFile = WendyDeleteFile;
	operations.DeleteDirectory = WendyDeleteDirectory;
	operations.GetDiskFreeSpace = WendyGetDiskFreeSpace;
	operations.GetVolumeInformation = WendyGetVolumeInformation;
	
	fs = new FileSystem;
	
	InitializeCriticalSection(&wendyMutex);
	
	int result = DokanMain(&options, &operations);
	
	DeleteCriticalSection(&wendyMutex);
	
	delete fs;
	
	return result;
}
Beispiel #9
0
static int DOKAN_CALLBACK WendyFindFiles(LPCWSTR filename, PFillFindData fillFindData, PDOKAN_FILE_INFO info)
{
	ScopeLock lock;
	wprintf(L"FindFiles %s\n", filename);
	
	WIN32_FIND_DATAW entry;
	ZeroMemory(&entry, sizeof(WIN32_FIND_DATAW));
	
	// insert special dirs '.' and '..'
	entry.dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
	wcscpy(entry.cFileName, L".");
	fillFindData(&entry, info);
	wcscpy(entry.cFileName, L"..");
	fillFindData(&entry, info);
	
	std::string path = makePathStandard(filename);
	
	std::vector<std::string> files;
	fs->readdir(path, &files);
	for (unsigned int i = 0; i < files.size(); ++i)
	{
		// filename
		const std::string &filename = files[i];
		std::wstring wfilename = utf8ToWide(filename);
		wcsncpy(entry.cFileName, wfilename.c_str(), MAX_PATH - 1);
		
		// other attributes
		FileSystem::FileAttributes attributes;
		std::string fullChildPath = files[i];
		if (path.size() > 0)
			fullChildPath = path + "/" + files[i];
		fs->stat(fullChildPath, &attributes);
		entry.dwFileAttributes = attributes.folder ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_NORMAL;
		entry.nFileSizeLow = attributes.length; // TODO: use the 64 bits
		entry.ftLastWriteTime = unixTimeToFileTime(attributes.date);
		
		// send item back to caller
		fillFindData(&entry, info);
	}
	
	return 0;
}
Beispiel #10
0
static int DOKAN_CALLBACK WendyCreateFile(LPCWSTR filename, DWORD accessMode, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes, PDOKAN_FILE_INFO info)
{
	ScopeLock lock;
	
	wprintf(L"CreateFile: %s\n", filename);
	
	std::string path = makePathStandard(filename);
	
	FileSystem::FileAttributes attributes;
	bool exists = fs->stat(path, &attributes);
	
	// cases when the file MUST exist
	if (!exists && ((creationDisposition == OPEN_EXISTING) || (creationDisposition == TRUNCATE_EXISTING)))
		return -ERROR_PATH_NOT_FOUND;
	
	// cases when the file MUST NOT exist
	if (exists && (creationDisposition == CREATE_NEW))
		return -ERROR_FILE_EXISTS;
	
	if (attributes.folder)
	{
		// flag as directory
		info->IsDirectory = TRUE;
	}
	else
	{
		// no real open
		if (accessMode == 0)
			return 0;
		
		// retrieve opening process name
		std::string processName = "unknown application";
		HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, info->ProcessId);
		if (process != NULL)
		{
			wchar_t processBaseName[256];
			DWORD length = GetModuleBaseName(process, NULL, processBaseName, 255);
			if (length > 0)
				processName = wideToUtf8(processBaseName);
			CloseHandle(process);
		}
		
		std::wstring processNameWide = utf8ToWide(processName);
		wprintf(L"%s opened by %s\n", filename, processNameWide.c_str());
		
		// translate access mode
		bool reading = false;
		bool writing = false;
		
		//if ((accessMode & FILE_GENERIC_READ) == FILE_GENERIC_READ) reading = true;
		//if ((accessMode & FILE_GENERIC_WRITE) == FILE_GENERIC_WRITE) writing = true;
		reading = true;
		
		if (writing)
			return -ERROR_ACCESS_DENIED;
		
		// open asset
		File *file = fs->open(path, reading, writing, false, processName);
		if (!file)
			return -ERROR_PATH_NOT_FOUND;
		
		info->Context = (ULONG64)file; // file descriptor
		wprintf(L"CreateFile succeeded (handle = 0x%x\n", file);
	}
	
	return 0;
}
Beispiel #11
0
char* realpath(const char * name, char * resolved)
{
    char *retname = NULL;

    /* SUSv3 says we must set `errno = EINVAL', and return NULL,
    * if `name' is passed as a NULL pointer.
    */
    if (name == NULL)
    {
        errno = EINVAL;
        return NULL;
    }

    /* Otherwise, `name' must refer to a readable filesystem object,
    * if we are going to resolve its absolute path name.
    */
    wchar_t wideNameBuffer[PATH_MAX];
    wchar_t *wideName = wideNameBuffer;
    if (!utf8ToWide(name, wideName, PATH_MAX))
    {
        errno = EINVAL;
        return NULL;
    }

    if (_waccess(wideName, 4) != 0)
        return NULL;

    /* If `name' didn't point to an existing entity,
    * then we don't get to here; we simply fall past this block,
    * returning NULL, with `errno' appropriately set by `access'.
    *
    * When we _do_ get to here, then we can use `_fullpath' to
    * resolve the full path for `name' into `resolved', but first,
    * check that we have a suitable buffer, in which to return it.
    */

    if ((retname = resolved) == NULL)
    {
        /* Caller didn't give us a buffer, so we'll exercise the
        * option granted by SUSv3, and allocate one.
        *
        * `_fullpath' would do this for us, but it uses `malloc', and
        * Microsoft's implementation doesn't set `errno' on failure.
        * If we don't do this explicitly ourselves, then we will not
        * know if `_fullpath' fails on `malloc' failure, or for some
        * other reason, and we want to set `errno = ENOMEM' for the
        * `malloc' failure case.
        */

        retname = (char *)malloc(PATH_MAX);
        if (retname == NULL)
        {
            errno = ENOMEM;
            return NULL;
        }
    }

    /* Otherwise, when we do have a valid buffer,
    * `_fullpath' should only fail if the path name is too long.
    */

    wchar_t wideFullPathBuffer[PATH_MAX];
    wchar_t *wideFullPath;
    if ((wideFullPath = _wfullpath(wideFullPathBuffer, wideName, PATH_MAX)) == NULL)
    {
        errno = ENAMETOOLONG;
        return NULL;
    }

    // Do a LongPath<->ShortPath roundtrip so that case is resolved by OS
    // FIXME: Check for failure
    size_t initialLength = wcslen(wideFullPath);
    GetShortPathNameW(wideFullPath, wideNameBuffer, PATH_MAX);
    GetLongPathNameW(wideNameBuffer, wideFullPathBuffer, initialLength + 1);

    // Convert back to UTF-8
    if (!wideToUtf8(wideFullPathBuffer, retname, PATH_MAX))
    {
        errno = EINVAL;
        return NULL;
    }

    // Force drive to be upper case
    if (retname[1] == ':')
        retname[0] = toupper(retname[0]);

    return retname;
}