Esempio n. 1
0
        public static async ValueTask ProcessFile(FileInfo file, bool overwrite)
        {
            if (!file.Exists)
            {
                EventLogger.logError($"File \"{file.FullName}\" could not be found and has been skipped.");
                return;
            }

            using FileStream inputStream = file.OpenRead();
            bool encrypted = SaveFileHandler.IsFileEncrypted(inputStream);

            Stream?processed = encrypted ? await Decrypt(inputStream) : await Encrypt(inputStream);

            if (processed == null)
            {
                EventLogger.logError($"Content of file \"{file.Name}\" could not be converted to a supported format.");
                return;
            }

            processed.Seek(0, SeekOrigin.Begin);
            string outputFile = GetOutputFilePath(file, encrypted, overwrite);

            using FileStream outputStream = File.Open(outputFile, FileMode.Create, FileAccess.Write);
            await processed.CopyToAsync(outputStream);
        }
Esempio n. 2
0
        private static async ValueTask ProcessFile(FileInfo file, bool overwrite)
        {
            if (!file.Exists)
            {
                await Console.Error.WriteLineAsync($"[  ERROR  ] File \"{file.FullName}\" could not be found and has been skipped.");

                return;
            }

            await using FileStream inputStream = file.OpenRead();
            bool encrypted = SaveFileHandler.IsFileEncrypted(inputStream);

            Stream?processed;

            if (encrypted)
            {
                processed = await Decrypt(inputStream);
            }
            else
            {
                processed = await Encrypt(inputStream);
            }
            if (processed == null)
            {
                await Console.Out.WriteLineAsync($"[  ERROR  ] Content of file \"{file.Name}\" could not be converted to a supported format.");

                return;
            }

            processed.Position = 0;
            string outputFile = GetOutputFilePath(file, encrypted, overwrite);

            await using FileStream outputStream = File.Open(outputFile, FileMode.Create, FileAccess.Write);
            await processed.CopyToAsync(outputStream);
        }
Esempio n. 3
0
        private async Task <Stream?> decryptFileIntoStream(string filePath)
        {
            var file = new FileInfo(filePath);

            using FileStream inputStream = file.OpenRead();
            bool encrypted = SaveFileHandler.IsFileEncrypted(inputStream);

            if (!encrypted)
            {
                Assert.Fail($"The file \"{file.Name}\" was in an unexpected format.");
                return(null);
            }
            Stream?stream = await FileProcessHelper.Decrypt(inputStream);

            if (stream == null)
            {
                Assert.Fail($"Content of file \"{file.Name}\" could not be converted to a supported format.");
                return(null);
            }
            return(stream);
        }
Esempio n. 4
0
        private async Task <ProfileSaveFile?> handleDatFileOpen(string filePath)
        {
            var file = new FileInfo(filePath);

            using FileStream inputStream = file.OpenRead();
            bool encrypted = SaveFileHandler.IsFileEncrypted(inputStream);

            if (!encrypted)
            {
                EventLogger.logError($"The file \"{file.Name}\" was in an unexpected format.");
                showError?.Invoke(R.formatFILE_IN_UNEXPECTED_FORMAT_ERROR_MESSAGE(file.Name));
                return(null);
            }
            using Stream? processed = await FileProcessHelper.Decrypt(inputStream);

            if (processed == null)
            {
                EventLogger.logError($"Content of file \"{file.Name}\" could not be converted to a supported format.");
                showError?.Invoke(R.formatFILE_DECRYPT_ERROR_MESSAGE(file.Name));
                return(null);
            }
            return(await tryParseFileStreamAsync(processed !));
        }