public void AddPostCatalogUpdates_AddsCallbackToUpdateBundleLocation_WhenNamingSchemaIsSetToFilenameOnly()
        {
            //Setup
            AddressableAssetGroup group = Settings.CreateGroup("TestAddPostCatalogUpdate", false, false, false,
                                                               new List <AddressableAssetGroupSchema>(), typeof(BundledAssetGroupSchema));

            group.GetSchema <BundledAssetGroupSchema>().BundleNaming = BundledAssetGroupSchema.BundleNamingStyle.NoHash;
            List <Action>           callbacks = new List <Action>();
            string                  targetBundlePathHashed         = "LocalPathToFile/testbundle_123456.bundle";
            string                  targetBundlePathUnHashed       = "LocalPathToFile/testbundle.bundle";
            string                  targetBundleInternalIdHashed   = "{runtime_val}/testbundle_123456.bundle";
            string                  targetBundleInternalIdUnHashed = "{runtime_val}/testbundle.bundle";
            ContentCatalogDataEntry dataEntry = new ContentCatalogDataEntry(typeof(ContentCatalogData), targetBundleInternalIdHashed, typeof(BundledAssetProvider).FullName, new List <object>());
            FileRegistry            registry  = new FileRegistry();

            registry.AddFile(targetBundlePathHashed);
            m_BuildScript.AddPostCatalogUpdatesInternal(group, callbacks, dataEntry, targetBundlePathHashed, registry);

            //Assert setup
            Assert.AreEqual(1, callbacks.Count);
            Assert.AreEqual(targetBundleInternalIdHashed, dataEntry.InternalId);

            //Test
            callbacks[0].Invoke();

            //Assert
            Assert.AreEqual(targetBundleInternalIdUnHashed, dataEntry.InternalId);
            Assert.AreEqual(registry.GetFilePathForBundle("testbundle"), targetBundlePathUnHashed);

            //Cleanup
            Settings.RemoveGroup(group);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Process Includes as source.
        /// </summary>
        /// <param name="listing">The source listing containing potential ".include" directives.</param>
        /// <returns>Returns the new source with the included sources expanded.</returns>
        IEnumerable <SourceLine> ProcessIncludes(IEnumerable <SourceLine> listing)
        {
            var includedLines = new List <SourceLine>();

            foreach (var line in listing)
            {
                if (line.Instruction.Equals(".include", Controller.Options.StringComparison))
                {
                    string filename = line.Operand;
                    if (filename.EnclosedInQuotes() == false)
                    {
                        Controller.Log.LogEntry(line, ErrorStrings.FilenameNotSpecified);
                        continue;
                    }
                    var inclistings = ConvertToSource(filename.TrimOnce('"'));
                    includedLines.AddRange(inclistings);
                }
                else if (line.Instruction.Equals(".binclude", Controller.Options.StringComparison))
                {
                    var args      = line.Operand.CommaSeparate();
                    var openblock = new SourceLine();
                    if (args.Count > 1)
                    {
                        if (string.IsNullOrEmpty(line.Label) == false && _symbolNameFunc(line.Label) == false)
                        {
                            Controller.Log.LogEntry(line, ErrorStrings.LabelNotValid, line.Label);
                            continue;
                        }
                        if (line.Operand.EnclosedInQuotes() == false)
                        {
                            Controller.Log.LogEntry(line, ErrorStrings.None);
                            continue;
                        }
                        if (FileRegistry.Add(line.Operand.TrimOnce('"')) == false)
                        {
                            throw new Exception(string.Format(ErrorStrings.FilePreviouslyIncluded, line.Operand));
                        }
                        openblock.Label = line.Label;
                    }
                    else if (line.Operand.EnclosedInQuotes() == false)
                    {
                        Controller.Log.LogEntry(line, ErrorStrings.FilenameNotSpecified);
                        continue;
                    }
                    openblock.Instruction = ConstStrings.OPEN_SCOPE;
                    includedLines.Add(openblock);
                    var inclistings = ConvertToSource(line.Operand.TrimOnce('"'));

                    includedLines.AddRange(inclistings);
                    includedLines.Add(new SourceLine());
                    includedLines.Last().Instruction = ConstStrings.CLOSE_SCOPE;
                }
                else
                {
                    includedLines.Add(line);
                }
            }
            return(includedLines);
        }
Exemplo n.º 3
0
 /// <summary>
 /// Utility method to write a file.  The directory will be created if it does not exist.
 /// </summary>
 /// <param name="path">The path of the file to write.</param>
 /// <param name="content">The content of the file.</param>
 /// <param name="registry">The file registry used to track all produced artifacts.</param>
 /// <returns>True if the file was written.</returns>
 protected static bool WriteFile(string path, string content, FileRegistry registry)
 {
     try
     {
         registry.AddFile(path);
         var dir = Path.GetDirectoryName(path);
         if (!string.IsNullOrEmpty(dir) && !Directory.Exists(dir))
         {
             Directory.CreateDirectory(dir);
         }
         File.WriteAllText(path, content);
         return(true);
     }
     catch (Exception ex)
     {
         Debug.LogException(ex);
         registry.RemoveFile(path);
         return(false);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Converts a file to a SourceLine list.
        /// </summary>
        /// <param name="file">The filename.</param>
        /// <returns>A <see cref="T:System.Collections.Generic.IEnumerable&lt;DotNetAsm.SourceLine&gt;"/> d.</returns>
        public IEnumerable <SourceLine> ConvertToSource(string file)
        {
            if (FileRegistry.Add(file) == false)
            {
                throw new Exception(string.Format(ErrorStrings.FilePreviouslyIncluded, file));
            }

            if (File.Exists(file))
            {
                Console.WriteLine("Processing input file " + file + "...");
                int currentline = 1;
                var sourcelines = new List <SourceLine>();
                using (StreamReader reader = new StreamReader(File.Open(file, FileMode.Open)))
                {
                    while (reader.EndOfStream == false)
                    {
                        var unprocessedline = reader.ReadLine();
                        try
                        {
                            var line = new SourceLine(file, currentline, unprocessedline);
                            line.Parse(
                                delegate(string token)
                            {
                                return(Controller.IsInstruction(token) || Reserved.IsReserved(token) ||
                                       (token.StartsWith(".") && Macro.IsValidMacroName(token.Substring(1))) ||
                                       token == "=");
                            });
                            sourcelines.Add(line);
                        }
                        catch (Exception ex)
                        {
                            Controller.Log.LogEntry(file, currentline, ex.Message);
                        }
                        currentline++;
                    }
                    sourcelines = Preprocess(sourcelines).ToList();
                }
                return(sourcelines);
            }
            throw new FileNotFoundException(string.Format("Unable to open source file \"{0}\"", file));
        }
Exemplo n.º 5
0
        void PostProcessBundles(AddressableAssetGroup assetGroup, List <string> buildBundles, List <string> outputBundles, IBundleBuildResults buildResult, IWriteData writeData, ResourceManagerRuntimeData runtimeData, List <ContentCatalogDataEntry> locations, FileRegistry registry, Dictionary <string, ContentCatalogDataEntry> primaryKeyToCatalogEntry)
        {
            var schema = assetGroup.GetSchema <BundledAssetGroupSchema>();

            if (schema == null)
            {
                return;
            }

            var path = schema.BuildPath.GetValue(assetGroup.Settings);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            for (int i = 0; i < buildBundles.Count; ++i)
            {
                if (primaryKeyToCatalogEntry.TryGetValue(buildBundles[i], out ContentCatalogDataEntry dataEntry))
                {
                    var info           = buildResult.BundleInfos[buildBundles[i]];
                    var requestOptions = new AssetBundleRequestOptions
                    {
                        Crc             = schema.UseAssetBundleCrc ? info.Crc : 0,
                        Hash            = schema.UseAssetBundleCache ? info.Hash.ToString() : "",
                        ChunkedTransfer = schema.ChunkedTransfer,
                        RedirectLimit   = schema.RedirectLimit,
                        RetryCount      = schema.RetryCount,
                        Timeout         = schema.Timeout,
                        BundleName      = Path.GetFileName(info.FileName),
                        BundleSize      = GetFileSize(info.FileName)
                    };
                    dataEntry.Data = requestOptions;

                    int      extensionLength         = Path.GetExtension(outputBundles[i]).Length;
                    string[] deconstructedBundleName = outputBundles[i].Substring(0, outputBundles[i].Length - extensionLength).Split('_');
                    string   reconstructedBundleName = string.Join("_", deconstructedBundleName, 1, deconstructedBundleName.Length - 1) + ".bundle";

                    outputBundles[i]     = ConstructAssetBundleName(assetGroup, schema, info, reconstructedBundleName);
                    dataEntry.InternalId = dataEntry.InternalId.Remove(dataEntry.InternalId.Length - buildBundles[i].Length) + outputBundles[i];
                    dataEntry.Keys[0]    = outputBundles[i];
                    ReplaceDependencyKeys(buildBundles[i], outputBundles[i], locations);

                    if (!m_BundleToInternalId.ContainsKey(buildBundles[i]))
                    {
                        m_BundleToInternalId.Add(buildBundles[i], dataEntry.InternalId);
                    }

                    if (dataEntry.InternalId.StartsWith("http:\\"))
                    {
                        dataEntry.InternalId = dataEntry.InternalId.Replace("http:\\", "http://").Replace("\\", "/");
                    }
                    if (dataEntry.InternalId.StartsWith("https:\\"))
                    {
                        dataEntry.InternalId = dataEntry.InternalId.Replace("https:\\", "https://").Replace("\\", "/");
                    }
                }
                else
                {
                    Debug.LogWarningFormat("Unable to find ContentCatalogDataEntry for bundle {0}.", outputBundles[i]);
                }

                var targetPath = Path.Combine(path, outputBundles[i]);
                if (!Directory.Exists(Path.GetDirectoryName(targetPath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                }
                File.Copy(Path.Combine(assetGroup.Settings.buildSettings.bundleBuildPath, buildBundles[i]), targetPath, true);
                registry.AddFile(targetPath);
            }
        }
Exemplo n.º 6
0
        static void PostProcessBundles(AddressableAssetGroup assetGroup, List <string> bundles, IBundleBuildResults buildResult, IWriteData writeData, ResourceManagerRuntimeData runtimeData, List <ContentCatalogDataEntry> locations, FileRegistry registry)
        {
            var schema = assetGroup.GetSchema <BundledAssetGroupSchema>();

            if (schema == null)
            {
                return;
            }

            var path = schema.BuildPath.GetValue(assetGroup.Settings);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            foreach (var originalBundleName in bundles)
            {
                var newBundleName = originalBundleName;
                var info          = buildResult.BundleInfos[newBundleName];
                ContentCatalogDataEntry dataEntry = locations.FirstOrDefault(s => newBundleName == (string)s.Keys[0]);
                if (dataEntry != null)
                {
                    var requestOptions = new AssetBundleRequestOptions
                    {
                        Crc             = schema.UseAssetBundleCrc ? info.Crc : 0,
                        Hash            = schema.UseAssetBundleCache ? info.Hash.ToString() : "",
                        ChunkedTransfer = schema.ChunkedTransfer,
                        RedirectLimit   = schema.RedirectLimit,
                        RetryCount      = schema.RetryCount,
                        Timeout         = schema.Timeout,
                        BundleName      = Path.GetFileName(info.FileName),
                        BundleSize      = GetFileSize(info.FileName)
                    };
                    dataEntry.Data = requestOptions;

                    dataEntry.InternalId = BuildUtility.GetNameWithHashNaming(schema.BundleNaming, info.Hash.ToString(), dataEntry.InternalId);
                    newBundleName        = BuildUtility.GetNameWithHashNaming(schema.BundleNaming, info.Hash.ToString(), newBundleName);
                }
                else
                {
                    Debug.LogWarningFormat("Unable to find ContentCatalogDataEntry for bundle {0}.", newBundleName);
                }

                var targetPath = Path.Combine(path, newBundleName);
                if (!Directory.Exists(Path.GetDirectoryName(targetPath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                }
                File.Copy(Path.Combine(assetGroup.Settings.buildSettings.bundleBuildPath, originalBundleName), targetPath, true);
                registry.AddFile(targetPath);
            }
        }
Exemplo n.º 7
0
        static void CreateCatalog(AddressableAssetSettings aaSettings, ContentCatalogData contentCatalog, List <ResourceLocationData> locations, string playerVersion, string localCatalogFilename, FileRegistry registry)
        {
            var localBuildPath = Addressables.BuildPath + "/" + localCatalogFilename;
            var localLoadPath  = "{UnityEngine.AddressableAssets.Addressables.RuntimePath}/" + localCatalogFilename;

            var jsonText = JsonUtility.ToJson(contentCatalog);

            WriteFile(localBuildPath, jsonText, registry);

            string[] dependencyHashes = null;
            if (aaSettings.BuildRemoteCatalog)
            {
                var contentHash = HashingMethods.Calculate(jsonText).ToString();

                var versionedFileName = aaSettings.profileSettings.EvaluateString(aaSettings.activeProfileId, "/catalog_" + playerVersion);
                var remoteBuildFolder = aaSettings.RemoteCatalogBuildPath.GetValue(aaSettings);
                var remoteLoadFolder  = aaSettings.RemoteCatalogLoadPath.GetValue(aaSettings);

                if (string.IsNullOrEmpty(remoteBuildFolder) ||
                    string.IsNullOrEmpty(remoteLoadFolder) ||
                    remoteBuildFolder == AddressableAssetProfileSettings.undefinedEntryValue ||
                    remoteLoadFolder == AddressableAssetProfileSettings.undefinedEntryValue)
                {
                    Addressables.LogWarning("Remote Build and/or Load paths are not set on the main AddressableAssetSettings asset, but 'Build Remote Catalog' is true.  Cannot create remote catalog.  In the inspector for any group, double click the 'Addressable Asset Settings' object to begin inspecting it. '" + remoteBuildFolder + "', '" + remoteLoadFolder + "'");
                }
                else
                {
                    var remoteJsonBuildPath = remoteBuildFolder + versionedFileName + ".json";
                    var remoteHashBuildPath = remoteBuildFolder + versionedFileName + ".hash";

                    WriteFile(remoteJsonBuildPath, jsonText, registry);
                    WriteFile(remoteHashBuildPath, contentHash, registry);

                    dependencyHashes = new string[((int)ContentCatalogProvider.DependencyHashIndex.Count)];
                    dependencyHashes[(int)ContentCatalogProvider.DependencyHashIndex.Remote] = ResourceManagerRuntimeData.kCatalogAddress + "RemoteHash";
                    dependencyHashes[(int)ContentCatalogProvider.DependencyHashIndex.Cache]  = ResourceManagerRuntimeData.kCatalogAddress + "CacheHash";

                    var remoteHashLoadPath = remoteLoadFolder + versionedFileName + ".hash";
                    locations.Add(new ResourceLocationData(
                                      new[] { dependencyHashes[(int)ContentCatalogProvider.DependencyHashIndex.Remote] },
                                      remoteHashLoadPath,
                                      typeof(TextDataProvider), typeof(string)));

                    var cacheLoadPath = "{UnityEngine.Application.persistentDataPath}/com.unity.addressables" + versionedFileName + ".hash";
                    locations.Add(new ResourceLocationData(
                                      new[] { dependencyHashes[(int)ContentCatalogProvider.DependencyHashIndex.Cache] },
                                      cacheLoadPath,
                                      typeof(TextDataProvider), typeof(string)));
                }
            }

            locations.Add(new ResourceLocationData(
                              new [] { ResourceManagerRuntimeData.kCatalogAddress },
                              localLoadPath,
                              typeof(ContentCatalogProvider),
                              typeof(ContentCatalogData),
                              dependencyHashes));
        }
Exemplo n.º 8
0
        private void PostProcessCatalogEnteries(AddressableAssetGroup group, IBundleWriteData writeData, List <ContentCatalogDataEntry> locations, FileRegistry fileRegistry)
        {
            if (!group.HasSchema <BundledAssetGroupSchema>() || !File.Exists(ContentUpdateScript.GetContentStateDataPath(false)))
            {
                return;
            }

            AddressablesContentState contentState = ContentUpdateScript.LoadContentState(ContentUpdateScript.GetContentStateDataPath(false));

            foreach (AddressableAssetEntry entry in group.entries)
            {
                CachedAssetState cachedAsset = contentState.cachedInfos.FirstOrDefault(i => i.asset.guid.ToString() == entry.guid);
                if (cachedAsset != null)
                {
                    if (entry.parentGroup.Guid == cachedAsset.groupGuid)
                    {
                        string file           = writeData.AssetToFiles[new GUID(entry.guid)][0];
                        string fullBundleName = writeData.FileToBundle[file];

                        ContentCatalogDataEntry catalogBundleEntry = locations.FirstOrDefault((loc) => (loc.Keys[0] as string) == fullBundleName);

                        if (catalogBundleEntry != null)
                        {
                            if (String.IsNullOrEmpty(entry.BundleFileId))
                            {
                                entry.BundleFileId = catalogBundleEntry.InternalId;
                            }
                            else
                            {
                                if (catalogBundleEntry.InternalId != cachedAsset.bundleFileId)
                                {
                                    string unusedBundlePath =
                                        fileRegistry.GetFilePathForBundle(
                                            Path.GetFileNameWithoutExtension(fullBundleName));

                                    if (File.Exists(unusedBundlePath) &&
                                        fileRegistry.ReplaceBundleEntry(
                                            Path.GetFileNameWithoutExtension(fullBundleName),
                                            cachedAsset.bundleFileId))
                                    {
                                        File.Delete(unusedBundlePath);
                                        catalogBundleEntry.InternalId = entry.BundleFileId;
                                        catalogBundleEntry.Data       = cachedAsset.data;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        static void PostProcessBundles(AddressableAssetGroup assetGroup, List <string> bundles, IBundleBuildResults buildResult, IWriteData writeData, ResourceManagerRuntimeData runtimeData, List <ContentCatalogDataEntry> locations, FileRegistry registry)
        {
            var schema = assetGroup.GetSchema <BundledAssetGroupSchema>();

            if (schema == null)
            {
                return;
            }

            var path = schema.BuildPath.GetValue(assetGroup.Settings);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            foreach (var originalBundleName in bundles)
            {
                var newBundleName = originalBundleName;
                var info          = buildResult.BundleInfos[newBundleName];
                ContentCatalogDataEntry dataEntry = locations.FirstOrDefault(s => newBundleName == (string)s.Keys[0]);
                if (dataEntry != null)
                {
                    var requestOptions = new AssetBundleRequestOptions
                    {
                        Crc             = schema.UseAssetBundleCrc ? info.Crc : 0,
                        Hash            = schema.UseAssetBundleCache ? info.Hash.ToString() : "",
                        ChunkedTransfer = schema.ChunkedTransfer,
                        RedirectLimit   = schema.RedirectLimit,
                        RetryCount      = schema.RetryCount,
                        Timeout         = schema.Timeout,
                        BundleName      = Path.GetFileName(info.FileName),
                        BundleSize      = GetFileSize(info.FileName)
                    };
                    dataEntry.Data = requestOptions;

                    int      extensionLength         = Path.GetExtension(originalBundleName).Length;
                    string[] deconstructedBundleName = originalBundleName.Substring(0, originalBundleName.Length - extensionLength)
                                                       .Split('_');
                    deconstructedBundleName[0] = assetGroup.Name
                                                 .Replace(" ", "")
                                                 .Replace('\\', '/')
                                                 .Replace("//", "/")
                                                 .ToLower();

                    string reconstructedBundleName = string.Join("_", deconstructedBundleName) + ".bundle";

                    newBundleName        = BuildUtility.GetNameWithHashNaming(schema.BundleNaming, info.Hash.ToString(), reconstructedBundleName);
                    dataEntry.InternalId = dataEntry.InternalId.Remove(dataEntry.InternalId.Length - originalBundleName.Length) + newBundleName;

                    if (dataEntry.InternalId.StartsWith("http:\\"))
                    {
                        dataEntry.InternalId = dataEntry.InternalId.Replace("http:\\", "http://").Replace("\\", "/");
                    }
                }
                else
                {
                    Debug.LogWarningFormat("Unable to find ContentCatalogDataEntry for bundle {0}.", newBundleName);
                }

                var targetPath = Path.Combine(path, newBundleName);
                if (!Directory.Exists(Path.GetDirectoryName(targetPath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                }
                File.Copy(Path.Combine(assetGroup.Settings.buildSettings.bundleBuildPath, originalBundleName), targetPath, true);
                registry.AddFile(targetPath);
            }
        }
Exemplo n.º 10
0
        private void PostProcessCatalogEnteries(AddressableAssetGroup group, IBundleWriteData writeData, List <ContentCatalogDataEntry> locations, FileRegistry fileRegistry)
        {
            if (!group.HasSchema <BundledAssetGroupSchema>() ||
                !File.Exists(ContentUpdateScript.GetContentStateDataPath(false)))
            {
                return;
            }

            AddressablesContentState contentState =
                ContentUpdateScript.LoadContentState(ContentUpdateScript.GetContentStateDataPath(false));

            foreach (AddressableAssetEntry entry in group.entries)
            {
                CachedAssetState cachedAsset =
                    contentState.cachedInfos.FirstOrDefault(i => i.asset.guid.ToString() == entry.guid);
                if (cachedAsset != null)
                {
                    GUID guid = new GUID(entry.guid);
                    if (!writeData.AssetToFiles.ContainsKey(guid))
                    {
                        continue;
                    }

                    string file              = writeData.AssetToFiles[guid][0];
                    string fullBundleName    = writeData.FileToBundle[file];
                    string convertedLocation = m_BundleToInternalId[fullBundleName];

                    ContentCatalogDataEntry catalogBundleEntry = locations.FirstOrDefault((loc) => loc.InternalId == (convertedLocation));

                    if (catalogBundleEntry != null)
                    {
                        if (entry.parentGroup.Guid == cachedAsset.groupGuid)
                        {
                            //Asset hash hasn't changed
                            if (AssetDatabase.GetAssetDependencyHash(entry.AssetPath) == cachedAsset.asset.hash)
                            {
                                if (catalogBundleEntry.InternalId != cachedAsset.bundleFileId)
                                {
                                    string builtBundlePath = m_BundleToInternalId[fullBundleName].Replace(
                                        group.GetSchema <BundledAssetGroupSchema>().LoadPath.GetValue(group.Settings),
                                        group.GetSchema <BundledAssetGroupSchema>().BuildPath.GetValue(group.Settings));

                                    string cachedBundlePath = cachedAsset.bundleFileId?.Replace(
                                        group.GetSchema <BundledAssetGroupSchema>().LoadPath.GetValue(group.Settings),
                                        group.GetSchema <BundledAssetGroupSchema>().BuildPath.GetValue(group.Settings));

                                    //Need to check and make sure our cached version exists
                                    if (!string.IsNullOrEmpty(cachedBundlePath) && File.Exists(cachedBundlePath))
                                    {
                                        //Try and replace the new bundle entry with the cached one and delete the new bundle
                                        if (File.Exists(builtBundlePath) &&
                                            fileRegistry.ReplaceBundleEntry(
                                                Path.GetFileNameWithoutExtension(convertedLocation),
                                                cachedAsset.bundleFileId))
                                        {
                                            File.Delete(builtBundlePath);
                                            catalogBundleEntry.InternalId = cachedAsset.bundleFileId;
                                            catalogBundleEntry.Data       = cachedAsset.data;
                                            entry.BundleFileId            = cachedAsset.bundleFileId;
                                        }
                                    }
                                }
                            }
                            entry.BundleFileId       = catalogBundleEntry.InternalId;
                            cachedAsset.bundleFileId = catalogBundleEntry.InternalId;
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
    public override void PostProcessBundles(AddressableAssetGroup assetGroup, List <string> buildBundles, List <string> outputBundles, IBundleBuildResults buildResult, ResourceManagerRuntimeData runtimeData, List <ContentCatalogDataEntry> locations, FileRegistry registry, Dictionary <string, ContentCatalogDataEntry> primaryKeyToCatalogEntry, Dictionary <string, string> bundleRenameMap, List <Action> postCatalogUpdateCallbacks)
    {
        var schema = assetGroup.GetSchema <BundledAssetGroupSchema>();

        if (schema == null)
        {
            return;
        }

        var path = schema.BuildPath.GetValue(assetGroup.Settings);

        if (string.IsNullOrEmpty(path))
        {
            return;
        }

        for (int i = 0; i < buildBundles.Count; ++i)
        {
            if (primaryKeyToCatalogEntry.TryGetValue(buildBundles[i], out ContentCatalogDataEntry dataEntry))
            {
                var info           = buildResult.BundleInfos[buildBundles[i]];
                var requestOptions = new AssetBundleEncryptRequestOptions
                {
                    Crc = schema.UseAssetBundleCrc ? info.Crc : 0,
                    UseCrcForCachedBundle = schema.UseAssetBundleCrcForCachedBundles,
                    Hash            = schema.UseAssetBundleCache ? info.Hash.ToString() : "",
                    ChunkedTransfer = schema.ChunkedTransfer,
                    RedirectLimit   = schema.RedirectLimit,
                    RetryCount      = schema.RetryCount,
                    Timeout         = schema.Timeout,
                    BundleName      = Path.GetFileName(info.FileName),
                    BundleSize      = GetFileSize(info.FileName)
                };
                dataEntry.Data = requestOptions;

                int      extensionLength         = Path.GetExtension(outputBundles[i]).Length;
                string[] deconstructedBundleName = outputBundles[i].Substring(0, outputBundles[i].Length - extensionLength).Split('_');
                string   reconstructedBundleName = string.Join("_", deconstructedBundleName, 1, deconstructedBundleName.Length - 1) + ".bundle";

                outputBundles[i]     = ConstructAssetBundleName(assetGroup, schema, info, reconstructedBundleName);
                dataEntry.InternalId = dataEntry.InternalId.Remove(dataEntry.InternalId.Length - buildBundles[i].Length) + outputBundles[i];
                dataEntry.Keys[0]    = outputBundles[i];
                ReplaceDependencyKeys(buildBundles[i], outputBundles[i], locations);

                Debug.Log(outputBundles[i] + "crc = " + requestOptions.Crc + " hash = " + requestOptions.Hash);

                if (!m_BundleToInternalId.ContainsKey(buildBundles[i]))
                {
                    m_BundleToInternalId.Add(buildBundles[i], dataEntry.InternalId);
                }

                if (dataEntry.InternalId.StartsWith("http:\\"))
                {
                    dataEntry.InternalId = dataEntry.InternalId.Replace("http:\\", "http://").Replace("\\", "/");
                }
                if (dataEntry.InternalId.StartsWith("https:\\"))
                {
                    dataEntry.InternalId = dataEntry.InternalId.Replace("https:\\", "https://").Replace("\\", "/");
                }
                dataEntry.InternalId = CheckNameNeedStripped(assetGroup, dataEntry.InternalId);
            }
            else
            {
                Debug.LogWarningFormat("Unable to find ContentCatalogDataEntry for bundle {0}.", outputBundles[i]);
            }

            //获取bundle的保存路径
            var targetPath = Path.Combine(path, outputBundles[i]);

            //判断目录是否存在
            if (!Directory.Exists(Path.GetDirectoryName(targetPath)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
            }

            File.Copy(Path.Combine(assetGroup.Settings.buildSettings.bundleBuildPath, buildBundles[i]), targetPath, true);

            var nameWithourHash = CheckNameNeedStripped(assetGroup, outputBundles[i]);
            EncodeAssetBundleBySetOffset(nameWithourHash, targetPath);
            var bundleName = Path.GetFileName(nameWithourHash);
            if (IsBuildInAssetBundle(bundleName))
            {
                string RuntimePath = UnityEngine.AddressableAssets.Addressables.RuntimePath;
                string destPath    = Path.Combine(System.Environment.CurrentDirectory, RuntimePath, PlatformMappingService.GetPlatform().ToString(), nameWithourHash);
                if (!Directory.Exists(Path.GetDirectoryName(destPath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(destPath));
                }
                if (!File.Exists(destPath))
                {
                    File.Copy(targetPath, destPath);
                }
            }

            AddPostCatalogUpdatesInternal(assetGroup, postCatalogUpdateCallbacks, dataEntry, targetPath);

            registry.AddFile(targetPath);
        }
    }
Exemplo n.º 12
0
        public void Process(SourceLine line)
        {
            var openblock = new SourceLine();

            if (line.Instruction.Equals(".binclude", Assembler.Options.StringComparison))
            {
                var args = line.Operand.CommaSeparate();

                if (args.Count > 1)
                {
                    if (string.IsNullOrEmpty(line.Label) == false)
                    {
                        Assembler.Log.LogEntry(line, ErrorStrings.LabelNotValid, line.Label);
                        Reset();
                        return;
                    }
                    else
                    {
                        openblock.Label = line.Label;
                    }
                }
                else if (line.Operand.EnclosedInQuotes() == false)
                {
                    Assembler.Log.LogEntry(line, ErrorStrings.FilenameNotSpecified);
                }
                openblock.Instruction = ConstStrings.OPEN_SCOPE;
                _includedLines.Add(openblock);
            }
            if (line.Operand.EnclosedInQuotes() == false)
            {
                Assembler.Log.LogEntry(line, ErrorStrings.None);
            }
            else
            {
                var fileName = line.Operand.Trim('"');
                if (File.Exists(fileName))
                {
                    FileRegistry.Add(fileName);
                    Console.WriteLine("Processing input file " + fileName + "...");
                    int currentline = 1;
                    var sourcelines = new List <SourceLine>();
                    using (StreamReader reader = new StreamReader(File.Open(fileName, FileMode.Open)))
                    {
                        while (reader.EndOfStream == false)
                        {
                            var source = reader.ReadLine();
                            _includedLines.Add(new SourceLine(fileName, currentline, source));
                            currentline++;
                        }
                    }
                }
                else
                {
                    throw new FileNotFoundException(string.Format("Unable to open source file '{0}'", fileName));
                }
                if (openblock.Instruction.Equals(ConstStrings.OPEN_SCOPE))
                {
                    var closeBlock = new SourceLine
                    {
                        Instruction = ConstStrings.CLOSE_SCOPE
                    };
                    _includedLines.Add(closeBlock);
                }
            }
            ProcessCommentBlocks(_includedLines);
        }