示例#1
0
void KGSFXModelViewPage::OnNMDblclkTree(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
    HTREEITEM hTreeItem = m_tree.GetSelectedItem();
    CString strPath = TEXT("");
    KG_PROCESS_ERROR(hTreeItem);
    while (hTreeItem)
    {
        strPath =
            TEXT("\\") + m_tree.GetItemText(hTreeItem) + strPath;
        hTreeItem = m_tree.GetParentItem(hTreeItem);
    }

    m_strSelPath = m_strStartPath + strPath;

    char* fileName = m_strSelPath.GetBuffer();

    if (g_IsFileExist(fileName))
    {
        char fullPath[MAX_PATH];
        g_GetFullPath(fullPath, fileName);
        AfxGetApp()->OpenDocumentFile(fullPath);
    }

    m_strSelPath.ReleaseBuffer();
    

Exit0:
    *pResult = 0;
}
示例#2
0
文件: UiBase.cpp 项目: viticm/pap2
//清除当前玩家私有数据的存储目录
void KUiBase::ClearFolder(const char* pszFolder, bool bDeleteFolder)
{
	char szPathFile[MAX_PATH];
	WIN32_FIND_DATA FileData;
	HANDLE hFind;

	if (pszFolder && pszFolder[0])
	{
		g_GetFullPath(szPathFile, (char*)pszFolder);
		int		nLen = strlen(szPathFile) + 1;
		strcat(szPathFile, "\\*.*");
		hFind = FindFirstFile(szPathFile, &FileData);
		if(hFind != INVALID_HANDLE_VALUE)
		{
			do
			{
				strcpy(szPathFile + nLen, FileData.cFileName);
				SetFileAttributes(szPathFile, FILE_ATTRIBUTE_NORMAL);
				DeleteFile(szPathFile);
			}while(FindNextFile(hFind, &FileData));
			FindClose(hFind);
		}
		if (bDeleteFolder)
		{
			szPathFile[nLen - 1] = 0;
			RemoveDirectory(szPathFile);
		}
	}
}
示例#3
0
void KGSFXModelViewPage::UpdateMdelAin()
{
    GET_SFX_EDITOR();
    TCHAR szFullPath[MAX_PATH];
    g_GetFullPath(szFullPath, m_strAinPath.GetBuffer());
    pScene->UpdateBindOrRefrenceAni(szFullPath);
}
示例#4
0
//---------------------------------------------------------------------------
// 功能:	创建一个文件,准备写入。
// 参数:	FileName	文件名
// 返回:	成功返回TRUE,失败返回FALSE。
//---------------------------------------------------------------------------
QAloneFile*	QAloneFile::Create(const char*  FileName)
{
	FILE* pFile = NULL;

	char FullPathName[MAX_PATH] = "";
	g_GetFullPath(FullPathName, FileName);
#ifdef unix
	{
		char *ptr = FullPathName;
		while(*ptr)
		{
			if (*ptr == '\\')
				*ptr = '/';
			ptr++;
		}
	}
#endif	// #ifdef unix
	char PathName[MAX_PATH] = "";
	g_ExtractFilePath(PathName, FullPathName);
	g_CreatePath(PathName);
	pFile = fopen(FullPathName, "wb+");
#ifdef unix
	{
		if (pFile == NULL)
		{
			QStrLower(FullPathName);
			pFile = fopen(FullPathName, "wb+");
		}
	}
#endif	// #ifdef unix

	return pFile ? new QAloneFile(pFile) : NULL;
}
示例#5
0
//---------------------------------------------------------------------------
// 函数:	Open
// 功能:	打开一个文件,准备读取
// 参数:	FileName	文件名
// 返回:	成功返回TRUE,失败返回FALSE。
//---------------------------------------------------------------------------
BOOL KFile::Open(LPSTR FileName)
{
	char PathName[MAXPATH];
	
	// close prior file handle
	//if (m_hFile != INVALID_HANDLE_VALUE)
	//	Close();

	if (m_hFile != NULL)
		Close();

	// get full path name
	g_GetFullPath(PathName, FileName);
/*#ifndef WIN32
	char *name_ptr = PathName;
	while(*name_ptr) {
		if(*name_ptr == '\\') *name_ptr = '/';
		name_ptr++;
	}
#endif
	// Open the file for read
	m_hFile = CreateFile(
		PathName,		// pointer to name of the file with path
		GENERIC_READ,	// access (read-write) mode
		FILE_SHARE_READ,// share mode
		NULL,			// pointer to security attributes
		OPEN_EXISTING,	// how to create
		FILE_ATTRIBUTE_NORMAL,// file attributes
		NULL);			// template file*/
#ifndef WIN32
        char *ptr = PathName;
        while(*ptr) {
          if(*ptr == '\\') *ptr = '/';
          ptr++;
        }

		//open lower case file for linux
		char lcasePathName[MAXPATH];
		char szRootPath[MAXPATH];
		g_GetRootPath(szRootPath);
		strcpy(lcasePathName, PathName);
		if (memcmp(lcasePathName, szRootPath, strlen(szRootPath)) == 0)
			strlwr(lcasePathName + strlen(szRootPath));
		else
			strlwr(lcasePathName);
		if (NULL == (m_hFile = fopen(lcasePathName, "rb")))
#endif
	m_hFile = fopen(PathName, "rb");

	// check file handle
	//if (m_hFile == INVALID_HANDLE_VALUE)
	//	return FALSE;

	if (m_hFile == NULL)
	{
		return FALSE;
	}
	
	return TRUE;
}
BOOL KSceneSettingPageRegionSplit::GetFileTime( LPCTSTR lpPath, LPFILETIME lpFileTime )
{
	_ASSERTE(lpPath && lpFileTime);

	char tcsFullPath[MAX_PATH] = "";
	KG_CUSTOM_HELPERS::UnicodeConvertor Cvt;
	g_GetFullPath(
		tcsFullPath,
#if defined(_UNICODE) | defined(UNICODE)
		Cvt.ToA(lpPath)
#else
		lpPath
#endif
		);

	WIN32_FIND_DATAA	FindedData;

	HANDLE hFind = ::FindFirstFile(lpPath, &FindedData);
	KG_PROCESS_ERROR(hFind);

	*lpFileTime = FindedData.ftLastWriteTime;

	if(hFind)
		::FindClose(hFind);
	return TRUE;
Exit0:
	if(hFind)
		::FindClose(hFind);
	return FALSE;
}
示例#7
0
void KGSFXModelViewPage::UpdateBindModel()
{
    GET_SFX_EDITOR();
    TCHAR szFullPath[MAX_PATH];
    g_GetFullPath(szFullPath, m_strSelPath.GetBuffer());
    if (CheckModelName(szFullPath))
        pScene->UpdateBindOrRefrenceModel(szFullPath);
}
示例#8
0
bool KTaskDataFile::SaveData()
{
	KFile	File;
	char	szFileName[128];

	GetFileName(szFileName, sizeof(szFileName));

	bool	bOk = false;
	while (ms_pPersonalRecord || ms_nSystemRecordCount > 0)
	{
		if (!File.Create(szFileName))
			break;
		//==写文件头==
		TASK_FILE_HEADER	Header = { 0 };
		*(int*)(&(Header.cFlag[0])) = TASK_FILE_FLAG;
		if (ms_pPersonalRecord && ms_pPersonalRecord->nLen > 0)
		{
			Header.nPersonalRecordBytes = sizeof(KPersonalRecord) +
				ms_pPersonalRecord->nLen - sizeof(ms_pPersonalRecord->cBuffer);
		}
		Header.nSystemRecordCount = ms_nSystemRecordCount;
		if (File.Write(&Header, sizeof(Header)) != sizeof(Header))
			break;

		//==写个人纪录==
		if (ms_pPersonalRecord)
		{
			if (File.Write(ms_pPersonalRecord, Header.nPersonalRecordBytes) != Header.nPersonalRecordBytes)
				break;
		}

		//==写系统纪录==
		KTaskSystemRecordNode* pCurrent = ms_pSystemRecordList;
		int	i;
		for (i = 0; i < ms_nSystemRecordCount; i++)
		{
			int nSize = sizeof(TASK_SYSTEM_RECORD) + pCurrent->Record.nContentLen -
				sizeof(pCurrent->Record.cBuffer);
			if (File.Write(&pCurrent->Record, nSize) != nSize)
				break;
			pCurrent = pCurrent->pNext;
		}
		if (i >= ms_nSystemRecordCount)
		{
			bOk = true;
		}
		break;
	};

	File.Close();
	if (bOk == false)
	{
		char	szFullName[MAX_PATH];
		g_GetFullPath(szFullName, szFileName);
		DeleteFile(szFullName);
	}
	return bOk;
}
示例#9
0
文件: UiBase.cpp 项目: viticm/pap2
//清除当前玩家私有数据的某个文件
void KUiBase::DeletePrivateDataFile(const char* pszFileName)
{
	char	szBuffer[128], szPathFile[MAX_PATH];

	if (pszFileName && pszFileName[0])
	{
		sprintf(szBuffer, "%s\\%s\\%s", UI_USER_DATA_FOLDER, m_UserAccountId, pszFileName);
		g_GetFullPath(szPathFile, (char*)szBuffer);
		SetFileAttributes(szPathFile, FILE_ATTRIBUTE_NORMAL);
		DeleteFile(szPathFile);
	}
}
示例#10
0
//---------------------------------------------------------------------------
// 功能:	打开一个文件,准备读取写
// 参数:	FileName	文件名
// 返回:	成功返回TRUE,失败返回FALSE。
//---------------------------------------------------------------------------
QAloneFile*	QAloneFile::Open(const char* FileName, int WriteSupport /*= false*/)
{
	FILE* pFile = NULL;
	char PathName[MAX_PATH];
	g_GetFullPath(PathName, FileName);

	#ifdef unix
	{
		char *ptr = PathName;
        while(*ptr)
		{
			if (*ptr == '\\')
				*ptr = '/';
			ptr++;
        }
	}
	#endif	// #ifdef unix

	const char*	pMode = "rb";
	if (WriteSupport)
	{
		if (g_IsFileExist(PathName))
			pMode = "r+b";
		else
			pMode = "a+b";
	}

	pFile = fopen(PathName, pMode);
	#ifdef unix
	{
		if (pFile == NULL)
		{
			QStrLower(PathName);
			pFile = fopen(PathName, pMode);
		}
	}
	#endif	// #ifdef unix

	if (pFile)
	{
		QAloneFile* pAloneFile = new QAloneFile(pFile);
		if (pAloneFile && WriteSupport)
			pAloneFile->m_nContentBufferSize = -1;
		return pAloneFile;
	}
	else
	{
		return NULL;
	}
}
示例#11
0
LRESULT KGSFXGlobPage::OnColorBkDialogClose(WPARAM w, LPARAM l)
{
    GET_SFX_EDITOR_RET(0);

    TCHAR szIniPath[MAX_PATH];
    g_GetFullPath(szIniPath, TEXT("config.ini"));
    IIniFile* pIniFile = g_OpenIniFile(szIniPath, true, true);

    if (pIniFile)
    {
        pIniFile->WriteStruct(TEXT("SfxEditor"), TEXT("bkcolor"), pScene->GetBkColorPtr(), sizeof(DWORD));
        pIniFile->Save(szIniPath);
        pIniFile->Release();
    }

    return 1;
}
示例#12
0
int KGSFXModelViewPage::FillComb()
{
    int nResult  = false;

    TCHAR  szFilePath[MAX_PATH];
    TCHAR  szFullPath[MAX_PATH];
    TCHAR* pExt = NULL;
    CFileFind fileFind;

    g_GetFullPath(szFullPath, m_strSelPath.GetBuffer());
    pExt = strrchr(szFullPath, '\\');
    KG_PROCESS_ERROR(pExt);
    *pExt = '\0';

    m_comb.ResetContent();
    sprintf(szFilePath, "%s%s", szFullPath, TEXT("\\*.*"));
    BOOL bWorking = fileFind.FindFile(szFilePath);
    while (bWorking)
    {
        bWorking = fileFind.FindNextFile();
        if (fileFind.IsDots())
            continue;
        CString strPath = fileFind.GetFilePath();
        CString strName = fileFind.GetFileName();
        if (fileFind.IsDirectory())
            continue;

        TCHAR  szName[MAX_PATH];
        strncpy(szName, strName.GetBuffer(), sizeof(szName));
        TCHAR* pszExt = strrchr(szName, '.');
        if (!pszExt)
            continue;
        if (!stricmp(pszExt, TEXT(".ani")))
            m_comb.AddString(szName);
        else
            continue;

    }
    m_comb.AddString(TEXT("浏览......"));
    fileFind.Close();

    nResult = true;
Exit0:
    return nResult;
}
示例#13
0
void KPvsAttriPanel::OnBnClickedButtonIw()
{
    if (!GetPvsScene())
        return;

    IEKG3DRepresentPVS* pvs = GetPvsScene()->GetPvs();

    if (!pvs)
        return;

    char szFullPath[MAX_PATH];
    char szFilePath[MAX_PATH];

    sprintf(szFilePath, TEXT("data\\source\\pvs\\"));
    g_GetFullPath(szFullPath, szFilePath);

    char szFilters[] = "Mesh Files|*.Mesh|Mdl Files|*.Mdl||";

    CFileDialog fileDlg(
        TRUE,
        szFullPath,
        NULL,
        OFN_EXPLORER|OFN_FILEMUSTEXIST| OFN_HIDEREADONLY,
        szFilters,
        this
        );
    fileDlg.m_ofn.lStructSize = sizeof(fileDlg.m_ofn);
    fileDlg.m_ofn.lpstrTitle  = "选择内墙模型";
    fileDlg.m_ofn.lpstrInitialDir = szFullPath;

    if (fileDlg.DoModal() == IDOK)
    {
        m_strIW = fileDlg.GetPathName();

        TCHAR szRetPaht[MAX_PATH];
        if (g_GetFilePathFromFullPath(szRetPaht, m_strIW.GetBuffer()))
            m_strIW = szRetPaht;
        m_strIW.ReleaseBuffer();
        UpdateData(FALSE);

        pvs->SetInsideBorderModel(m_strIW.GetBuffer());
        m_strIW.ReleaseBuffer();
   
    }
}
示例#14
0
void KUiInit::PlayStartMovie()
{
	KIniFile	Ini;

	char	szMovieIndex[32], szFile[128];
	char	szPathFile[MAX_PATH];

	if (Ini.Load(LAUNCH_GAME_INI))
	{
		int		nSkipable;
		sprintf(szMovieIndex, "Movie_%d", m_nCurrentMovieIndex);
		Ini.GetString("JustLaunched", szMovieIndex, "", szFile, sizeof(szFile));
		strcat(szMovieIndex, "_Skipable");
		Ini.GetInteger("JustLaunched", szMovieIndex, 0, &nSkipable);

		if (szFile[0])
		{			
			KUiPlayVideo* pPlayer = KUiPlayVideo::OpenWindow();
			if (pPlayer)
			{
				pPlayer->SetPosition(0, 0);
				int nWidth, nHeight;
				Wnd_GetScreenSize(nWidth, nHeight);
				pPlayer->SetSize(nWidth, nHeight);
				pPlayer->Setting(nSkipable != 0, false, this, 0);
		
				g_GetFullPath(szPathFile, szFile);
				if (pPlayer->OpenVideo(szPathFile))
				{	//成功播放影片
					m_nCurrentMovieIndex++;
					return;
				}
			}
		}
	}
	KUiPlayVideo::CloseWindow(true);
	Wnd_ShowCursor(true);
	OpenWindow(true, false);
}
示例#15
0
//---------------------------------------------------------------------------
// 函数:	Append
// 功能:	打开一个文件,准备在后部添加数据,如果此文件不存在,则产生这个文件。
// 参数:	FileName	文件名
// 返回:	成功返回TRUE,失败返回FALSE。
//---------------------------------------------------------------------------
BOOL KFile::Append(LPSTR FileName)
{
	char PathName[MAXPATH];
	
	// close prior file handle
	//if (m_hFile != INVALID_HANDLE_VALUE)
	//	Close();

	if (m_hFile != NULL)
		Close();
	
	// get full path name
	g_GetFullPath(PathName, FileName);

	// change file attribute for write
//	SetFileAttributes(PathName, FILE_ATTRIBUTE_NORMAL);

	// create file for write
/*	m_hFile = CreateFile(
		PathName,		// pointer to name of the file with path
		GENERIC_WRITE,	// access (read-write) mode
		FILE_SHARE_READ,// share mode
		NULL,			// pointer to security attributes
		OPEN_ALWAYS,	// Opens the file, if it exists. If the file does not exist, the function creates the file as if dwCreationDisposition were CREATE_NEW
		FILE_ATTRIBUTE_NORMAL, // file attributes
		NULL);			// template file*/
	//if (m_hFile == INVALID_HANDLE_VALUE)
	//	return FALSE;
	
	// check file handle
	m_hFile = fopen(PathName, "ab");
	if (m_hFile == NULL)
		return FALSE;

	Seek(0, FILE_END);
	return TRUE;
}
示例#16
0
//---------------------------------------------------------------------------
// 函数:	Create
// 功能:	创建一个文件,准备写入。
// 参数:	FileName	文件名
// 返回:	成功返回TRUE,失败返回FALSE。
//---------------------------------------------------------------------------
BOOL KFile::Create(LPSTR FileName)
{
	char PathName[MAXPATH];
	
	// close prior file handle
	//if (m_hFile != INVALID_HANDLE_VALUE)
	//	Close();

	if (m_hFile != NULL)
		Close();
	
	// get full path name
	g_GetFullPath(PathName, FileName);

	// change file attribute for write
//	SetFileAttributes(PathName, FILE_ATTRIBUTE_NORMAL);

	// create file for write
/*	m_hFile = CreateFile(
		PathName,		// pointer to name of the file with path
		GENERIC_WRITE,	// access (read-write) mode
		FILE_SHARE_READ,// share mode
		NULL,			// pointer to security attributes
		CREATE_ALWAYS,	// create or over write
		FILE_ATTRIBUTE_NORMAL, // file attributes
		NULL);			// template file
*/	
	m_hFile = fopen(PathName, "wb+");
	// check file handle
	//if (m_hFile == INVALID_HANDLE_VALUE)
	//	return FALSE;

	if (m_hFile == NULL)
		return FALSE;
	return TRUE;
}
示例#17
0
//创建/打开的一个打包文件,返回打包文件索引,返回0值表示操作失败。
int KPackFileManager::CreatePack(const char* pszFile, int bOpenExist, int bExcludeOfCheckId)
{
    int nPakIndex;
    for (nPakIndex = 0; nPakIndex < PACK_FILE_SHELL_MAX_SUPPORT_PAK_NUM; nPakIndex++)
    {
        if (m_PackItemList[nPakIndex].pIOFile == NULL)
            break;
    }
    if (nPakIndex == PACK_FILE_SHELL_MAX_SUPPORT_PAK_NUM)
        return -1;

    PACK_ITEM& item = m_PackItemList[nPakIndex];
    bool bOk = false;
	g_GetFullPath(item.PackFileName, pszFile);
    while(true)
    {
        item.pIndexList = (XPackIndexInfo*)malloc(sizeof(XPackIndexInfo) * PACK_FILE_SHELL_MAX_SUPPORT_ELEM_FILE_NUM);
        if (item.pIndexList == NULL)
            break;
        memset(item.pIndexList, 0, sizeof(XPackIndexInfo) * PACK_FILE_SHELL_MAX_SUPPORT_ELEM_FILE_NUM);
        if (bOpenExist)
        {
			if (!g_IsFileExist(pszFile))	//FilePath.cpp:426 --> pszFile = 路径名+文件名
				break;
			item.pIOFile = g_OpenFile(pszFile, true, true);
			if (item.pIOFile == NULL)
				break;
			if (item.pIOFile->Read(&item.Header, sizeof(item.Header)) != sizeof(item.Header) ||
				(*(int*)(&(item.Header.cSignature)) != IPACK_FILE_SIGNATURE_FLAG))
			{
				break;
			}
			item.pIOFile->Seek(item.Header.uIndexTableOffset, SEEK_SET);
			if (item.pIOFile->Read(item.pIndexList, sizeof(XPackIndexInfo) * item.Header.uCount) != sizeof(XPackIndexInfo) * item.Header.uCount)//读入文件尾部,插入新的文件数据之后再插回来
				break;
			item.nDataEndOffset = item.Header.uIndexTableOffset;
			item.pIOFile->Seek(item.nDataEndOffset, SEEK_SET);
			LoadPackPartner(nPakIndex);
        }
        else
        {
            item.pIOFile = g_CreateFile(pszFile);
            if (item.pIOFile == NULL)
                break;
            memset(&item.Header, 0, sizeof(item.Header));
            *(int*)(&(item.Header.cSignature)) = IPACK_FILE_SIGNATURE_FLAG;		/* 前提条件为:Little-Endian */
            if (item.pIOFile->Write(&item.Header, sizeof(item.Header)) != sizeof(item.Header))
                break;
            item.Header.uDataOffset = sizeof(item.Header);
            item.nDataEndOffset = sizeof(item.Header);
            item.bModified = true;
			CreatePackPartner(nPakIndex);
        }
        item.bExcludeOfCheckId = (bExcludeOfCheckId != false);
        bOk = true;
        break;
    }

    if (!bOk)
    {
		SAFE_FREE(item.pIndexList);
		SAFE_RELEASE(item.pIOFile);
		item.PackFileName[0] = 0;
        return -1;
    }

    return nPakIndex;
}
BOOL KScriptManager::Reload(const char* pszFileName)
{
    BOOL            bResult                 = false;
    BOOL            bRetCode                = false;
    IFile*          piFile                  = NULL;
    char*           pszBuffer               = NULL;
    DWORD           dwScriptID              = 0;
    DWORD           dwFileSize              = 0;
    DWORD           dwReadSize              = 0;
    KLuaScriptData* pScriptData             = NULL;
    char            szPathName[MAX_PATH];
    char            szFileName[MAX_PATH];

    assert(pszFileName);

    piFile = g_OpenFile(pszFileName);
    KG_PROCESS_ERROR(piFile);

    dwFileSize = piFile->Size();

    pszBuffer = new char[dwFileSize];
    KG_PROCESS_ERROR(pszBuffer);

    dwReadSize = piFile->Read(pszBuffer, dwFileSize);
    KG_PROCESS_ERROR(dwReadSize == dwFileSize);

    g_GetFullPath(szPathName, pszFileName);

    bRetCode = g_GetFilePathFromFullPath(szFileName, szPathName);
    KG_PROCESS_ERROR(bRetCode);

    dwScriptID = g_FileNameHash(szFileName);

    bRetCode = IsScriptExist(dwScriptID);
    KG_PROCESS_ERROR(bRetCode);

    bRetCode = m_piScript->LoadFromBuffer(dwScriptID, szPathName, pszBuffer, dwFileSize);
    KG_PROCESS_ERROR(bRetCode);

    pScriptData = m_piScript->GetScriptData(dwScriptID);
    if (pScriptData)
    {
        std::vector<DWORD>::iterator it = pScriptData->vecIncludeScriptID.begin();
        std::vector<DWORD>::iterator itEnd = pScriptData->vecIncludeScriptID.end();

        for (NULL; it != itEnd; ++it)
        {
            KLuaScriptData* pNewScriptData = NULL;

            pNewScriptData = m_piScript->GetScriptData(*it);
            if (pNewScriptData)
                Reload(pNewScriptData->szName);
        }
    }

    bResult = true;
Exit0:
    if (!bResult)
    {
        KGLogPrintf(KGLOG_ERR, "[Lua] Failed to reload file \"%s\" !\n", pszFileName);
    }
    KG_DELETE_ARRAY(pszBuffer);
    KG_COM_RELEASE(piFile);
    return bResult;
}