Beispiel #1
0
        private async Task <string> FileLoadAsync(string filePath)
        {
            try
            {
                string extension = Path.GetExtension(filePath).ToLower();

                // If the file is encrypted.
                if (extension == ".rpgmvo" || extension == ".ogg_" || extension == ".rpgmvm" || extension == ".m4a_" || extension == ".rpgmvw" || extension == ".wav_")
                {
                    var verifyTask = new Task <bool>(() => CryptographyProvider.VerifyFakeHeader(filePath));
                    verifyTask.Start();
                    await verifyTask;

                    if (!verifyTask.Result)
                    {
                        throw new InvalidDataException("An invalid *.rpgmvo(*.ogg_), *.rpgmvm(*.m4a_), *.rpgmvw(*.wav_) file was entered.");
                    }

                    // Restore the file.
                    string tempFilePath = Path.GetTempFileName();

                    if (extension == ".rpgmvo" || extension == ".ogg_")
                    {
                        var restoreTask = new Task(() => CryptographyProvider.RestoreOggHeader(filePath, tempFilePath));
                        restoreTask.Start();
                        await restoreTask;

                        _isUnstable = true;

                        return(tempFilePath);
                    }
                    else
                    {
                        var restoreTask = new Task(() => CryptographyProvider.RestoreHeader(filePath, tempFilePath));
                        restoreTask.Start();
                        await restoreTask;

                        return(tempFilePath);
                    }
                }
                else
                {
                    return(filePath);
                }
            }
            catch (Exception ex)
            {
                Workspace.Instance.Report.AddReportWithIdentifier($"{ex.Message}\r\n{ex.StackTrace}", ReportType.Warning);
                return(null);
            }
        }
Beispiel #2
0
        private async void Initialize(string filePath)
        {
            var task = Task.Run(() =>
            {
                try
                {
                    string extension = Path.GetExtension(filePath).ToLower();

                    if (extension == ".rpgmvp" || extension == ".png_")
                    {
                        if (!CryptographyProvider.VerifyFakeHeader(filePath))
                        {
                            throw new InvalidDataException("An invalid *.rpgmvp(*.png_) file was entered.");
                        }

                        string tempFilePath = Path.GetTempFileName();
                        CryptographyProvider.RestoreHeader(filePath, tempFilePath);
                        ImageFilePath = tempFilePath;
                    }
                    else
                    {
                        ImageFilePath = filePath;
                    }

                    _fileProperties = new FileProperties(filePath);

                    BitmapImage bi = new BitmapImage();
                    bi.BeginInit();
                    bi.UriSource = new Uri(ImageFilePath, UriKind.RelativeOrAbsolute);
                    bi.EndInit();

                    ImageSizeString = $"{(int)bi.Width} * {(int)bi.Height} px";
                }
                catch (Exception ex)
                {
                    Workspace.Instance.Report.AddReportWithIdentifier($"{ex.Message}\r\n{ex.StackTrace}", ReportType.Warning);
                }
            });

            Workspace.Instance.SetStatus(TaskStatusType.Loading, $"Loading a file... ({filePath})");

            await task;

            Workspace.Instance.SetStatus(TaskStatusType.Completed, $"Completed.");
        }