Example #1
0
        /// <summary>
        /// Applique des paramètres à l'instance actuelle de VGMGUI.
        /// </summary>
        /// <param name="data">Les paramètres à appliquer.</param>
        public void ApplySettings(IniData data, bool startup = false)
        {
            object o;

            App.SetLanguage(data.Global["Language"] ?? "Auto");
            if ((o = data.Global["StopWhenDelete"].ToBool()) != null)
            {
                StopPlayingWhenDeleteFile = (bool)o;
            }
            if ((o = data.Global["PreAnalyse"].ToBool()) != null)
            {
                PreAnalyse = (bool)o;
            }
            if (startup && (o = data.Global["Preview"]) != null)
            {
                switch (o)
                {
                case "In":
                    ALERadioButton.IsChecked = true;
                    break;

                case "Out":
                    ALSRadioButton.IsChecked = true;
                    break;
                }
            }
            if ((o = data.Global["SamplesDisplay"]) != null)
            {
                switch (o)
                {
                case "S":
                    HMSSamplesDisplay = false;
                    break;

                case "HMS":
                    HMSSamplesDisplay = true;
                    break;
                }
            }
            if ((o = data.Global["SamplesDisplayMaxDec"].ToInt()) != null)
            {
                SamplesDisplayMaxDec = ((int)o);
            }

            if ((o = data["Search"]["SearchDelay"].ToInt()) != null)
            {
                SearchDelay = ((int)o);
            }

            if (startup)
            {
                o = data.Global["LoopType"];
                {
                    switch (o)
                    {
                    case "None":
                        AP.LoopType = LoopTypes.None;
                        break;

                    case "All":
                        AP.LoopType = LoopTypes.All;
                        break;

                    case "Random":
                        AP.LoopType = LoopTypes.Random;
                        break;
                    }
                }

                if ((o = data.Global["Volume"].ToInt()) != null)
                {
                    AP.Volume = (int)o;
                }
                if ((o = data.Global["Mute"].ToBool()) != null)
                {
                    AP.Mute = (bool)o;
                }

                if ((o = data.Global["ConversionFolderName"]) != null)
                {
                    MainDestTB.Text = o as string;
                }
                if ((o = SettingsData.Global["DefaultOutData"]?.Replace("\"", string.Empty)?.Split(new[] { " | " }, StringSplitOptions.None)) != null)
                {
                    var outData = (string[])o;
                    var s       = SettingsData.Global["DefaultOutData"];
                    if (outData.Length == 6)
                    {
                        DefaultOutData = new FichierOutData()
                        {
                            OriginalDestination = outData[0],
                            FadeDelay           = outData[1].ToDouble(),
                            FadeOut             = outData[2].ToBool(),
                            FadeTime            = outData[3].ToDouble(),
                            LoopCount           = outData[4].ToInt(),
                            StartEndLoop        = outData[5].ToBool(),
                        };
                    }
                }

                if ((o = SettingsData.Global["ColumnsInfo"]?.Split(new[] { " | " }, StringSplitOptions.RemoveEmptyEntries)) != null)
                {
                    var columns    = (tasklist.FILEList.View as GridView).Columns;
                    var oldColumns = columns.ToArray();

                    var columnsInfo = ((string[])o).Select(info =>
                    {
                        var num = info.Split(new[] { " : " }, StringSplitOptions.None);
                        if (num.Length == 2)
                        {
                            var index = num[0].ToInt();
                            return(Index: index ?? 0, Width: index == null ? double.NaN : num[1].ToDouble() ?? double.NaN);
                        }
                        else
                        {
                            return(Index: 0, Width: double.NaN);
                        }
                    }).Where(info => !double.IsNaN(info.Width)).ToArray();

                    if (columnsInfo.Length == oldColumns.Length && !columnsInfo.OrderBy(i => i.Index).Select((i, j) => i.Index - j).Distinct().Skip(1).Any())
                    {
                        for (int i = 0; i < oldColumns.Length; i++)
                        {
                            int oldIndex = columns.IndexOf(oldColumns[i]);
                            int newIndex = columnsInfo[i].Index;

                            columns.Move(oldIndex, newIndex);
                            columns[newIndex].Width = columnsInfo[i].Width;
                        }
                    }
                }

                if ((o = data["Window"]["Width"].ToDouble()) != null)
                {
                    Width = (double)o;
                }
                if ((o = data["Window"]["Height"].ToDouble()) != null)
                {
                    Height = (double)o;
                }
                if ((o = data["Window"]["State"].ToEnum <WindowState>()) != null && (WindowState)o != WindowState.Minimized)
                {
                    WindowState = (WindowState)o;
                }

                if ((o = SettingsData["Grids"]["TopGrid"]?.Split(new[] { " | " }, StringSplitOptions.RemoveEmptyEntries)) is string[] columndefsstr && columndefsstr.Length == 2)
                {
                    var columndefs = new GridLength?[] { columndefsstr[0].ToGridLength(), columndefsstr[1].ToGridLength() };
                    if (!columndefs.Contains(null))
                    {
                        TopGrid.ColumnDefinitions[0].Width = (GridLength)columndefs[0];
                        TopGrid.ColumnDefinitions[1].Width = (GridLength)columndefs[1];
                    }
                }
                if ((o = SettingsData["Grids"]["RightGrid"]?.Split(new[] { " | " }, StringSplitOptions.RemoveEmptyEntries)) is string[] rowdefsstr && rowdefsstr.Length == 2)
                {
                    var rowdefs = new GridLength?[] { rowdefsstr[0].ToGridLength(), rowdefsstr[1].ToGridLength() };
                    if (!rowdefs.Contains(null))
                    {
                        RightGrid.RowDefinitions[0].Height = (GridLength)rowdefs[0];
                        RightGrid.RowDefinitions[1].Height = (GridLength)rowdefs[1];
                    }
                }

                if ((o = data["Search"]["SearchFilter"]) != null)
                {
                    RestoreSearchFilter = o as string;
                }
                if ((o = data["Search"]["SearchColumn"].ToEnum <FileListColumn>()) != null)
                {
                    SearchColumn = (FileListColumn)o;
                }
                if ((o = data["Search"]["CaseSensitive"].ToBool()) != null)
                {
                    SearchCaseSensitive = ((bool)o);
                }
                if ((o = data["Search"]["Regex"].ToBool()) != null)
                {
                    SearchRegex = ((bool)o);
                }
            }

            if ((o = data["Multithreading"]["Conversion"].ToBool()) != null)
            {
                ConversionMultithreading = (bool)o;
            }
            if ((o = data["Multithreading"]["MaxConversion"].ToInt()) != null)
            {
                ConversionMaxProcessCount = (int)o;
            }

            if ((o = data["Multithreading"]["Adding"].ToBool()) != null)
            {
                AddingMultithreading = (bool)o;
            }
            if ((o = data["Multithreading"]["MaxAdding"].ToInt()) != null)
            {
                AddingMaxProcessCount = (int)o;
            }

            if ((o = data["StatusBar"]["Display"].ToBool()) != null)
            {
                StatusBar.Display = (bool)o;
            }
            if ((o = data["StatusBar"]["Counter"].ToBool()) != null)
            {
                StatusBar.Counter = (bool)o;
            }
            if ((o = data["StatusBar"]["RAM"].ToBool()) != null)
            {
                StatusBar.RAM = (bool)o;
            }
            if ((o = data["StatusBar"]["SamplesDisplay"].ToBool()) != null)
            {
                StatusBar.SamplesDisplay = (bool)o;
            }
            if ((o = data["StatusBar"]["SearchDelay"].ToBool()) != null)
            {
                StatusBar.SearchDelay = (bool)o;
            }
            if ((o = data["StatusBar"]["PreAnalyse"].ToBool()) != null)
            {
                StatusBar.PreAnalyse = (bool)o;
            }
            if ((o = data["StatusBar"]["StreamingType"].ToBool()) != null)
            {
                StatusBar.StreamingType = (bool)o;
            }
            if ((o = data["StatusBar"]["Size"].ToBool()) != null)
            {
                StatusBar.Size = (bool)o;
            }
            if ((o = data["StatusBar"]["Conversion"].ToBool()) != null)
            {
                StatusBar.Conversion = (bool)o;
            }

            if ((o = data.Global["StreamingType"].ToEnum <StreamingType>()) != null)
            {
                Settings.StreamingType = (StreamingType)o;
            }

            //if ((o = data["AdditionalFormats"]["DKCTFCSMP"].ToBool()) != null) AdditionalFormats.DKCTFCSMP = (bool)o;

            if ((o = data["Colors"]["Foreground"].ToColor()) != null)
            {
                Color ocolor = (Color)o;

                Application.Current.Resources["ForegroundBrush"]          = new SolidColorBrush(ocolor).GetAsTypedFrozen();
                Application.Current.Resources["ForegroundBrush_Disabled"] = new SolidColorBrush(Color.FromArgb(80, ocolor.R, ocolor.G, ocolor.B)).GetAsTypedFrozen();
            }
            if ((o = data["Colors"]["Background"].ToColor()) != null)
            {
                Color ocolor = (Color)o;

                Application.Current.Resources["BackgroundBrush"]          = new SolidColorBrush(ocolor).GetAsTypedFrozen();
                Application.Current.Resources["BackgroundBrush_Disabled"] = new SolidColorBrush(Color.FromArgb(80, ocolor.R, ocolor.G, ocolor.B)).GetAsTypedFrozen();
            }
            if ((o = data["Colors"]["Error"].ToColor()) != null)
            {
                Color ocolor = (Color)o;

                Application.Current.Resources["ErrorBrush"]          = new SolidColorBrush(ocolor).GetAsTypedFrozen();
                Application.Current.Resources["ErrorBrush_Disabled"] = new SolidColorBrush(Color.FromArgb(80, ocolor.R, ocolor.G, ocolor.B)).GetAsTypedFrozen();

                foreach (Fichier fichier in tasklist.Files)
                {
                    fichier.RefreshValidity();
                }
            }

            RefreshInfos();
            UpdateStatusBar(false, true);
        }
