Exemple #1
0
    public static List <string> ReadBlackFile(string strFileName, BuildTarget Target)
    {
        List <string> strRet  = new List <string>();
        string        strPath = PlatformMap.GetPlatformPath(Target) + "/" + strFileName;

        XmlDocument xmlIgnore = new XmlDocument();

        try
        {
            xmlIgnore.Load(strPath);
            XmlElement files = xmlIgnore.DocumentElement;
            foreach (XmlElement file in files)
            {
                string strfile = file.GetAttribute("name");
                if (strfile != null && strfile.Length != 0)
                {
                    strRet.Add(strfile);
                }
            }
        }
        catch
        {
            return(null);
        }
        return(strRet);
    }
Exemple #2
0
    public static bool UpdateVersionXml(BuildTarget target, List <string> strOldVersionLst, string strNewVer, string notices)
    {
        string strVersionPath;

        strVersionPath  = PlatformMap.GetPlatformPath(target);
        strVersionPath += "/" + strVerFile;

        XmlDocument XmlDoc  = new XmlDocument();
        XmlElement  XmlRoot = XmlDoc.CreateElement(strVersionRoot);

        XmlDoc.AppendChild(XmlRoot);
        foreach (string str in strOldVersionLst)
        {
            XmlElement xmlElem = XmlDoc.CreateElement(strVersionElement);
            xmlElem.SetAttribute(strVersionAttr, str);
            XmlRoot.AppendChild(xmlElem);
        }
        XmlElement xmlNewver = XmlDoc.CreateElement(strVersionElement);

        xmlNewver.SetAttribute(strVersionAttr, strNewVer);
        XmlRoot.AppendChild(xmlNewver);

        XmlDoc.Save(strVersionPath);
        XmlDoc = null;
        return(true);
    }
Exemple #3
0
    void OnWizardUpdate()
    {
        string strTarget = System.Enum.GetName(typeof(BuildTarget), Target);

        if (strTarget == null || strTarget == "")
        {
            return;
        }

        if (System.IO.File.Exists(PlatformMap.GetPlatformPath(Target) + "/IgnoreFile.xml"))
        {
            strTip = "Load IGnoreFile : " + PlatformMap.GetPlatformPath(Target) + "/IgnoreFile.xml" + "  Successed";

            List <string> filelist = VersionWizard.ReadBlackFile("IgnoreFile.xml", Target);
            if (filelist != null && filelist.Count != 0)
            {
                IgnoreFile = new string[filelist.Count];
                int nIndex = 0;
                foreach (string str in filelist)
                {
                    IgnoreFile[nIndex++] = str;
                }
            }
        }
        else
        {
            IgnoreFile = null;
            strTip     = "Load IGnoreFile Failed: file not found";
        }
    }
    public static void CompressVersionXml(UnityEditor.BuildTarget target)
    {
        string SavePath = PlatformMap.GetPlatformPath(target);

        CompressFileLZMA(SavePath + "/" + GenAllUpdateVersionXml.strVFile + ".xml", SavePath + "/" + GenAllUpdateVersionXml.strVFile + ".zip");
        AssetDatabase.Refresh();
        return;
    }
Exemple #5
0
    public static bool CreateNewVersion(BuildTarget target, string major = "", string minor = "", string build = "", string rev = "", string notices = "")
    {
        Major    = major;
        Minor    = minor;
        Build    = build;
        Revision = rev;
        string strTip = "";
        string strVer = BuildVersion();

        strTip = "NewVersion:" + strVer + "\r\n";

        List <string> strVersionLst = new List <string>();

        strVersionLst = GetAllVersion(target);

        int nNum = 0;

        foreach (string str in strVersionLst)
        {
            ++nNum;
            strTip += string.Format("OldVersion{0} : {1}\r\n", nNum, str);
        }

        if (0 != EditorUtility.DisplayDialogComplex("Tip", strTip, "OK", "Cancel", ""))
        {
            return(false);
        }

        try
        {
            System.IO.Directory.CreateDirectory(PlatformMap.GetPlatformPath(target) + "/" + strVer);
        }
        catch (IOException exp)
        {
            EditorUtility.DisplayDialog("Error", "Target Directory Exist", "Quit");
            return(false);
        }

        if (!UpdateVersionXml(target, strVersionLst, strVer, notices))
        {
            return(false);
        }

        AssetDatabase.Refresh();
        return(true);
    }
