Exemple #1
0
    //XmlNode MakeApkNode(XmlDocument xmlDoc)
    //{
    //	if (xmlDoc == null)
    //		return null;

    //	XmlNode majorNode = xmlDoc.CreateElement("MAJOR");
    //	XmlNode minorNode = xmlDoc.CreateElement("MINOR");
    //	XmlNode revisionNode = xmlDoc.CreateElement("REVISION");

    //	XmlAttribute majorValue = xmlDoc.CreateAttribute("value");
    //	XmlAttribute minorValue = xmlDoc.CreateAttribute("value");
    //	XmlAttribute revisionValue = xmlDoc.CreateAttribute("value");

    //	majorValue.Value = Major;
    //	minorValue.Value = Minor;
    //	revisionValue.Value = Revision;

    //	majorNode.Attributes.Append(majorValue);
    //	minorNode.Attributes.Append(minorValue);
    //	revisionNode.Attributes.Append(revisionValue);

    //	XmlNode versionNode = xmlDoc.CreateElement("LastApkVersion");
    //	versionNode.AppendChild(majorNode);
    //	versionNode.AppendChild(minorNode);
    //	versionNode.AppendChild(revisionNode);

    //	return versionNode;
    //}

    XmlNode MakeAssetNode(XmlDocument xmlDoc, stAssetInfo assetInfo)
    {
        if (xmlDoc == null)
        {
            return(null);
        }

        XmlNode assetNode = xmlDoc.CreateElement(assetInfo.Name);

        XmlAttribute crcAttr = xmlDoc.CreateAttribute("CRC");

        crcAttr.Value = assetInfo.CRC.ToString();

        XmlAttribute verAttr = xmlDoc.CreateAttribute("VERSION");

        verAttr.Value = assetInfo.Version.ToString();

        XmlAttribute sizeAttr = xmlDoc.CreateAttribute("FILESIZE");

        sizeAttr.Value = assetInfo.FileSize.ToString();

        assetNode.Attributes.Append(crcAttr);
        assetNode.Attributes.Append(verAttr);
        assetNode.Attributes.Append(sizeAttr);

        return(assetNode);
    }
Exemple #2
0
    public void ParseXML(XmlDocument xmlDoc, string strURL = "")
    {
        Init();

        if (xmlDoc == null)
        {
            return;
        }

        XmlElement verElem = xmlDoc["VERSION_INFO"];

        if (verElem == null)
        {
            return;
        }

        XmlElement assetListElem = verElem["AssetVersion"];

        if (assetListElem != null)
        {
            string strAssetVer = assetListElem.GetAttribute("VERSION");
            uint.TryParse(strAssetVer, out AssetVersion);

            string strAssetCRC = assetListElem.GetAttribute("CRC");
            uint.TryParse(strAssetCRC, out AssetCRC);

            XmlNodeList assetList = assetListElem.ChildNodes;

            if (assetList != null)
            {
                for (int i = 0; i < assetList.Count; ++i)
                {
                    stAssetInfo assetInfo = new stAssetInfo();
                    assetInfo.Name = assetList[i].Name;
                    assetInfo.URL  = strURL;

                    XmlAttributeCollection attributeList = assetList[i].Attributes;
                    if (attributeList != null)
                    {
                        if (attributeList["CRC"] != null)
                        {
                            uint.TryParse(attributeList["CRC"].Value, out assetInfo.CRC);
                        }
                        if (attributeList["VERSION"] != null)
                        {
                            uint.TryParse(attributeList["VERSION"].Value, out assetInfo.Version);
                        }
                        if (attributeList["FILESIZE"] != null)
                        {
                            double.TryParse(attributeList["FILESIZE"].Value, out assetInfo.FileSize);
                        }
                        //assetInfo.Version = attributeList["VERSION"].Value;
                    }

                    AssetDict[assetInfo.Name] = assetInfo;
                }
            }
        }
    }
