//================================================================================================================
//================================================================================================================
CreateGameDirectory::CreateGameDirectory(GameDirectory2D* gd, GameType2D gameType)
{
	_mkdir(gd->GAME_FOLDER.c_str());
	_mkdir(gd->m_required_textures.c_str());
	_mkdir(gd->m_sprites_path.c_str());
	_mkdir(gd->m_menu_sprites_path.c_str());
	_mkdir(gd->m_hud_path.c_str());
	_mkdir(gd->m_tiles_path.c_str());
	_mkdir(gd->m_scripts_path.c_str());
	_mkdir(gd->m_music_path.c_str());
	_mkdir(gd->m_animation_profiles_path.c_str());
	_mkdir(gd->m_animation_profile_sprites_path.c_str());
	_mkdir(gd->m_animation_profile_tiles_path.c_str());
	_mkdir(gd->m_xml_path.c_str());
	_mkdir(gd->m_xml_maps_path.c_str());
	_mkdir(gd->m_xml_sprites_path.c_str());
	//_mkdir(gd->m_xml_menu_path.c_str());
	//_mkdir(gd->m_xml_hud_path.c_str());
	_mkdir(gd->m_xml_worlds_path.c_str());

	if (gameType == TOPDOWN)
	{
		CFileWriter fileWriter;
		fileWriter.Open(gd->m_game_ini_path);
		fileWriter.Write("[GAME]\n");
		fileWriter.Write("\n");
		fileWriter.Write(";Game can either be Topdown or Platformer, 3D for 3D game\n");
		fileWriter.Write("GameType=Topdown\n");
		fileWriter.Close();
	}
	else if (gameType == PLATFORMER)
	{
		CFileWriter fileWriter;
		fileWriter.Open(gd->m_game_ini_path);
		fileWriter.Write("[GAME]\n");
		fileWriter.Write("\n");
		fileWriter.Write(";Game can either be Topdown or Platformer, 3D for 3D game\n");
		fileWriter.Write("GameType=Platformer\n");
		fileWriter.Close();
	}
	
	CFileWriter fileMainMenuWriter;
	fileMainMenuWriter.Open(gd->m_xml_main_menu_path);
	fileMainMenuWriter.Close();
	
	CFileWriter fileInGameMenuWriter;
	fileInGameMenuWriter.Open(gd->m_xml_ingame_menu_path);
	fileInGameMenuWriter.Close();

	CFileWriter fileHUDWriter;
	fileHUDWriter.Open(gd->m_xml_hud_path);
	fileHUDWriter.Close();
	
	CFileWriter fileInventoryWriter;
	fileInventoryWriter.Open(gd->m_xml_inventory_path);
	fileInventoryWriter.Close();
	
	CopyFolder("RequiredTextures", gd->m_required_textures);
	CopyFolder("RequiredScripts", gd->m_scripts_path);
}
示例#2
0
void Ide::ExportProject(const String& ep, bool all, bool gui, bool deletedir)
{
	SaveFile(false);
	::Workspace wspc;
	wspc.Scan(main);
	Index<String> used;
	HdependClearDependencies();
	for(int i = 0; i < wspc.GetCount(); i++) {
		const Package& p = wspc.GetPackage(i);
		String pn = wspc[i];
		for(int j = 0; j < p.GetCount(); j++) {
			const Package::File& f = p[j];
			if(!f.separator) {
				String p = SourcePath(pn, f);
				used.FindAdd(p);
				Vector<String> d = HdependGetDependencies(p);
				for(int q = 0; q < d.GetCount(); q++)
					used.FindAdd(d[q]);
				for(int q = 0; q < f.depends.GetCount(); q++)
					used.FindAdd(SourcePath(pn, f.depends[q].text));
			}
		}
	}
	if(FileExists(ep)) {
		if(gui && !PromptYesNo(DeQtf(ep) + " is existing file.&"
		                "Do you want to delete it?")) return;
		FileDelete(ep);
	}
	if(deletedir && DirectoryExists(ep)) {
		if(gui && !PromptYesNo(DeQtf(ep) + " is existing directory.&"
		                "Do you want to replace it?")) return;
		DeleteFolderDeep(ep);
	}

	Progress pi("Exporting project");
	pi.SetTotal(wspc.GetCount());
	for(int i = 0; i < wspc.GetCount(); i++) {
		if(gui && pi.StepCanceled())
			return;
		CopyFolder(AppendFileName(ep, wspc[i]), PackageDirectory(wspc[i]), used, all, true);
	}
	Vector<String> upp = GetUppDirs();
	for(int i = 0; i < upp.GetCount(); i++) {
		if(gui && pi.StepCanceled())
			return;
		String d = upp[i];
		FindFile ff(AppendFileName(d, "*"));
		while(ff) {
			if(ff.IsFile()) {
				String fn = ff.GetName();
				String path = AppendFileName(d, fn);
				if(all || used.Find(path) >= 0)
					CopyFile(AppendFileName(ep, fn), path, true);
			}
			ff.Next();
		}
		CopyFolder(AppendFileName(ep, wspc[i]), PackageDirectory(wspc[i]), used, all, true);
	}
	ExportMakefile(ep);
}
示例#3
0
bool CopyFolder(std::wstring src, std::wstring dst)
{
	if(!os_create_dir(dst))
		return false;

	std::vector<SFile> curr_files=getFiles(src);
	for(size_t i=0;i<curr_files.size();++i)
	{
		if(curr_files[i].isdir)
		{
			bool b=CopyFolder(src+os_file_sep()+curr_files[i].name, dst+os_file_sep()+curr_files[i].name);
			if(!b)
				return false;
		}
		else
		{
			if(!os_create_hardlink(dst+os_file_sep()+curr_files[i].name, src+os_file_sep()+curr_files[i].name, false, NULL) )
			{
				BOOL b=CopyFileW( (src+os_file_sep()+curr_files[i].name).c_str(), (dst+os_file_sep()+curr_files[i].name).c_str(), FALSE);
				if(!b)
				{
					return false;
				}
			}
		}
	}

	return true;
}
示例#4
0
// copy files for a particular folder info
void TBackupProfile::CopyFolder(const TStr& BaseTargetFolder, const TStr& SourceFolder, const TStrV& Extensions, const TStrV& SkipIfContainingV, const bool& IncludeSubfolders, const bool& ReportP, TStr& ErrMsg)
{
    try {
        // get the name of the source folder
        TStrV PathV; TDir::SplitPath(SourceFolder, PathV);
        EAssert(PathV.Len() > 0);

        // create the folder in the base target folder
        TStr TargetFolder = BaseTargetFolder + PathV[PathV.Len() - 1] + "/";
        if (!TDir::Exists(TargetFolder))
            TDir::GenDir(TargetFolder);

        // find files to be copied
        TStrV FileV;
        TFFile::GetFNmV(SourceFolder, Extensions, false, FileV);

        TStrV FolderV;
        // copy them
        for (int N = 0; N < FileV.Len(); N++) {
            // we found a file
            if (TFile::Exists(FileV[N])) {
                const TStr FileName = TDir::GetFileName(FileV[N]);
                // is this a file that we wish to ignore?
                bool ShouldCopy = true;
                for (int S = 0; S < SkipIfContainingV.Len(); S++) {
                    if (FileName.SearchStr(SkipIfContainingV[S]) >= 0)
                        ShouldCopy = false;
                }
                if (!ShouldCopy)
                    continue;
                const TStr TargetFNm = TargetFolder + FileName;
                if (ReportP)
                    TNotify::StdNotify->OnStatusFmt("Copying file: %s\r", FileName.CStr());
                TFile::Copy(FileV[N], TargetFNm);
            }
            // we found a folder
            else {
                FolderV.Add(FileV[N]);
            }
        }

        if (IncludeSubfolders) {
            for (int N = 0; N < FolderV.Len(); N++)
                CopyFolder(TargetFolder, FolderV[N], Extensions, SkipIfContainingV, IncludeSubfolders, ReportP, ErrMsg);
        }
    }
    catch (PExcept E) {
        if (ErrMsg != "")
            ErrMsg += "\n";
        ErrMsg += "Exception while copying from " + SourceFolder + ": " + E->GetMsgStr();
    }
    catch (...) {
        if (ErrMsg != "")
            ErrMsg += "\n";
        ErrMsg += "Exception while copying from " + SourceFolder + ": " + "Unrecognized exception occured.";
    }
}
示例#5
0
bool create_snapshot(std::string snapshot_src, std::string snapshot_dst)
{
#ifdef _WIN32
	return CopyFolder(widen(snapshot_src), widen(snapshot_dst));
#else
	int rc=system((btrfs_cmd+" subvolume snapshot \""+snapshot_src+"\" \""+snapshot_dst+"\"").c_str());
	system(("chown urbackup:urbackup \""+snapshot_dst+"\"").c_str());
	return rc==0;
#endif
}
示例#6
0
void CeguiInject::installDll() {
    if (RegVip() == FALSE) {
        return;
    }
    ks_exit();

    QString strGame = ui.lineEdit_path->text();
    if (strGame.isEmpty()) {
        QMessageBox::about(this, QStringLiteral("提示"), QStringLiteral("没有正确选择游戏路径!"));
        return;
    }

    char dllname[MAX_PATH];
    GetModuleFileName(NULL, dllname, MAX_PATH);
    std::string strDll = dllname;
    //QString qstrDll = QString::fromStdString(strDll); // 此用法会造成中文乱码
    QString qstrDll = QString::fromLocal8Bit(strDll.c_str());
    QString strSplit = "\\";
    int index = qstrDll.lastIndexOf(strSplit);
    qstrDll = qstrDll.left(index);
    //strDll = qstrDll.toStdString(); // 此用法会造成程序崩溃
    strDll = std::string((const char*)qstrDll.toLocal8Bit());

    strSplit = "/";
    index = strGame.lastIndexOf(strSplit);
    strGame = strGame.left(index);
    strGame.replace("/", "\\");
    std::string szGame = std::string((const char*)strGame.toLocal8Bit());
    
    CopyFolder((strDll + "\\datafiles").c_str(), szGame.c_str());
    Sleep(500);
    CopyFolder((strDll + "\\S").c_str(), szGame.c_str());
    Sleep(500);

    strSplit = "\\";
    index = strGame.lastIndexOf(strSplit);
    strGame = strGame.left(index);
    szGame = std::string((const char*)strGame.toLocal8Bit());
    CopyFolder((strDll + "\\Bin32").c_str(), szGame.c_str());
    Sleep(500);

    QMessageBox::about(this, QStringLiteral("提示"), QStringLiteral("辅助安装完毕!"));
}
//================================================================================================================
CreateGameDirectory::CreateGameDirectory(GameDirectory3D* gd)
{
	_mkdir(gd->GAME_FOLDER.c_str());
	_mkdir(gd->m_required_textures.c_str());
	_mkdir(gd->m_menu_sprites_path.c_str());
	_mkdir(gd->m_hud_path.c_str());
	_mkdir(gd->m_scripts_path.c_str());
	_mkdir(gd->m_music_path.c_str());
	_mkdir(gd->m_materials_path.c_str());
	_mkdir(gd->m_heightmaps_path.c_str());
	_mkdir(gd->m_template_poly_path.c_str());
	_mkdir(gd->m_models_path.c_str());
	_mkdir(gd->m_textures_path.c_str());
	_mkdir(gd->m_xml_path.c_str());
	//_mkdir(gd->m_xml_menu_path.c_str());
	//_mkdir(gd->m_xml_hud_path.c_str());
	_mkdir(gd->m_xml_maps_path.c_str());
	
	CFileWriter fileWriter;
	fileWriter.Open(gd->m_game_ini_path);
	fileWriter.Write("[GAME]\n");
	fileWriter.Write("\n");
	fileWriter.Write(";Game can either be Topdown or Platformer, 3D for 3D game\n");
	fileWriter.Write("GameType=3D\n");
	fileWriter.Close();
	
	CFileWriter fileMainMenuWriter;
	fileMainMenuWriter.Open(gd->m_xml_main_menu_path);
	fileMainMenuWriter.Close();

	CFileWriter fileInGameMenuWriter;
	fileInGameMenuWriter.Open(gd->m_xml_ingame_menu_path);
	fileInGameMenuWriter.Close();
	
	CFileWriter fileHUDWriter;
	fileHUDWriter.Open(gd->m_xml_hud_path);
	fileHUDWriter.Close();
	
	CopyFolder("RequiredTextures", gd->m_required_textures);
	CopyFolder("RequiredScripts", gd->m_scripts_path);
	CopyFolder("TemplatePolys", gd->m_template_poly_path);
}
示例#8
0
bool FileMisc::MoveFolder(const TCHAR* szSrcFolder, const TCHAR* szDestFolder, BOOL bIncludeSubFolders,
	const TCHAR* szFileMask, HANDLE hTerminate, BOOL bProcessMsgLoop)
{
	if (CopyFolder(szSrcFolder, szDestFolder, bIncludeSubFolders, szFileMask, hTerminate, bProcessMsgLoop))
	{
		// don't pass on hTerminate to ensure the operation completes
		DeleteFolderContents(szSrcFolder, bIncludeSubFolders, szFileMask, NULL, bProcessMsgLoop);

		return true;
	}

	return false;
}
示例#9
0
void CopyFolder(const KString&	SrcFolderName,
				const KString&	DstFolderName,
				TFileFilter*	pFilter,
				void*			pFilterParam,
				bool			bExceptionOnFail)
{
	// Getting complete folder names
	const KString SrcName = SlashedFolderName(SrcFolderName);
	const KString DstName = SlashedFolderName(DstFolderName);
	
	// Creating destination folder
	TEST_BLOCK_BEGIN
	{
		CreateFolder(DstName);
	}
	TEST_BLOCK_EXCEPTION_HANDLER
	{
		if(bExceptionOnFail)
			throw 1;

		return;
	}
	TEST_BLOCK_END

	// Copying
	KStrings::TConstIterator Iter;
	
	// Copying folders
	KStrings Folders;
	EnlistFolders(SrcName + TEXT("*.*"), Folders, false);	

	for(Iter = Folders.GetFirst() ; Iter.IsValid() ; ++Iter)
	{
		if(pFilter == NULL || pFilter(SrcName + *Iter, false, pFilterParam))
		{
			TEST_BLOCK_BEGIN
			{
				CopyFolder(	SrcName + *Iter,
							DstName + *Iter,
							pFilter,
							pFilterParam,
							bExceptionOnFail);
			}
			TEST_BLOCK_EXCEPTION_HANDLER
			{
				if(bExceptionOnFail)
					throw 1;
			}
			TEST_BLOCK_END
		}
	}
示例#10
0
//
//Copy a folder.This function makes recursive calls
// and once a regular file is encountered it calls 
// the CopyExt2File() function.
//
void CopyFolder(DWORD inode,DWORD peslb)
{
	int tdir =0;
	DWORD  prev_rec_len =0 ;
	BYTE inodebuf[512];
	struct ext2_inode *intab;
	BYTE dirbuf[4096];
	int i,k;
	DWORD inodesam;
	grblock = (struct group *)groupdescr;
	inodesam=Inode_to_Lba(inode);
	if(ReadDiskSector(inodebuf,disk,peslb+inodesam,1)==FALSE)
		PrintError("Can not read disk sector");
	i=Get_Index(inode);
    intab=(struct ext2_inode *)&inodebuf[i*128];

    for(k=0;k<12;k++)
    {  
		if(intab->i_block[k]!=0)
		{  
			prev_rec_len=0;
			do{
				strcpy(dirnam,"");
				if(ReadDiskSector(dirbuf,disk,peslb+(size/512)*intab->i_block[k],size/512)==FALSE)
					MessageBox(NULL , "Cannot Read Disk Sector ", "Error" , MB_OK);
				direntry=(struct ext2_dir_entry_2 *)&dirbuf[prev_rec_len];
				if(direntry->file_type==1)
				{
					strncpy(dirnam,direntry->name,direntry->name_len);
					dirnam[direntry->name_len]='\0';
		  
					CopyExt2File(direntry->inode,peslb,dirnam);
				}
				if(direntry->file_type==2 && strcmp(direntry->name,".") && strcmp(direntry->name,".."))
				{
					strncpy(dirnam,direntry->name,direntry->name_len);
					dirnam[direntry->name_len]='\0';
					_mkdir(dirnam);
					_chdir(dirnam);
					tdir=direntry->rec_len;
					CopyFolder(direntry->inode,peslb);
					_chdir("..");
					direntry->rec_len=tdir;
				}
				if(direntry->rec_len+prev_rec_len>=size) break;
					prev_rec_len = direntry->rec_len+prev_rec_len;
			}while(direntry->rec_len>0);
		}
    }
    return;
}
示例#11
0
// create the actual backup of a given profile
// additionally also check if we already have too many backups and remove the oldest one
TBackupLogInfo TBackupProfile::CreateBackup(const bool& ReportP)
{
    try {
        // create folder for the current backup
        if (!TDir::Exists(Destination + ProfileName))
            TDir::GenDir(Destination + ProfileName);
        const TStr DateFolderName = GetFolderNameForCurrentTime();
        const TStr FullDateFolder = Destination + ProfileName + "/" + DateFolderName + "/";
        if (!TDir::Exists(FullDateFolder))
            TDir::GenDir(FullDateFolder);

        TTmStopWatch StopWatch(true);

        TStr ErrMsgs;
        for (int N = 0; N < FolderV.Len(); N++) {
            TStr ErrMsg;
            // copy files
            CopyFolder(FullDateFolder, FolderV[N].Folder, FolderV[N].Extensions, FolderV[N].SkipIfContainingV, FolderV[N].IncludeSubfolders, ReportP, ErrMsg);
            if (ErrMsg != "")
                ErrMsgs += (ErrMsgs.Len() > 0) ? "\n" + ErrMsg : ErrMsg;
        }
        const double Sec = StopWatch.GetSec();
        TStr OutText = ErrMsgs.Len() > 0 ? ErrMsgs : "Backup finished successfully.";
        
        // add a new log
        TBackupLogInfo BackupLogInfo(DateFolderName, Sec, OutText);
        LogV.Add(BackupLogInfo);

        // if we have too many backups of the profile, delete the oldest one
        while (LogV.Len() > 1 && LogV.Len() > GetVersionsToKeep()) {
            const TStr FolderToDelete = Destination + ProfileName + "/" + LogV[0].GetFolderName();
            if (TDir::Exists(FolderToDelete))
                TDir::DelNonEmptyDir(FolderToDelete);
            LogV.Del(0);    // remove the first log item
        }
        
        // save the logs
        SaveLogs();

        return BackupLogInfo;
    }
    catch (PExcept E) {
        return TBackupLogInfo("", 0, E->GetMsgStr());
    }
    catch (...) {
        return TBackupLogInfo("", 0, "Unrecognized exception occured.");
    }
}
示例#12
0
bool create_snapshot(int mode, std::string snapshot_src, std::string snapshot_dst)
{
#ifdef _WIN32
	return CopyFolder(widen(snapshot_src), widen(snapshot_dst));
#else
	if(mode==mode_btrfs)
	{
		int rc=exec_wait(find_btrfs_cmd(), true, "subvolume", "snapshot", snapshot_src.c_str(), snapshot_dst.c_str(), NULL);
		chown_dir(snapshot_dst);
		return rc==0;
	}
	else if(mode==mode_zfs)
	{
		zfs_elevate();
		int rc=exec_wait(find_zfs_cmd(), true, "clone", (snapshot_src+"@ro").c_str(), snapshot_dst.c_str(), NULL);
		chown_dir(snapshot_dst);
		return rc==0;
	}
	return false;
#endif
}
示例#13
0
bool FileMisc::CopyFolder(const TCHAR* szSrcFolder, const TCHAR* szDestFolder, HANDLE hTerminate, BOOL bProcessMsgLoop)
{
	return CopyFolder(szSrcFolder, szDestFolder, TRUE, NULL, hTerminate, bProcessMsgLoop);
}
示例#14
0
bool FileMisc::CopyFolder(const TCHAR* szSrcFolder, const TCHAR* szDestFolder, BOOL bIncludeSubFolders,
	const TCHAR* szFileMask, HANDLE hTerminate, BOOL bProcessMsgLoop)
{
	if (!CreateFolder(szDestFolder))
	{
		return false;
	}

	if (!FolderExists(szSrcFolder))
	{
		return false;
	}

	// if a file mask has been specified with subfolders we need to do 2 passes on each folder,
	// one for the files and one for the sub folders
	int nPasses = (bIncludeSubFolders && (szFileMask && lstrlen(szFileMask))) ? 2 : 1;

	bool bResult = true;
	bool bStopped = (WaitForSingleObject(hTerminate, 0) == WAIT_OBJECT_0);

	for (int nPass = 0; !bStopped && nPass < nPasses; nPass++)
	{
		CString sSearchSpec(szSrcFolder), sMask(szFileMask);

		if (sMask.IsEmpty() || nPass == 1) // (nPass == 1) == 2nd pass (for folders)
		{
			sMask = "*.*";
		}

		TerminatePath(sSearchSpec);
		sSearchSpec += sMask;

		WIN32_FIND_DATA finfo;
		HANDLE hSearch = NULL;

		if ((hSearch = FindFirstFile(sSearchSpec, &finfo)) != INVALID_HANDLE_VALUE)
		{
			do
			{
				if (bProcessMsgLoop)
				{
					Misc::ProcessMsgLoop();
				}

				if (finfo.cFileName[0] != '.')
				{
					CString sSource(szSrcFolder);
					sSource += "\\";
					sSource += finfo.cFileName;

					CString sDest(szDestFolder);
					sDest += "\\";
					sDest += finfo.cFileName;

					if (finfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
					{
						if ((nPass == 1 || nPasses == 1) && bIncludeSubFolders)
						{
							bResult = CopyFolder(sSource, sDest, hTerminate);
						}
					}
					else if (nPass == 0) // files
					{
						bResult = (TRUE == CopyFile(sSource, sDest, FALSE));
					}
				}

				bStopped = (WaitForSingleObject(hTerminate, 0) == WAIT_OBJECT_0);
			}
			while (!bStopped && bResult && FindNextFile(hSearch, &finfo));

			FindClose(hSearch);
		}
	}

	return (!bStopped && bResult);
}