Exemple #6
0
    void OnWizardCreate()
    {
        string strTarget = System.Enum.GetName(typeof(BuildTarget), Target);

        if (strTarget == null || strTarget == "")
        {
            return;
        }

        if (!(bGenIgnorePrefabxml || bGenIgnoreScenexml || bGenIgnoreFilexml))
        {
            return;
        }

        XmlDocument xml  = new XmlDocument();
        XmlElement  root = xml.CreateElement("files");

        xml.AppendChild(root);
        List <Object> ObjectList = new List <Object>();

        foreach (Object obj in IgnoreObjects)
        {
            if (ObjectList.Contains(obj))
            {
                continue;
            }
            XmlElement node = xml.CreateElement("file");
            node.SetAttribute("name", obj.name);
            root.AppendChild(node);
            ObjectList.Add(obj);
        }
        if (bGenIgnorePrefabxml)
        {
            xml.Save(PlatformMap.GetPlatformPath(Target) + "/IgnorePrefab.xml");
        }
        if (bGenIgnoreScenexml)
        {
            xml.Save(PlatformMap.GetPlatformPath(Target) + "/IgnoreScene.xml");
        }
        if (bGenIgnoreFilexml)
        {
            xml.Save(PlatformMap.GetPlatformPath(Target) + "/IgnoreFile.xml");
        }
    }
    public static void Extract(UnityEditor.BuildTarget target)
    {
        string SavePath = PlatformMap.GetPlatformPath(target);

        DecompressFileLZMA(SavePath + "/v.zip", SavePath + "/" + "v_bak.xml");
        AssetDatabase.Refresh();
//		FileStream fsWrite = new FileStream(SavePath + "/" + "v_bak.xml", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
//		FileStream fsRead = new FileStream(SavePath + "/v.zip", FileMode.Open, FileAccess.Read, FileShare.Read);
//		GZipStream zs = new GZipStream(fsRead, CompressionMode.Decompress, true);
//		int n = 0;
//		byte []buff = new byte[100];
//		while ((n = zs.Read(buff, 0, 100)) != 0)
//		{
//			fsWrite.Write(buff, 0, n);
//		}
//		zs.Close();
//		fsWrite.Flush();
//		fsWrite.Close();
//		AssetDatabase.Refresh();
    }
Exemple #8
0
    public static List <string> GetHistoryVersion(UnityEditor.BuildTarget target)
    {
        string strTarget = System.Enum.GetName(typeof(BuildTarget), target);

        if (strTarget == null || strTarget == "")
        {
            return(null);
        }

        List <string> strRet = new List <string>();

        string strVersionPath;

        strVersionPath  = PlatformMap.GetPlatformPath(target);
        strVersionPath += "/" + strVerFile;
        try
        {
            strRet = ReadVersion(strVersionPath);
        }
        catch (IOException exp)
        {
        }

        if (strRet.Count != 0)
        {
            string strVersion = strRet[0];
            for (int i = 1; i <= strRet.Count - 1; ++i)
            {
                if (strVersion.CompareTo(strRet[i]) == -1)
                {
                    strVersion = strRet[i];
                }
            }

            strRet.Remove(strVersion);
        }
        return(strRet);
    }
Exemple #9
0
    public static List <string> GetAllVersion(UnityEditor.BuildTarget target)
    {
        string strTarget = System.Enum.GetName(typeof(BuildTarget), target);

        if (strTarget == null || strTarget == "")
        {
            return(null);
        }

        List <string> strRet = new List <string>();

        string strVersionPath;

        strVersionPath  = PlatformMap.GetPlatformPath(target);
        strVersionPath += "/" + strVerFile;
        try
        {
            strRet = ReadVersion(strVersionPath);
        }
        catch (IOException exp)
        {
        }
        return(strRet);
    }
