示例#1
0
void string_to_file(std::string str, char* fname)
{
	posix_file_t	fp;
	uint32_t		bytertd;

    posix_fopen(fname, GENERIC_WRITE, CREATE_ALWAYS, fp);
	if (fp == INVALID_FILE) {
		posix_print_mb("string_to_file, cann't create file %s for write", fname);
		return;
	}
	posix_fwrite(fp, str.c_str(), str.length(), bytertd);
	posix_fclose(fp);
	return;
}
示例#2
0
static BOOL cb_walk_campaign(char* name, uint32_t flags, uint64_t len, int64_t lastWriteTime, uint32_t* ctx)
{
	char text1[_MAX_PATH], text2[_MAX_PATH];
	BOOL fok;
	walk_campaign_param_t* wcp = (walk_campaign_param_t*)ctx;

	if (flags & FILE_ATTRIBUTE_DIRECTORY ) {
		sprintf(text2, "%s\\%s", wcp->ins_campaign_dir.c_str(), name);
		MakeDirectory(std::string(text2)); // !!不要在<data>/campaigns/{campaign}下建images目录
		sprintf(text1, "%s\\%s\\images", wcp->src_campaign_dir.c_str(), name);
		sprintf(text2, "%s\\%s\\images", wcp->ins_campaign_dir.c_str(), name);
		if (is_directory(text1)) {
			posix_print("<data>, copy %s to %s ......\n", text1, text2);
			fok = copyfile(text1, text2);
			if (!fok) {
				posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
				return FALSE;
			}
		}
	}
	return TRUE;
}
示例#3
0
BOOL copy_root_files(char* src, char* dst)
{
	char				szCurrDir[_MAX_PATH], text1[_MAX_PATH], text2[_MAX_PATH];
	HANDLE				hFind;
	WIN32_FIND_DATA		finddata;
	BOOL				fok, fret = TRUE;
	
	if (!src || !src[0] || !dst || !dst[0]) {
		return FALSE;
	}
		
	GetCurrentDirectory(_MAX_PATH, szCurrDir);
	SetCurrentDirectory(appendbackslash(src));
	hFind = FindFirstFile("*.*", &finddata);
	fok = (hFind != INVALID_HANDLE_VALUE);

	while (fok) {
		if (finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
			// 目录
		} else {
			// 文件
			sprintf(text1, "%s\\%s", src, finddata.cFileName);
			sprintf(text2, "%s\\%s", dst, finddata.cFileName);
			fret = CopyFile(text1, text2, FALSE);
			if (!fret) {
				posix_print_mb("copy file from %s to %s fail", text1, text2);
				break;
			}
		}
		fok = FindNextFile(hFind, &finddata);
	}
	if (hFind != INVALID_HANDLE_VALUE) {
		FindClose(hFind);
	}

	SetCurrentDirectory(szCurrDir);
	return fret;
}
示例#4
0
BOOL extra_kingdom_ins_disk(char* kingdom_src, char* kingdom_ins, char* kingdom_ins_android)
{
	char text1[_MAX_PATH], text2[_MAX_PATH];
	BOOL fok;
	walk_campaign_param_t wcp;

	MakeDirectory(std::string(kingdom_ins));

	// 清空目录
	fok = delfile1(kingdom_ins);
	if (!fok) {
		posix_print_mb("删除目录: %s,失败", kingdom_ins);
		return fok;
	}
	fok = delfile1(kingdom_ins_android);
	if (!fok) {
		posix_print_mb("删除目录: %s,失败", kingdom_ins_android);
		// return fok;
	}

	//
	// <kingdom-src>\data
	//

	// 1. images in all campaigns
	wcp.src_campaign_dir = std::string(kingdom_src) + "\\data\\campaigns";
	wcp.ins_campaign_dir = std::string(kingdom_ins) + "\\data\\campaigns";
	fok = walk_dir_win32_deepen(wcp.src_campaign_dir.c_str(), 0, cb_walk_campaign, (uint32_t *)&wcp);
	if (!fok) {
		return fok;
	}
	wcp.ins_campaign_dir = std::string(kingdom_ins_android) + "\\data\\campaigns";
	fok = walk_dir_win32_deepen(wcp.src_campaign_dir.c_str(), 0, cb_walk_campaign, (uint32_t *)&wcp);
	if (!fok) {
		return fok;
	}

	// 2. images in <data>\core root
	MakeDirectory(std::string("") + kingdom_ins + "\\data\\core");
	sprintf(text1, "%s\\data\\core\\images", kingdom_src);
	sprintf(text2, "%s\\data\\core\\images", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	MakeDirectory(std::string("") + kingdom_ins_android + "\\data\\core");
	sprintf(text2, "%s\\data\\core\\images", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// 3. music in <data>\core root
	sprintf(text1, "%s\\data\\core\\music", kingdom_src);
	sprintf(text2, "%s\\data\\core\\music", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\data\\core\\music", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// 4. sounds in <data>\core root
	sprintf(text1, "%s\\data\\core\\sounds", kingdom_src);
	sprintf(text2, "%s\\data\\core\\sounds", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\data\\core\\sounds", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}

	sprintf(text1, "%s\\data\\hardwired", kingdom_src);
	sprintf(text2, "%s\\data\\hardwired", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\data\\hardwired", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}

	sprintf(text1, "%s\\data\\lua", kingdom_src);
	sprintf(text2, "%s\\data\\lua", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\data\\lua", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}

	sprintf(text1, "%s\\data\\tools", kingdom_src);
	sprintf(text2, "%s\\data\\tools", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\data\\tools", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// <kingdom-src>\data\_main_cfg
	sprintf(text1, "%s\\data\\_main.cfg", kingdom_src);
	sprintf(text2, "%s\\data\\_main.cfg", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制文件,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\data\\_main.cfg", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制文件,从%s到%s,失败", text1, text2);
		goto exit;
	}
	//
	// <kingdom-src>\fonts
	//
	sprintf(text1, "%s\\fonts", kingdom_src);
	sprintf(text2, "%s\\fonts", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\fonts", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	//
	// <kingdom-src>\images
	//
	sprintf(text1, "%s\\images", kingdom_src);
	sprintf(text2, "%s\\images", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\images", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	//
	// <kingdom-src>\manual
	//
	sprintf(text1, "%s\\manual", kingdom_src);
	sprintf(text2, "%s\\manual", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// andorid don't copy manual

	//
	// <kingdom-src>\sounds
	//
	sprintf(text1, "%s\\sounds", kingdom_src);
	sprintf(text2, "%s\\sounds", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\sounds", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	//
	// <kingdom-src>\translations
	//
	sprintf(text1, "%s\\translations", kingdom_src);
	sprintf(text2, "%s\\translations", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\translations", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	//
	// <kingdom-src>\xwml
	//
	sprintf(text1, "%s\\xwml", kingdom_src);
	sprintf(text2, "%s\\xwml", kingdom_ins);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}
	// android
	sprintf(text2, "%s\\xwml", kingdom_ins_android);
	posix_print("<data>, copy %s to %s ......\n", text1, text2);
	fok = copyfile(text1, text2);
	if (!fok) {
		posix_print_mb("复制目录,从%s到%s,失败", text1, text2);
		goto exit;
	}

	fok = copy_root_files(kingdom_src, kingdom_ins);
exit:
	if (!fok) {
		delfile1(kingdom_ins);
	}

	return fok;
}
示例#5
0
void On_DlgDDescCommand(HWND hdlgP, int id, HWND hwndCtrl, UINT codeNotify)
{
	char *ptr = NULL;
	int retval;
	char text[_MAX_PATH];
	BOOL fok;
	std::string str;
	std::stringstream strstr;
	
	switch (id) {
	case IDC_BT_DDESC_BROWSE:
		ptr = GetBrowseFilePath(hdlgP);
		if (!ptr) {
			break;
		}
		strcpy(text, appendbackslash(ptr));
		if (text[strlen(text) - 1] == '\\') {
			text[strlen(text) - 1] = 0;
		}
		if (!check_wok_root_folder(text)) {
			posix_print_mb("%s,不是有效的kingdom-src-x.x.x源数据目录,请重新选择", appendbackslash(text));
			break;
		}
		if (strcasecmp(ptr, game_config::path.c_str())) {
			game_config::path = ptr;
			gdmgr.heros_.set_path(game_config::path.c_str());
			Edit_SetText(GetDlgItem(hdlgP, IDC_ET_DDESC_WWWROOT), appendbackslash(ptr));
			OnLSBt(TRUE);
			if (gdmgr._da != da_sync) {
				title_select(da_sync);
			} else {
				sync_enter_ui();
			}
			update_locale_dir();
		}
		break;

	case IDM_NEW_EXTRAINSDIST:
		sprintf(text, "Do you want to extract install-material to C:\\kingdom-ins?"); 
		retval = MessageBox(hdlgP, text, "Confirm Generate", MB_YESNO | MB_DEFBUTTON2);
		if (retval == IDYES) {
			fok = extra_kingdom_ins_disk(gdmgr._menu_text, "c:\\kingdom-ins", "c:\\kingdom-ins-android\\com.freeors.kingdom");
			posix_print_mb("Extract install-material from %s to C:\\kingdom-ins, %s!!", gdmgr._menu_text, fok? "Success": "Fail");
		}
		break;

	case IDM_NEW_CAMPAIGN:
		if (campaign_new()) {
			// title_select(da_sync);
		}
		break;

	case IDM_EXPLORER_WML:
		if (!_stricmp(gdmgr._menu_text, "hero.dat")) {
			if (gdmgr._da != da_wgen) {
				title_select(da_wgen);
			} else {
				wgen_enter_ui();
			}
		} else if (!_stricmp(gdmgr._menu_text, "tb.dat")) {
			editor_config::type = BIN_BUILDINGRULE;
			if (gdmgr._da != da_visual) {
				title_select(da_visual);
			} else {
				visual_enter_ui();
			}
		} else if (!_stricmp(extname(gdmgr._menu_text), "bin")) {
			if (wml_checksum_from_file(std::string(gdmgr._menu_text))) {
				editor_config::type = BIN_WML;
				if (gdmgr._da != da_visual) {
					title_select(da_visual);
				} else {
					visual_enter_ui();
				}
			}
		}
		break;

	case IDM_DELETE_ITEM0:
		// 册除指定的文件/目录
		strstr.str("");
		str = gdmgr._menu_text;
		strstr << str.substr(0, str.rfind("\\xwml"));
		strstr << "\\data\\campaigns\\" << offextname(basename(gdmgr._menu_text));
		strcpy(text, strstr.str().c_str());

		strstr.str("");
		strstr << "您想删除文件:" << gdmgr._menu_text << ",以及目录:";
		strstr << text << "?";

		// Confirm Multiple File Delete 
		retval = MessageBox(hdlgP, strstr.str().c_str(), "确认删除", MB_YESNO | MB_DEFBUTTON2);
		if (retval == IDYES) {
			if (delfile1(gdmgr._menu_text)) {
                TreeView_DeleteItem(GetDlgItem(hdlgP, IDC_TV_DDESC_EXPLORER), (HTREEITEM)(UINT_PTR)gdmgr._menu_lparam);
				TreeView_SetChilerenByPath(GetDlgItem(hdlgP, IDC_TV_DDESC_EXPLORER), (HTREEITEM)(UINT_PTR)gdmgr._menu_lparam, dirname(gdmgr._menu_text)); 
			} else {
				posix_print_mb("Failed delete %s !", gdmgr._menu_text); 
			}
			if (!delfile1(text)) {
                posix_print_mb("Failed delete %s !", text); 
			}
			sync_refresh_sync();
		}

		break;

	case IDM_DELETE_ITEM1:
		strstr.str("");
		strstr << "将产生不同步,您想删除文件:" << gdmgr._menu_text << "?";
		// Confirm Multiple File Delete 
		retval = MessageBox(hdlgP, strstr.str().c_str(), "确认删除", MB_YESNO | MB_DEFBUTTON2);
		if (retval == IDYES) {
			if (delfile1(gdmgr._menu_text)) {
                TreeView_DeleteItem(GetDlgItem(hdlgP, IDC_TV_DDESC_EXPLORER), (HTREEITEM)(UINT_PTR)gdmgr._menu_lparam);
				TreeView_SetChilerenByPath(GetDlgItem(hdlgP, IDC_TV_DDESC_EXPLORER), (HTREEITEM)(UINT_PTR)gdmgr._menu_lparam, dirname(gdmgr._menu_text)); 
			} else {
				posix_print_mb("Failed delete %s !", gdmgr._menu_text); 
			}
			// inform user, there is non sync.
			if (gdmgr._da != da_sync) {
				title_select(da_sync);
			} else {
				// forbid refresh
				sync_enter_ui();
			}
		}
		break;

	default:
		break;
	}
	return;
}