/* * private void UploadActionTable() * { * if (MessageConfirm("上傳所有動作到機械人, 機械人內所有動作將會被覆蓋. 建議分開動作獨立上傳.")) * { * if (UBT.UploadActionTable()) * { * UpdateInfo("上傳資料完成"); * } * } * * } */ private void ConvertAction() { UpdateInfo(); int actionId = GetSelectedActionId(); if (actionId < 0) { return; } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "aesx or hts files|*.aesx;*.hts|aesx file (*.aesx)|*.aesx|hts file (*.hts)|*.hts"; if (openFileDialog.ShowDialog() == true) { String fileName = openFileDialog.FileName.Trim(); String lName = fileName.ToLower(); CONST.UBT_FILE fileType = CONST.UBT_FILE.UNKNOWN; if (lName.EndsWith(".aesx")) { fileType = CONST.UBT_FILE.AESX; } if (lName.EndsWith(".hts")) { fileType = CONST.UBT_FILE.HTS; } if (fileType == CONST.UBT_FILE.UNKNOWN) { UpdateInfo(String.Format("Invalid file extension {0}", fileName), UTIL.InfoType.error); return; } char actionCode = UBT.actionTable.action[actionId].actionCode; if (MessageConfirm(String.Format("把 UBTech 檔 {0} 的動作檔截入動作 {1} 中, 當前資料將會被覆蓋", fileName, actionCode))) { try { long size = new FileInfo(fileName).Length; FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read); BinaryReader br = new BinaryReader(fs); byte[] actionData = null; // File size should not be over 2M, so not need to handle overflow) actionData = br.ReadBytes((int)size); br.Close(); fs.Close(); string actionName = openFileDialog.SafeFileName; actionName = actionName.Substring(0, actionName.IndexOf('.')); if (UBT.actionTable.ReadFromUBTechFile(actionData, actionId, actionName, fileType)) { UpdateInfo(String.Format("Rebuild action table from {0}", fileName)); } else { UpdateInfo(String.Format("Error building action from {0}", fileName), UTIL.InfoType.error); } } catch (Exception ex) { UpdateInfo(String.Format("Error reading data from {0}: {1}", fileName, ex.Message), UTIL.InfoType.error); } RefreshActionInfo(); } } }
public bool ReadFromUBTechFile(byte[] actionData, int actionId, string actionName, CONST.UBT_FILE fileType) { if ((actionId < 0) || (actionId > CONST.AI.MAX_ACTION)) { return(false); } bool success = false; switch (fileType) { case CONST.UBT_FILE.AESX: if (actionData.Length < CONST.AESX_FILE.MIN_SIZE) { return(false); } success = action[actionId].ReadFromAESX(actionData, actionId, actionName); break; case CONST.UBT_FILE.HTS: if (actionData.Length < CONST.HTS_FILE.MIN_SIZE) { return(false); } success = action[actionId].ReadFromHTS(actionData, actionId, actionName); break; } return(success); }