Exemple #3
0
    public static XmlDocument MakeVersionFile(uint totalCRC, string srcPath, List <stAssetInfo> listAssetNotVersioned = null, bool isFirst = false)
    {
        string targetPath = GetVersionFilePath(srcPath);

        if (isFirst == false)
        {
            LoadVersionFile(srcPath);
            if (CachedVerInfo == null)
            {
                Debug.Log("No Cached File, make new ..");
                LoadedVerDoc = MakeVersionFile(0, srcPath, null, true);                 // ���� ����X�� �⺻��
                //CachedVerInfo = new VersionInfo(LoadedVerDoc);
            }
        }
        else
        {
            CachedVerInfo = new VersionInfo();
        }

        //string strMajor = EnvVariable.GetEnvStr(MajorVerKey);
        //string strMinor = EnvVariable.GetEnvStr(MinorVerKey);
        //string strRevision = EnvVariable.GetEnvStr(RevisionKey);
        //string strAssetVer = EnvVariable.GetEnvStr(AssetVerKey);

        uint uAssetVer = 0;

        uAssetVer = CachedVerInfo.AssetVersion;

        //uint.TryParse(strAssetVer, out uAssetVer);

        VersionInfo newVerInfo = new VersionInfo();
        {
            newVerInfo.Init();
            //newVerInfo.Major = strMajor;
            //newVerInfo.Minor = strMinor;
            //newVerInfo.Revision = strRevision;
            newVerInfo.AssetVersion = uAssetVer;
            newVerInfo.AssetCRC     = totalCRC;

            //newVerInfo.SetVersion(UnityEditor.PlayerSettings.bundleVersion);
            Debug.Log("new version is now " + UnityEditor.PlayerSettings.bundleVersion);

            if (newVerInfo.AssetCRC == CachedVerInfo.AssetCRC)             // CRC ������ ���� �ø��� �ʴ´�
            {
                newVerInfo.AssetDict = CachedVerInfo.AssetDict;
            }
            else
            {                                                                                                                                                           // �Ȱ����� �־��� �����ͷ� ���� �ø���
                if (listAssetNotVersioned != null)
                {
                    newVerInfo.AssetVersion++;

                    for (int i = 0; i < listAssetNotVersioned.Count; ++i)
                    {
                        stAssetInfo tempAssetInfo = listAssetNotVersioned[i];                                   // �� ���� ��� ������ ���� ���� ����
                        tempAssetInfo.Version = newVerInfo.AssetVersion;

                        if (CachedVerInfo.AssetDict.ContainsKey(tempAssetInfo.Name))                                // �ڽ��� �����ִ� ����߿� ���� ����� ���� ��
                        {
                            stAssetInfo cachedAssetInfo = CachedVerInfo.AssetDict[tempAssetInfo.Name];

                            if (tempAssetInfo.CRC == cachedAssetInfo.CRC)                                           // �� ��ü�� CRC ���� ������ ������ �ٲ��� �ʴ´�
                            {
                                tempAssetInfo.Version = cachedAssetInfo.Version;
                            }
                        }

                        newVerInfo.AssetDict[tempAssetInfo.Name] = tempAssetInfo;
                    }
                }
            }
        }

        XmlDocument newDocu = newVerInfo.ToXML();

        CachedVerInfo = newVerInfo;

        if (File.Exists(targetPath) == true)                            // ������ ���� ����
        {
            File.Delete(targetPath);
        }

        XmlTool.writeXml(targetPath, newDocu);                  // ���� ����

        Debug.LogError("Save in MakeVersionFile");

        return(newDocu);
    }
    //[MenuItem(kBuildAssetBundlesMenu)]
    public static void BuildAssetBundles(BuildTarget buildTarget, List <string> buildingAssets = null)
    {
        Debug.Log("Start Build Assetbundles");

        //ProjectBuilder.SetBuildVersion_fromEnvVariable();
        // Choose the output path according to the build target.
        string outputPath = Path.Combine(kAssetBundlesOutputPath, BaseLoader.GetPlatformFolderForAssetBundles(buildTarget));

        if (!Directory.Exists(outputPath))
        {
            Directory.CreateDirectory(outputPath);
        }

        string[]        existingFilesPath = Directory.GetFiles(outputPath);
        List <FileInfo> existingFiles     = new List <FileInfo>();

        if (existingFilesPath != null)
        {
            for (int i = 0; i < existingFilesPath.Length; ++i)
            {
                FileInfo eachFile = new FileInfo(existingFilesPath[i]);
                existingFiles.Add(eachFile);
            }
        }


        //total assets
        string[] bundles = AssetDatabase.GetAllAssetBundleNames();

        AssetBundleManifest totalManifest;

        //BuildPipeline.BuildAssetBundles (outputPath, 0, EditorUserBuildSettings.activeBuildTarget);
        if (buildingAssets == null || buildingAssets.Count <= 0)
        {
            totalManifest =
                BuildPipeline.BuildAssetBundles(outputPath, BuildAssetBundleOptions.None, buildTarget);   // hash값 유지?
        }
        else if (bundles != null)
        {
            List <AssetBundleBuild> tempListBundles = new List <AssetBundleBuild>();

            for (int i = 0; i < buildingAssets.Count; ++i)
            {
                bool isRightAssetName = false;
                for (int j = 0; j < bundles.Length; ++j)
                {
                    if (bundles[j].Equals(buildingAssets[i]) == true)
                    {
                        isRightAssetName = true;
                        break;
                    }
                }

                if (isRightAssetName == true)
                {
                    AssetBundleBuild newStructInfo = new AssetBundleBuild();
                    newStructInfo.assetBundleName = buildingAssets[i];
                    newStructInfo.assetNames      = AssetDatabase.GetAssetPathsFromAssetBundle(buildingAssets[i]);

                    tempListBundles.Add(newStructInfo);
                }
            }

            AssetBundleBuild[] arrBundles = tempListBundles.ToArray();
            totalManifest =
                BuildPipeline.BuildAssetBundles(outputPath, arrBundles, BuildAssetBundleOptions.None, buildTarget);
        }
        else
        {
            Debug.LogError("There is no assetbundle to build");
            return;
        }

        string deviceManifestPath = Path.Combine(outputPath, buildTarget.ToString());
        uint   deviceCRC          = 0;

        BuildPipeline.GetCRCForAssetBundle(deviceManifestPath, out deviceCRC);
        FileInfo totalManiFile = new FileInfo(deviceManifestPath);

        //total manifest
        stAssetInfo totalAssetManifest = new stAssetInfo();

        totalAssetManifest.Name     = buildTarget.ToString();
        totalAssetManifest.CRC      = deviceCRC;
        totalAssetManifest.FileSize = totalManiFile.Length;
        //each assets
        string[] BuiltBundles = totalManifest.GetAllAssetBundles();

        List <stAssetInfo> listAssetInfo = new List <stAssetInfo>();

        listAssetInfo.Add(totalAssetManifest);

        if (BuiltBundles == null)
        {
            Debug.LogError("bundles is null");
            return;
        }

        int invalidCount = 0;

        for (int i = 0; i < BuiltBundles.Length; ++i)
        {
            //어셋 파일 존재 검증
            string targetPath = Path.Combine(outputPath, BuiltBundles[i]);
            if (File.Exists(targetPath) == false)
            {
                invalidCount++;
                Debug.LogError(BuiltBundles[i] + " is not exist");
            }
        }

        if (invalidCount > 0)
        {
            return;
        }

        string buildTargetBundle   = buildTarget.ToString();
        string buildTargetManifest = buildTargetBundle + ".manifest";

        IEnumerable <FileInfo> deleteTarget = existingFiles.Where(
            (fileInfo) =>
        {
            if (fileInfo.Name.Equals(buildTargetBundle) || fileInfo.Name.Equals(buildTargetManifest) || fileInfo.Name.Equals("patch.xml"))
            {
                return(false);
            }

            IEnumerable <string> foundBundles = from bundleName in bundles
                                                where (fileInfo.Name.Equals(bundleName) || fileInfo.Name.Equals(StringUtils.Append(bundleName, ".manifest")))
                                                select bundleName;

            if (foundBundles.Count() > 0)
            {
                return(false);
            }

            return(true);
        }
            );

        Debug.Log("Start Delete non-asset files");
        foreach (FileInfo deleteFile in deleteTarget)
        {
            Debug.Log("Deleting " + deleteFile.Name + " ......");
            deleteFile.Delete();
        }

        for (int i = 0; i < bundles.Length; ++i)
        {
            stAssetInfo newInfo = new stAssetInfo();

            string bundleName = bundles[i];

            string targetPath = Path.Combine(outputPath, bundleName);
            uint   crc        = 0;
            if (BuildPipeline.GetCRCForAssetBundle(targetPath, out crc) == true)
            {
                FileInfo assetFile = new FileInfo(targetPath);

                newInfo.Name     = bundleName;
                newInfo.CRC      = crc;
                newInfo.FileSize = assetFile.Length;

                listAssetInfo.Add(newInfo);
            }
        }

        VersionXML.MakeVersionFile(deviceCRC, outputPath, listAssetInfo);

        Debug.Log("End Build Assetbundles");
    }