Exemple #10
0
    public static string GetCurVersion(UnityEditor.BuildTarget target)
    {
        string strTarget = System.Enum.GetName(typeof(BuildTarget), target);

        if (strTarget == null || strTarget == "")
        {
            return(null);
        }

        string strVersion = "";
        string strVersionPath;

        strVersionPath  = PlatformMap.GetPlatformPath(target);
        strVersionPath += "/" + strVerFile;

        List <VersionItem> strVersionlst = JsonUtility.FromJson <List <VersionItem> >(File.ReadAllText(strVersionPath));

        if (strVersionlst.Count != 0)
        {
            strVersion = strVersionlst[strVersionlst.Count - 1].strVersion;
        }

        string [] strVerBuild = new string[4];
        if (strVersion.Length != 0)
        {
            strVerBuild = strVersion.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            if (strVerBuild.Length == 4)
            {
                Major    = strVerBuild[0];
                Minor    = strVerBuild[1];
                Build    = strVerBuild[2];
                Revision = strVerBuild[3];
            }
        }
        return(strVersion);
    }
    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");
    }
    public static void ExecuteEx(UnityEditor.BuildTarget target)
    {
        Dictionary <string, string> DicFileMD5   = new Dictionary <string, string>();
        MD5CryptoServiceProvider    md5Generator = new MD5CryptoServiceProvider();

        string dir = "";

        try
        {
            dir = PlatformMap.GetPlatformPath(target) + "/" + VersionManager.GetCurVersion(target) + "/";
        }
        catch (IOException exp)
        {
            EditorUtility.DisplayDialog("Error", exp.Message, "OK");
            return;
        }

        string [] allfiles = Directory.GetFiles(dir, "*.*", SearchOption.AllDirectories);
        foreach (string filePath in allfiles)
        {
            if (filePath.EndsWith(".meta") ||
                filePath.EndsWith("FileList.xml") ||
                filePath.EndsWith(".xml") ||
                filePath.EndsWith(".DS_Store") ||
                filePath.EndsWith("entries") ||
                filePath.EndsWith("ForceUpdate.txt") ||
                filePath.EndsWith("referenceTable.txt") ||
                filePath.EndsWith("ext.txt") ||
                filePath.EndsWith("MergeLog.txt"))
            {
                continue;
            }

            FileStream file   = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            byte[]     hash   = md5Generator.ComputeHash(file);
            string     strMD5 = System.BitConverter.ToString(hash);
            file.Close();

            string key = filePath.Substring(dir.Length, filePath.Length - dir.Length);

            if (DicFileMD5.ContainsKey(key) == false)
            {
                DicFileMD5.Add(key, strMD5);
            }
            else
            {
                Debug.LogWarning("<Two File has the same name> name = " + filePath);
            }
        }

        XmlDocument XmlDoc  = new XmlDocument();
        XmlElement  XmlRoot = XmlDoc.CreateElement(strXmlRoot);

        XmlDoc.AppendChild(XmlRoot);
        foreach (KeyValuePair <string, string> pair in DicFileMD5)
        {
            XmlElement xmlElem = XmlDoc.CreateElement(strXmlElement);
            XmlRoot.AppendChild(xmlElem);
            xmlElem.SetAttribute(strFileAttrName, pair.Key.Replace('\\', '/'));
            xmlElem.SetAttribute(strFileAttrMd5, pair.Value);
        }
        try
        {
            XmlDoc.Save(dir + "/" + strFileName);
        }
        catch (System.Exception exp)
        {
            Debug.LogError(exp.Message);
        }
        XmlDoc = null;
    }
    public static void CompressScript(UnityEditor.BuildTarget target, List <string> ignoreFilelist, List <string> CompressTarget, bool bDeleted)
    {
        string SavePath = "";

        try
        {
            SavePath = PlatformMap.GetPlatformPath(target) + "/" + VersionManager.GetCurVersion(target) + "/";
        }
        catch (IOException exp)
        {
            EditorUtility.DisplayDialog("Error", exp.Message, "OK");
            return;
        }

        int compressfile   = 0;
        int uncompressfile = 0;

        foreach (string file in CompressTarget)
        {
            string path = file;
            if (path.EndsWith(".XOR"))
            {
                path = path.Substring(0, path.Length - 4);
            }

            if (ignoreFilelist != null)
            {
                bool   bIgnore    = false;
                string name       = "";
                int    nNameBegin = path.LastIndexOf('/');
                if (nNameBegin == -1)
                {
                    Debug.Log("file named error" + path);
                }
                name = path.Substring(nNameBegin + 1);
                foreach (string strIgnore in ignoreFilelist)
                {
                    if (name == strIgnore)
                    {
                        bIgnore = true;
                        break;
                    }
                }

                if (bIgnore)
                {
                    uncompressfile++;
                    continue;
                }
            }
            path = SavePath + path;
            path = path.Replace("\\", "/");
            int nDirectoryIndex = path.LastIndexOf('/');
            Directory.CreateDirectory(path.Substring(0, nDirectoryIndex));
            path += ".zip";
            CompressFileLZMA(file, path);
            if (bDeleted)
            {
                File.Delete(file);
            }
            compressfile++;
        }
        AssetDatabase.Refresh();
    }
