Пример #1
0
        public void DeleteBundles(Func <string, bool> bundleFileDeletePredicate)
        {
            var bundleFiles = VirtualFileSystem.ListFiles(vfsBundleDirectory, "*" + BundleExtension, VirtualSearchOption.TopDirectoryOnly).Result;

            // Group incremental bundles together
            var bundleFilesGroups = bundleFiles.GroupBy(bundleUrl =>
            {
                // Remove incremental ID from bundle url
                ObjectId incrementalId;
                var filename = VirtualFileSystem.GetFileName(bundleUrl);
                var bundleExtensionLength = filename.EndsWith(BundleExtension) ? BundleExtension.Length : 0;
                if (filename.Length - bundleExtensionLength >= ObjectId.HashStringLength + 1 && filename[filename.Length - bundleExtensionLength - ObjectId.HashStringLength - 1] == '.' &&
                    ObjectId.TryParse(filename.Substring(filename.Length - bundleExtensionLength - ObjectId.HashStringLength, ObjectId.HashStringLength), out incrementalId))
                {
                    bundleUrl = bundleUrl.Remove(bundleUrl.Length - bundleExtensionLength - ObjectId.HashStringLength - 1, 1 + ObjectId.HashStringLength);
                }

                return(bundleUrl);
            });

            foreach (var bundleFilesInGroup in bundleFilesGroups)
            {
                var bundleMainFile = VirtualFileSystem.GetAbsolutePath(bundleFilesInGroup.Key);

                if (bundleFileDeletePredicate(bundleMainFile))
                {
                    foreach (var bundleRealFile in bundleFilesInGroup)
                    {
                        NativeFile.FileDelete(VirtualFileSystem.GetAbsolutePath(bundleRealFile));
                    }
                }
            }
        }
Пример #2
0
        public void DeleteBundles(Func <string, bool> bundleFileDeletePredicate)
        {
            var bundleFiles = VirtualFileSystem.ListFiles(vfsBundleDirectory, "*.bundle", VirtualSearchOption.TopDirectoryOnly).Result;

            // Obsolete: Android used to have .bundle.mp3 to avoid compression. Still here so that they get deleted on next build.
            // This can be removed later.
            bundleFiles = bundleFiles.Union(VirtualFileSystem.ListFiles(vfsBundleDirectory, "*.mp3", VirtualSearchOption.TopDirectoryOnly).Result).ToArray();

            foreach (var bundleFile in bundleFiles)
            {
                var bundleRealFile = VirtualFileSystem.GetAbsolutePath(bundleFile);

                // Remove ".mp3" (Android only)
                if (bundleRealFile.EndsWith(".mp3", StringComparison.CurrentCultureIgnoreCase))
                {
                    bundleRealFile = bundleRealFile.Substring(0, bundleRealFile.Length - 4);
                }

                if (bundleFileDeletePredicate(bundleRealFile))
                {
                    NativeFile.FileDelete(bundleRealFile);
                }
            }
        }