Example #2
0
        /// <summary>
        /// À partir d'un nom de fichier, obtient un fichier analysé uniquement s'il possède l'en-tête RFRM CSMP.
        /// </summary>
        /// <param name="fileName">Nom du fichier.</param>
        /// <param name="outData">Données complémentaires pour le fichier.</param>
        /// <param name="cancellationToken">Jeton d'annulation qui peut être utilisé par d'autres objets ou threads pour être informés de l'annulation.</param>
        /// <returns>Le fichier analysé.</returns>
        public static async Task <Fichier> GetFile(string fileName, FichierOutData outData = default, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested || !File.Exists(fileName))
            {
                return(null);
            }

            IEnumerable <string> filesToDelete = null;

            try
            {
                ScanningCount++;
                var(dspFileNames, channelsCount) = await GetDSPFiles(fileName, VGMStreamProcessTypes.Metadata, 1, cancellationToken);

                if ((filesToDelete = dspFileNames) == null)
                {
                    return(null);
                }

                Process vgmstreamprocess = new Process()
                {
                    StartInfo = VGMStream.StartInfo(dspFileNames[0], VGMStreamProcessTypes.Metadata)
                };
                VGMStream.RunningProcess.Add(vgmstreamprocess, VGMStreamProcessTypes.Metadata);

                cancellationToken.Register(() =>
                {
                    vgmstreamprocess.TryKill();
                    if (VGMStream.RunningProcess.ContainsKey(vgmstreamprocess))
                    {
                        VGMStream.RunningProcess.Remove(vgmstreamprocess);
                    }
                });

                TryResult StartResult = await vgmstreamprocess.TryStartAsync(cancellationToken); //Start

                if (!StartResult.Result)                                                         //N'a pas pu être démarré
                {
                    if (!(StartResult.Exception is OperationCanceledException))
                    {
                        MessageBox.Show(StartResult.Exception.Message, App.Str("TT_Error"), MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                    return(null);
                }

                await vgmstreamprocess.WaitForExitAsync(cancellationToken); //WaitForExit

                if (VGMStream.RunningProcess.ContainsKey(vgmstreamprocess))
                {
                    VGMStream.RunningProcess.Remove(vgmstreamprocess);
                }

                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }

                string[] s = vgmstreamprocess.StandardOutput.ReadAllLines();

                if (s.IsNullOrEmpty())
                {
                    return(null);
                }

                var fichier = VGMStream.GetFile(s, outData, false, false);

                if (cancellationToken.IsCancellationRequested)
                {
                    return(null);
                }
                else if (fichier.Invalid)
                {
                    return(fichier);
                }
                else
                {
                    fichier.Path           = fileName;
                    fichier.OriginalFormat = "Retro Studios DKCTF CSMP";
                    fichier.Channels       = channelsCount;
                    fichier.Bitrate       *= channelsCount;
                    return(fichier);
                }
            }
            catch (OperationCanceledException) { return(null); }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, App.Str("TT_Error"), MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }
            finally
            {
                if (!cancellationToken.IsCancellationRequested)
                {
                    await VGMStream.DeleteTempFilesByName(filesToDelete);
                }
                ScanningCount--;
            }
        }