public static void GenUpdateXmlByVersion(BuildTarget target, string strNewVersion, List <string> strOldVersion) { string platformPath = PlatformMap.GetPlatformPath(target) + "/"; Dictionary <string, Dictionary <string, string> > strOldVersionInfo = new Dictionary <string, Dictionary <string, string> >(); foreach (string str in strOldVersion) { string strFilePath = platformPath + str + "/" + CreateMD5List.strFileName; Dictionary <string, string> dicOldMD5Info = ReadMD5File(strFilePath); if (!File.Exists(strFilePath)) { EditorUtility.DisplayDialog("Error", "Version File lost", "OK"); return; } strOldVersionInfo.Add(str, dicOldMD5Info); } string newVerXmlPath = platformPath + strNewVersion + "/" + CreateMD5List.strFileName; Dictionary <string, string> dicNewMD5Info = ReadMD5File(newVerXmlPath); // v File Info DataStruct Dictionary <string, string> vFileInfoDict = new Dictionary <string, string>(); string strVersionXml = platformPath + strVFile; // Compare MD5 Generate UpdateXml foreach (KeyValuePair <string, Dictionary <string, string> > oldVer in strOldVersionInfo) { string strUpdateXmlTmp = string.Format(strUpdateXml, oldVer.Key, strNewVersion) + ".xml"; XmlDocument xmlDoc = new XmlDocument(); XmlElement xmlRoot = xmlDoc.CreateElement(strUpdateRoot); xmlDoc.AppendChild(xmlRoot); foreach (KeyValuePair <string, string> NewFileList in dicNewMD5Info) { //old File Find string strMD5 = ""; XmlElement item = null; if (oldVer.Value.TryGetValue(NewFileList.Key, out strMD5)) { if (strMD5 != NewFileList.Value) { item = xmlDoc.CreateElement(strUpdateElement); item.SetAttribute(strUpdateElementNameAttr, NewFileList.Key.Replace('\\', '/')); item.SetAttribute(strUpdateElementHashAttr, NewFileList.Value); } } else { item = xmlDoc.CreateElement(strUpdateElement); item.SetAttribute(strUpdateElementNameAttr, NewFileList.Key.Replace('\\', '/')); item.SetAttribute(strUpdateElementHashAttr, NewFileList.Value); } if (item == null) { continue; } xmlRoot.AppendChild(item); } xmlRoot.SetAttribute(strUpdateFileNumAttr, xmlRoot.ChildNodes.Count.ToString()); xmlDoc.Save(platformPath + strUpdateXmlTmp); string strZip = string.Format(strUpdateXml, oldVer.Key, strNewVersion) + ".zip"; CompressForFile.CompressFile(platformPath + strUpdateXmlTmp, platformPath + strZip); vFileInfoDict.Add(oldVer.Key, strZip); xmlDoc = null; } //update v.xml SaveVFile(strNewVersion, vFileInfoDict, strOldVersionInfo.Count, strVersionXml + ".xml"); CompressForFile.CompressFile(strVersionXml + ".xml", strVersionXml + ".zip"); }
void OnWizardCreate() { string strTarget = System.Enum.GetName(typeof(BuildTarget), Target); if (strTarget == null || strTarget == "") { CreateWizard(); return; } if (FileDirectory == null) { EditorUtility.DisplayDialog("Error", "SceneDirectory Is Empty", "QUIT"); CreateWizard(); return; } try { List <string> filelist = null; if (IgnoreFile != null && IgnoreFile.Length != 0) { filelist = new List <string>(); foreach (string str in IgnoreFile) { filelist.Add(str); } } List <string> strCompress = new List <string>(); if (bEntrypt) { if (!EncryptXOR.EncryptResource(Target, filelist, FileDirectory, strExt, ref strCompress)) { CreateWizard(); return; } } else { string SavePath = PlatformMap.GetPlatformPath(Target) + "/" + VersionManager.GetCurVersion(Target) + "/"; string SelectPath = AssetDatabase.GetAssetPath(FileDirectory); foreach (string st in strExt) { string [] files = System.IO.Directory.GetFiles(SelectPath, st, System.IO.SearchOption.AllDirectories); foreach (string stPush in files) { if (!strCompress.Contains(stPush)) { strCompress.Add(stPush); } } } } //if encrypted delete original file CompressForFile.CompressScript(Target, filelist, strCompress, bEntrypt); //write force updated string ForceTxtSavePath = ""; try { ForceTxtSavePath = PlatformMap.GetPlatformPath(Target) + "/" + VersionManager.GetCurVersion(Target) + "/"; } catch (IOException exp) { EditorUtility.DisplayDialog("Error", exp.Message, "OK"); return; } FileStream fsForce = File.Open(ForceTxtSavePath + "ForceUpdate.txt", FileMode.OpenOrCreate); fsForce.Seek(0, SeekOrigin.End); int i = 0; foreach (string file in strCompress) { string path = file; if (path.EndsWith(".XOR")) { path = path.Substring(0, path.Length - 4); } path = path.Replace("\\", "/"); path += ".zip"; byte[] buffer = System.Text.Encoding.UTF8.GetBytes(path); fsForce.Write(buffer, 0, buffer.Length); fsForce.Write(new byte[] { (byte)'\r', (byte)'\n' }, 0, 2); } fsForce.Flush(); fsForce.Close(); } catch (System.Exception exp) { Debug.Log(exp.Message); CreateWizard(); return; } }