예제 #1
0
        static bool ProcessJsonLottieFile(
            CommandLineOptions options,
            Reporter reporter,
            string jsonFilePath,
            string outputFolder,
            DateTime timestamp)
        {
            using var jsonStream = TryOpenFile(jsonFilePath, reporter);

            if (jsonStream is null)
            {
                reporter.WriteError($"Failed to read {jsonFilePath}.");
                return(false);
            }

            return(LottieJsonFileProcessor.ProcessLottieJsonFile(
                       options: options,
                       reporter: reporter,
                       sourceFilePath: jsonFilePath,
                       jsonFilePath: jsonFilePath,
                       className: GetClassName(jsonFilePath),
                       jsonStream: jsonStream,
                       outputFolder: outputFolder,
                       timestamp: timestamp));
        }
예제 #2
0
        static bool ProcessDotLottieFile(
            CommandLineOptions options,
            Reporter reporter,
            string filePath,
            string outputFolder,
            DateTime timestamp)
        {
            using var fileStream = TryOpenFile(filePath, reporter);

            if (fileStream is null)
            {
                return(false);
            }

            ZipArchive zipArchive;

            try
            {
                zipArchive = new ZipArchive(fileStream, ZipArchiveMode.Read);
            }
            catch (InvalidDataException e)
            {
                using (reporter.ErrorStream.Lock())
                {
                    reporter.WriteError($"File {filePath} is not a valid .lottie file.");
                    reporter.WriteError(e.Message);
                }

                return(false);
            }

            var dotLottieFile = DotLottieFile.FromZipArchive(zipArchive);

            if (dotLottieFile is null)
            {
                reporter.WriteError($"File {filePath} is not a valid .lottie file.");
                return(false);
            }

            if (dotLottieFile.Animations.Count == 0)
            {
                reporter.WriteError($"File {filePath} contains no animations.");
                return(false);
            }

            var succeeded = true;

            foreach (var animation in dotLottieFile.Animations)
            {
                var jsonPath = $"{filePath}{animation.Path}";

                using var jsonStream = animation.Open();

                if (jsonStream == null)
                {
                    reporter.WriteError($"Failed to read from {jsonPath}.");
                    succeeded = false;
                    continue;
                }

                // The name of the class should reflect the name of the .lottie file,
                // but if there are multiple .json files in the .lottie file then we
                // need to differentiate them by adding the file name.
                var className = dotLottieFile.Animations.Count == 1
                    ? GetClassName(filePath)
                    : GetClassName($"{filePath}_{animation.Id}");

                if (!LottieJsonFileProcessor.ProcessLottieJsonFile(
                        options: options,
                        reporter: reporter,
                        sourceFilePath: filePath,
                        jsonFilePath: jsonPath,
                        className: className,
                        jsonStream: jsonStream,
                        outputFolder: outputFolder,
                        timestamp))
                {
                    succeeded = false;
                }
            }

            return(succeeded);
        }