コード例 #1
0
    void OnWizardUpdate()
    {
        strLastestVer = VersionManager.GetCurVersion(target);
        List <string> str = VersionManager.GetHistoryVersion(target);

        if (str != null && str.Count != 0)
        {
            historyVer = new string[str.Count];
            for (int i = 0; i < str.Count; ++i)
            {
                historyVer[i] = str[i];
            }
        }
    }
コード例 #2
0
    public static void ExecuteEx(UnityEditor.BuildTarget target)
    {
        string platformPath = PlatformMap.GetPlatformPath(target) + "/";

        Dictionary <string, Dictionary <string, string> > strOldVersionInfo = new Dictionary <string, Dictionary <string, string> >();

        List <string> strOldVersion = VersionManager.GetHistoryVersion(target);

        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);
        }

        // new version Filelist XML
        string strNewVersion = "";

        try
        {
            strNewVersion = VersionManager.GetCurVersion(target);
        }
        catch (IOException exp)
        {
            EditorUtility.DisplayDialog("Error", exp.Message, "OK");
            return;
        }

        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");
    }
コード例 #3
0
    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;
    }
コード例 #4
0
    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();
    }
コード例 #5
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;
        }
    }
コード例 #6
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);
    }