Exemple #14
0
    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;
        }
    }
Exemple #15
0
    //[MenuItem("Assets/Tool/Single Scene PackageWizard", false, 10)]
    //public static void CreateSingleSceneBundle()
    //{
    //	var path = EditorUtility.SaveFilePanel ("Build Bundle", "", "*", "unity3d");
    //       if (path == "")
    //           return;
    //	string SelectPath = AssetDatabase.GetAssetPath(Selection.activeObject);
    //	string [] scene = new string[]{SelectPath};
    //	BuildPipeline.BuildStreamedSceneAssetBundle (scene, path, BuildTarget.iOS);
    //}

    public static bool Execute(UnityEditor.BuildTarget target, List <string> ignoreFilelist, Object SelectObject)
    {
        string SavePath = "";

        try
        {
            SavePath = PlatformMap.GetPlatformPath(target) + "/" + VersionManager.GetCurVersion(target) + "/";
        }
        catch (IOException exp)
        {
            EditorUtility.DisplayDialog("Error", exp.Message, "OK");
            return(false);
        }

        string SelectPath = AssetDatabase.GetAssetPath(SelectObject);

        string [] files         = Directory.GetFiles(SelectPath, "*.unity", SearchOption.AllDirectories);
        int       packagefile   = 0;
        int       unpackagefile = 0;

        foreach (string file in files)
        {
            string path       = file.Replace("\\", "/");
            string name       = "";
            int    nNameBegin = path.LastIndexOf('/');
            int    nNameEnd   = path.LastIndexOf('.');
            name = path.Substring(nNameBegin + 1, nNameEnd - nNameBegin - 1);
            if (ignoreFilelist != null)
            {
                bool bIgnore = false;
                foreach (string strIgnore in ignoreFilelist)
                {
                    if (name == strIgnore)
                    {
                        bIgnore = true;
                        break;
                    }
                }

                if (bIgnore)
                {
                    unpackagefile++;
                    continue;
                }
            }
            packagefile++;
            path = SavePath + name;
            //path =  path.Substring(0, path.LastIndexOf('.'));
            path += ".unity3d";
            BuildPipeline.BuildPlayer(new string[1] {
                file
            }, path, target, BuildOptions.BuildAdditionalStreamedScenes);
            //break;
        }

        //int nRet = 0;
        // 当前选中的资源列表
//		foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
//		{
//			string path = AssetDatabase.GetAssetPath(o);
//			string []strLevel = new string[1];
//			strLevel[0] = path;
//			// 过滤掉meta文件和文件夹
//			if(path.Contains(".meta") || path.Contains(".") == false || path.Contains(".DS_Store"))
//				continue;
//
//			// 过滤掉UIAtlas目录下的贴图和材质(UI/Common目录下的所有资源都是UIAtlas)
//			if (path.Contains("UI/Common"))
//			{
//				if ((o is Texture) || (o is Material))
//					continue;
//			}
//
//			path = SavePath + ConvertToAssetBundleName(path);
//			path = path.Substring(0, path.LastIndexOf('.'));
//			path += ".unity3d";
//			BuildPipeline.BuildPlayer(strLevel, path, target, BuildOptions.BuildAdditionalStreamedScenes);
//			nRet++;
//		}
        EditorUtility.DisplayDialog("Tip", "Package scene : " + packagefile.ToString() + "\r\nunPackage scene : " + unpackagefile.ToString(), "OK");
        AssetDatabase.Refresh();
        return(true);
    }