// convert_between_ENG_CHS.js
// Author: ddid
// Date: 2009-08-11
// Purpose: Convert display language between Simpilied Chinse and English for Zmud.
// Script Language = JScript
// Q: How to run it? A: wscript convert_between_ENG_CHS.js


/**** 声明对象 ****/

var WshShell = WScript.CreateObject("WScript.Shell");
var fso = new ActiveXObject("Scripting.FileSystemObject");

/**** 声明全局变量 ****/

var	ENG_mud_file = "global.mud.en",	CHS_mud_file = "global.mud.cn",	CHS_lng_file = "zmud.lng.cn";
var	current_mud_file = "global.mud", current_lng_file = "zmud.lng";
// var original_ENG_lng_file = "zmud_english.lng";


/**** 判断运行条件，并根据条件执行转换 ****/

if ( !fso.FileExists(current_mud_file) || !fso.FileExists(CHS_mud_file) || !fso.FileExists(CHS_lng_file) )
	{
		WScript.Echo("语言转换文件不全，不能进行转换。");
	}
	
else
	{
		if ( fso.FileExists(current_lng_file) )
			{
				var oFile = fso.OpenTextFile(current_lng_file, 1);
				var lng_first_line = oFile.ReadLine();
				oFile.close();
	
				if ( lng_first_line == "; ZMUD.LNG.CN" && fso.FileExists(ENG_mud_file) )
					{
						var BtnCode = WshShell.Popup("ZMUD当前是简体中文版，是否要将其转换为英文版？", 0, "提示问题：", 3 + 32);
		
						switch(BtnCode) 
							{
   							case 2:
      						break;
   							case 6:
      						convert_from_CHS_to_ENG();
      						break;
   							case 7:
  		 		  			break;
    	  			}	
					}
					
				else
					{
						WScript.Echo("不能确定当前ZMUD的语言版本，建议重新安装ZMUD英文版及语言转换文件。");
					}
					
			}	
	
		else
			{
				var BtnCode = WshShell.Popup("ZMUD当前是英文版，是否要将其转换为简体中文版？", 0, "提示问题：", 3 + 32);

				switch(BtnCode) 
					{
   					case 2:
      				break;
   					case 6:
      				convert_from_ENG_to_CHS();
      				break;
   					case 7:
  	 		  		break;
      		}	
			}
	}		

/**** 释放对象 ****/

WshShell = null;
fso = null;


/**** 以下function完成 Simplified Chinese --> English 转换 ****/

function convert_from_CHS_to_ENG()
{
	fso.CopyFile (current_mud_file, CHS_mud_file, 1);
	fso.CopyFile (ENG_mud_file, current_mud_file, 1);

	fso.DeleteFile (current_lng_file);

	WScript.Echo("转换完毕！ZMUD当前为英文版（需要再次启动ZMUD）。");
}


/**** 以下function完成 English --> Simplified Chinese 转换 ****/

function convert_from_ENG_to_CHS()
{
	fso.CopyFile (current_mud_file, ENG_mud_file, 1);
	fso.CopyFile (CHS_mud_file, current_mud_file, 1);
	
	fso.CopyFile (CHS_lng_file, current_lng_file, 1);

	WScript.Echo("转换完毕！ZMUD当前为简体中文版（需要再次启动ZMUD）。");
}
