Exemplo n.º 1
0
        private void saveFile()
        {
            var fileChooser = new FileChooserDialog(
                "Save File (*.clong)", this, FileChooserAction.Save,
                "Cancel", ResponseType.Cancel,
                "Save As", ResponseType.Accept
                );

            fileChooser.Filter = new FileFilter();
            fileChooser.Filter.AddPattern("*.clong");
            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                FileManager.Save(
                    fileChooser.Filename,
                    docView.GetText(),
                    exView.Examples,
                    dictView.Words
                    );
                currentFile = fileChooser.Filename;
                Title       = AppSettings.WindowTitle + " - " + currentFile;
                var popup = new Dialog(
                    "Success", this, DialogFlags.DestroyWithParent
                    );
                popup.ContentArea.Add(new Label("Successfully saved!"));
                popup.AddButton("Okay", ResponseType.Accept);
                popup.ShowAll();
                popup.Resizable = false;
                popup.Run();
                popup.Dispose();
            }
            fileChooser.Dispose();
        }
Exemplo n.º 2
0
 void Button6_Activated(object sender, EventArgs e)
 {
     try
     {
         FileChooserDialog fileChooserDialog = new FileChooserDialog("Select project file", null, FileChooserAction.Open, new object[0]);
         fileChooserDialog.AddButton(Stock.Cancel, ResponseType.Cancel);
         fileChooserDialog.AddButton(Stock.Open, ResponseType.Ok);
         fileChooserDialog.DefaultResponse = ResponseType.Ok;
         fileChooserDialog.SelectMultiple  = false;
         FileFilter fileFilter = new FileFilter();
         fileFilter.AddMimeType("application/json");
         fileFilter.AddPattern("project.json");
         fileFilter.Name = "iCode project file (project.json)";
         fileChooserDialog.AddFilter(fileFilter);
         bool flag = fileChooserDialog.Run() == -5;
         if (flag)
         {
             ProjectManager.LoadProject(fileChooserDialog.Filename);
         }
         fileChooserDialog.Dispose();
     }
     catch (Exception ex)
     {
         ExceptionWindow.Create(ex, this).ShowAll();
     }
 }
Exemplo n.º 3
0
 public static string?SelectFile(Window parent)
 {
     using var fc = new FileChooserDialog("XDM", parent, FileChooserAction.Open);
     try
     {
         if (parent.Group != null)
         {
             parent.Group.AddWindow(fc);
         }
         fc.AddButton(Stock.Save, ResponseType.Accept);
         fc.AddButton(Stock.Cancel, ResponseType.Cancel);
         if (fc.Run() == (int)ResponseType.Accept)
         {
             return(fc.Filename);
         }
         return(null);
     }
     finally
     {
         if (parent.Group != null)
         {
             parent.Group.RemoveWindow(fc);
         }
         fc.Destroy();
         fc.Dispose();
     }
 }
Exemplo n.º 4
0
        private void openFile()
        {
            var fileChooser = new FileChooserDialog(
                "Open File", this, FileChooserAction.Open,
                "Cancel", ResponseType.Cancel,
                "Open", ResponseType.Accept
                );

            fileChooser.Filter = new FileFilter();
            fileChooser.Filter.AddPattern("*.clong");
            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                newFile();

                var fileTuple = FileManager.Open(fileChooser.Filename);

                docView.SetText(fileTuple.Item1);
                exView.UpdateExamples(fileTuple.Item2.Item1);
                dictView.UpdateWords(fileTuple.Item2.Item2);

                currentFile = fileChooser.Filename;
                Title       = AppSettings.WindowTitle + " - " + currentFile;
            }
            fileChooser.Dispose();
        }
Exemplo n.º 5
0
    //Exportování dat návrháře do nového CSV souboru
    protected void OnExportActionActivated(object sender, EventArgs e)
    {
        //Vytvoření dialogu otevření souboru
        var filedlg = new FileChooserDialog("Uložit soubor", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel, "Save", ResponseType.Accept);
        var filter  = new FileFilter();

        filter.Name = "*.csv";
        filter.AddPattern("*.csv");
        filedlg.AddFilter(filter);
        var result = filedlg.Run();

        if (result == (int)ResponseType.Accept)
        {
            //Při exportu se data prakticky jen přepíšou, protože návrhář je vždy ukládá do souboru
            var    data     = System.IO.File.ReadLines(Constants.CSV_FILE_NAME);
            string csv      = string.Join(Environment.NewLine, data.Select(s => s));
            string filename = filedlg.Filename;
            //Pokud název souboru ještě nemá příponu, tak ji připojíme
            if (!System.Text.RegularExpressions.Regex.IsMatch(filename, @".+\..+"))
            {
                filename += @".csv";
            }
            //Vypsání dat do souboru
            System.IO.File.WriteAllText(filename, csv);
        }
        filedlg.Destroy();
        filedlg.Dispose();
    }
Exemplo n.º 6
0
        private void BtnLoad_Click(object sender, EventArgs e)
        {
            var dialog = new FileChooserDialog(
                "Load configuration",
                this,
                FileChooserAction.Open);

            dialog.AddButton(Stock.Cancel, ResponseType.Cancel);
            dialog.AddButton(Stock.Open, ResponseType.Ok);
            dialog.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            dialog.SelectMultiple = false;

            var response = (ResponseType)dialog.Run();

            if (response == ResponseType.Ok)
            {
                if (_sikInterface.LoadParamsFromFile(dialog.Filename))
                {
                    _sikInterface.SiKConfig.PropertyChanged += _boardIdentifiers.SiKConfig_PropertyChanged;
                    _dataTableControls.CreateBindings(_sikInterface.SiKConfig);
                    StatusMessage = "Parameters loaded from a config file.";
                }
                else
                {
                    StatusMessage = "Failed to load the parameters.";
                }
            }
            dialog.Dispose();
        }
Exemplo n.º 7
0
        private void BtnSave_Click(object sender, EventArgs e)
        {
            var dialog = new FileChooserDialog(
                "Save configuration",
                this,
                FileChooserAction.Save);

            dialog.AddButton(Stock.Cancel, ResponseType.Cancel);
            dialog.AddButton(Stock.Save, ResponseType.Ok);
            dialog.SetCurrentFolder(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            dialog.SelectMultiple = false;

            var response = (ResponseType)dialog.Run();

            if (response == ResponseType.Ok)
            {
                if (_sikInterface.SaveParamsToFile(dialog.Filename))
                {
                    StatusMessage = "Parameters saved to a backup file.";
                }
                else
                {
                    StatusMessage = "Failed to save the parameters file.";
                }
            }
            dialog.Dispose();
        }
Exemplo n.º 8
0
        public void saveFile(object sender, EventArgs args)
        {
            FileChooserDialog filesaveDialog = new FileChooserDialog("Save File", this, FileChooserAction.Save);

            filesaveDialog.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
            filesaveDialog.AddButton(Gtk.Stock.Save, Gtk.ResponseType.Ok);
            if (!File.Exists(activeFile))
            {
                var respone = filesaveDialog.Run();
                if (respone == (int)Gtk.ResponseType.Ok)
                {
                    activeFile = filesaveDialog.Filename;
                    string currentText = sourceView.Buffer.Text;
                    var    lm          = LanguageManager.Default;
                    var    lang        = lm.GuessLanguage(activeFile, "");
                    sourceView.Buffer.Language = lang;
                    if (lang != null)
                    {
                        languageSelectorButton.Label = lang.Name;
                    }
                    else
                    {
                        languageSelectorButton.Label = "Text";
                    }

                    statusBarLabel.Text = "Saved File";
                    previousText        = currentText;
                    headerBar.Subtitle  = activeFile;
                    headerBar.Title     = headerBarOringalText;
                    isChangeSaved       = true;

                    // StreamWriter writer = new StreamWriter(activeFile, false);
                    // writer.Write(currentText);
                    using (var stream = File.Create(activeFile))
                    {
                        using (TextWriter tw = new StreamWriter(stream))
                        {
                            tw.Write(currentText);
                        }
                    }
                    File.WriteAllText(activeFile, currentText);
                    // Console.WriteLine("ok");
                }
                // else if (respone == (int) Gtk.ResponseType.Cancel)
                // {
                //     Console.WriteLine("cancel");
                // }

                filesaveDialog.Dispose();
            }
            else
            {
                headerBar.Subtitle = activeFile;
                headerBar.Title    = headerBarOringalText;
                isChangeSaved      = true;
                string currentText = sourceView.Buffer.Text;
                previousText = currentText;
                File.WriteAllText(activeFile, currentText);
            }
        }
Exemplo n.º 9
0
 public static string?SaveFile(Window parent, string?path)
 {
     using var fc = new FileChooserDialog("XDM", parent, FileChooserAction.Save);
     if (!string.IsNullOrEmpty(path))
     {
         var dir = Path.GetDirectoryName(path);
         fc.SetFilename(Path.GetFileName(path));
         fc.SetCurrentFolderFile(GLib.FileFactory.NewForPath(dir));
     }
     try
     {
         if (parent.Group != null)
         {
             parent.Group.AddWindow(fc);
         }
         fc.AddButton(Stock.Save, ResponseType.Accept);
         fc.AddButton(Stock.Cancel, ResponseType.Cancel);
         if (fc.Run() == (int)ResponseType.Accept)
         {
             return(fc.Filename);
         }
         return(null);
     }
     finally
     {
         if (parent.Group != null)
         {
             parent.Group.RemoveWindow(fc);
         }
         fc.Destroy();
         fc.Dispose();
     }
 }
Exemplo n.º 10
0
        private void SaveClick(object obj, EventArgs args)
        {
            string contents = CreateString();

            FileChooserDialog saveFile = new FileChooserDialog("Save File", this, FileChooserAction.Save, "Cancel", ResponseType.Cancel,
                                                               "Save", ResponseType.Accept);

            if (saveFile.Run() == (int)ResponseType.Accept)
            {
                WriteFile(contents, saveFile.Filename);
                saveFile.Dispose();
            }
            else
            {
                saveFile.Dispose();
            }
        }
Exemplo n.º 11
0
        private void Load_Application_Folder(object sender, EventArgs args)
        {
            FileChooserDialog fileChooser = new FileChooserDialog("Choose the folder to open", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);

            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                LoadApplication(fileChooser.Filename);
            }

            fileChooser.Dispose();
        }
Exemplo n.º 12
0
        private void BrowseDir_Pressed(object sender, EventArgs args)
        {
            FileChooserDialog fileChooser = new FileChooserDialog("Choose the game directory to add to the list", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Add", ResponseType.Accept);

            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                _gameDirsBoxStore.AppendValues(fileChooser.Filename);
            }

            fileChooser.Dispose();

            _browseDir.SetStateFlags(0, true);
        }
Exemplo n.º 13
0
        /// <summary/>
        protected virtual void Dispose(bool fDisposing)
        {
            System.Diagnostics.Debug.WriteLineIf(!fDisposing, "****** Missing Dispose() call for " + GetType() + ". *******");
            if (fDisposing && m_dlg != null)
            {
                ResetFilter(m_dlg);

                //Don't forget to call Destroy() or the dialog window won't get closed.
                m_dlg.Destroy();
                m_dlg.Dispose();

                OnDisposed(EventArgs.Empty);
            }
            m_dlg = null;
        }
Exemplo n.º 14
0
        private void BrowseThemeDir_Pressed(object sender, EventArgs args)
        {
            FileChooserDialog fileChooser = new FileChooserDialog("Choose the theme to load", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Select", ResponseType.Accept);

            fileChooser.Filter = new FileFilter();
            fileChooser.Filter.AddPattern("*.css");

            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                _custThemePath.Buffer.Text = fileChooser.Filename;
            }

            fileChooser.Dispose();

            _browseThemePath.SetStateFlags(0, true);
        }
Exemplo n.º 15
0
        private void AddDir_Pressed(object sender, EventArgs args)
        {
            if (Directory.Exists(_addGameDirBox.Buffer.Text))
            {
                _gameDirsBoxStore.AppendValues(_addGameDirBox.Buffer.Text);
            }
            else
            {
                FileChooserDialog fileChooser = new FileChooserDialog("Choose the game directory to add to the list", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Add", ResponseType.Accept)
                {
                    SelectMultiple = true
                };

                if (fileChooser.Run() == (int)ResponseType.Accept)
                {
                    foreach (string directory in fileChooser.Filenames)
                    {
                        bool directoryAdded = false;

                        if (_gameDirsBoxStore.GetIterFirst(out TreeIter treeIter))
                        {
                            do
                            {
                                if (directory.Equals((string)_gameDirsBoxStore.GetValue(treeIter, 0)))
                                {
                                    directoryAdded = true;
                                    break;
                                }
                            } while(_gameDirsBoxStore.IterNext(ref treeIter));
                        }

                        if (!directoryAdded)
                        {
                            _gameDirsBoxStore.AppendValues(directory);
                        }
                    }
                }

                fileChooser.Dispose();
            }

            _addGameDirBox.Buffer.Text = "";

            ((ToggleButton)sender).SetStateFlags(0, true);
        }
Exemplo n.º 16
0
        private void Load_Application_File(object sender, EventArgs args)
        {
            FileChooserDialog fileChooser = new FileChooserDialog("Choose the file to open", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);

            fileChooser.Filter = new FileFilter();
            fileChooser.Filter.AddPattern("*.nsp");
            fileChooser.Filter.AddPattern("*.pfs0");
            fileChooser.Filter.AddPattern("*.xci");
            fileChooser.Filter.AddPattern("*.nca");
            fileChooser.Filter.AddPattern("*.nro");
            fileChooser.Filter.AddPattern("*.nso");

            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                LoadApplication(fileChooser.Filename);
            }

            fileChooser.Dispose();
        }
Exemplo n.º 17
0
        public void openFile(object sender, EventArgs args)
        {
            String            text;
            FileChooserDialog fileopenDialog = new FileChooserDialog("Open File", this, FileChooserAction.Open);

            fileopenDialog.AddButton(Gtk.Stock.Cancel, Gtk.ResponseType.Cancel);
            fileopenDialog.AddButton(Gtk.Stock.Open, Gtk.ResponseType.Ok);
            var respone = fileopenDialog.Run();

            if (respone == (int)Gtk.ResponseType.Ok)
            {
                activeFile = fileopenDialog.Filename;
                // Console.WriteLine(activeFile);
                headerBar.Subtitle = activeFile;
                text = File.ReadAllText(activeFile);
                var lm   = LanguageManager.Default;
                var lang = lm.GuessLanguage(activeFile, "");
                // if(lang!=null) Console.WriteLine(lang.Name);
                sourceView.Buffer.Language = lang;
                if (lang != null)
                {
                    languageSelectorButton.Label = lang.Name;
                }
                else
                {
                    languageSelectorButton.Label = "Text";
                }
                statusBarLabel.Text = "Opened File";

                sourceView.Buffer.Text = text;
                headerBar.Title        = headerBarOringalText;
                // defaultTextList = Regex.Split(textView.Buffer.Text, @"(\s+|\n+)").ToList();
                // defaultText = text;
                isChangeSaved = true;
            }
            // else if (respone == (int) Gtk.ResponseType.Cancel)
            // {
            //
            // }
            fileopenDialog.Dispose();
        }
Exemplo n.º 18
0
    protected void ImportData()
    {
        //Testování, jestli se server připojený k DB
        if (!this.server.isConnected)
        {
            var dial = new MessageDialog(this, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Připojte se k databázi.");
            if (dial.Run() == (int)ResponseType.Ok)
            {
                dial.Destroy();
                dial.Dispose();
            }
        }

        //Import maže všechna dosavadní data, aby nedocházelo ke konfliktům v DB
        var dail = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.OkCancel, @"Import přemaže všechna vaše dosavadní data, jste si jistí?");

        if (dail.Run() == (int)ResponseType.Ok)
        {
            dail.Destroy();
            dail.Dispose();
        }
        else
        {
            return;
        }

        //Dialog na zvolení souboru
        var        filedlg = new FileChooserDialog("Choose file", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept);
        FileFilter filter  = new FileFilter();

        filter.Name = "CSV files";
        filter.AddPattern("*.csv");
        filedlg.AddFilter(filter);
        if (filedlg.Run() == (int)ResponseType.Accept)
        {
            var data = System.IO.File.ReadLines(filedlg.Filename);
            server.ImportData(data);
        }
        filedlg.Destroy();
        filedlg.Dispose();
    }
Exemplo n.º 19
0
    protected void OnOpenActionActivated(object sender, EventArgs e)
    {
        Gtk.FileChooserDialog dialog = new FileChooserDialog("Select the oracles disassembly base directory",
                                                             mainWindow,
                                                             FileChooserAction.SelectFolder,
                                                             "Cancel", ResponseType.Cancel,
                                                             "Select Folder", ResponseType.Accept);
        dialog.LocalOnly = false;
        ResponseType response = (ResponseType)dialog.Run();

        if (response == ResponseType.Accept)
        {
            ResponseType r2 = AskSave("Save project before closing it?");
            if (r2 != ResponseType.Cancel)
            {
                string basedir = dialog.Filename;
                OpenProject(basedir);
            }
        }
        dialog.Dispose();
    }
Exemplo n.º 20
0
        private void ProfileImageFileChooser()
        {
            FileChooserDialog fileChooser = new FileChooserDialog("Import Custom Profile Image", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Import", ResponseType.Accept)
            {
                SelectMultiple = false,
                Filter         = new FileFilter()
            };

            fileChooser.SetPosition(WindowPosition.Center);
            fileChooser.Filter.AddPattern("*.jpg");
            fileChooser.Filter.AddPattern("*.jpeg");
            fileChooser.Filter.AddPattern("*.png");
            fileChooser.Filter.AddPattern("*.bmp");

            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                ProcessProfileImage(File.ReadAllBytes(fileChooser.Filename));
            }

            fileChooser.Dispose();
        }
Exemplo n.º 21
0
        private void AddButton_Clicked(object sender, EventArgs args)
        {
            FileChooserDialog fileChooser = new FileChooserDialog("Select update files", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Add", ResponseType.Accept)
            {
                SelectMultiple = true,
                Filter         = new FileFilter()
            };

            fileChooser.SetPosition(WindowPosition.Center);
            fileChooser.Filter.AddPattern("*.nsp");

            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                foreach (string path in fileChooser.Filenames)
                {
                    AddUpdate(path);
                }
            }

            fileChooser.Dispose();
        }
Exemplo n.º 22
0
        private void AddDir_Pressed(object sender, EventArgs args)
        {
            if (Directory.Exists(_addGameDirBox.Buffer.Text))
            {
                _gameDirsBoxStore.AppendValues(_addGameDirBox.Buffer.Text);
            }
            else
            {
                FileChooserDialog fileChooser = new FileChooserDialog("Choose the game directory to add to the list", this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Add", ResponseType.Accept);

                if (fileChooser.Run() == (int)ResponseType.Accept)
                {
                    _gameDirsBoxStore.AppendValues(fileChooser.Filename);
                }

                fileChooser.Dispose();
            }

            _addGameDirBox.Buffer.Text = "";

            ((ToggleButton)sender).SetStateFlags(0, true);
        }
Exemplo n.º 23
0
    protected void Quit()
    {
        if (OriginalImage != null)
        {
            OriginalImage.Dispose();
        }

        if (ImageLoader != null)
        {
            ImageLoader.Dispose();
        }

        if (ImageSaver != null)
        {
            ImageSaver.Dispose();
        }

        if (FolderChooser != null)
        {
            FolderChooser.Dispose();
        }

        Application.Quit();
    }
Exemplo n.º 24
0
        private void HandleInstallerDialog(FileChooserDialog fileChooser)
        {
            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                try
                {
                    string filename = fileChooser.Filename;

                    fileChooser.Dispose();

                    SystemVersion firmwareVersion = _contentManager.VerifyFirmwarePackage(filename);

                    string dialogTitle = $"Install Firmware {firmwareVersion.VersionString}";

                    if (firmwareVersion == null)
                    {
                        GtkDialog.CreateErrorDialog($"A valid system firmware was not found in {filename}.");

                        return;
                    }

                    SystemVersion currentVersion = _contentManager.GetCurrentFirmwareVersion();

                    string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed.";

                    if (currentVersion != null)
                    {
                        dialogMessage += $"\n\nThis will replace the current system version {currentVersion.VersionString}. ";
                    }

                    dialogMessage += "\n\nDo you want to continue?";

                    ResponseType responseInstallDialog = (ResponseType)GtkDialog.CreateConfirmationDialog(dialogTitle, dialogMessage).Run();

                    MessageDialog waitingDialog = GtkDialog.CreateWaitingDialog(dialogTitle, "Installing firmware...");

                    if (responseInstallDialog == ResponseType.Yes)
                    {
                        Logger.Info?.Print(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");

                        Thread thread = new Thread(() =>
                        {
                            Application.Invoke(delegate
                            {
                                waitingDialog.Run();
                            });

                            try
                            {
                                _contentManager.InstallFirmware(filename);

                                Application.Invoke(delegate
                                {
                                    waitingDialog.Dispose();

                                    string message = $"System version {firmwareVersion.VersionString} successfully installed.";

                                    GtkDialog.CreateInfoDialog(dialogTitle, message);
                                    Logger.Info?.Print(LogClass.Application, message);
                                });
                            }
                            catch (Exception ex)
                            {
                                Application.Invoke(delegate
                                {
                                    waitingDialog.Dispose();

                                    GtkDialog.CreateErrorDialog(ex.Message);
                                });
                            }
                            finally
                            {
                                RefreshFirmwareLabel();
                            }
                        });

                        thread.Name = "GUI.FirmwareInstallerThread";
                        thread.Start();
                    }
                }
                catch (LibHac.MissingKeyException ex)
                {
                    Logger.Error?.Print(LogClass.Application, ex.ToString());
                    UserErrorDialog.CreateUserErrorDialog(UserError.NoKeys);
                }
                catch (Exception ex)
                {
                    GtkDialog.CreateErrorDialog(ex.Message);
                }
            }
            else
            {
                fileChooser.Dispose();
            }
        }
Exemplo n.º 25
0
        private void ExtractSection(NcaSectionType ncaSectionType)
        {
            FileChooserDialog fileChooser = new FileChooserDialog("Choose the folder to extract into", null, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Extract", ResponseType.Accept);

            fileChooser.SetPosition(WindowPosition.Center);

            int    response    = fileChooser.Run();
            string destination = fileChooser.Filename;

            fileChooser.Dispose();

            if (response == (int)ResponseType.Accept)
            {
                Thread extractorThread = new Thread(() =>
                {
                    string sourceFile = _gameTableStore.GetValue(_rowIter, 9).ToString();

                    Gtk.Application.Invoke(delegate
                    {
                        _dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Cancel, null)
                        {
                            Title          = "Ryujinx - NCA Section Extractor",
                            Icon           = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png"),
                            SecondaryText  = $"Extracting {ncaSectionType} section from {System.IO.Path.GetFileName(sourceFile)}...",
                            WindowPosition = WindowPosition.Center
                        };

                        int dialogResponse = _dialog.Run();
                        if (dialogResponse == (int)ResponseType.Cancel || dialogResponse == (int)ResponseType.DeleteEvent)
                        {
                            _cancel = true;
                            _dialog.Dispose();
                        }
                    });

                    using (FileStream file = new FileStream(sourceFile, FileMode.Open, FileAccess.Read))
                    {
                        Nca mainNca  = null;
                        Nca patchNca = null;

                        if ((System.IO.Path.GetExtension(sourceFile).ToLower() == ".nsp") ||
                            (System.IO.Path.GetExtension(sourceFile).ToLower() == ".pfs0") ||
                            (System.IO.Path.GetExtension(sourceFile).ToLower() == ".xci"))
                        {
                            PartitionFileSystem pfs;

                            if (System.IO.Path.GetExtension(sourceFile) == ".xci")
                            {
                                Xci xci = new Xci(_virtualFileSystem.KeySet, file.AsStorage());

                                pfs = xci.OpenPartition(XciPartitionType.Secure);
                            }
                            else
                            {
                                pfs = new PartitionFileSystem(file.AsStorage());
                            }

                            foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
                            {
                                pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();

                                Nca nca = new Nca(_virtualFileSystem.KeySet, ncaFile.AsStorage());

                                if (nca.Header.ContentType == NcaContentType.Program)
                                {
                                    int dataIndex = Nca.GetSectionIndexFromType(NcaSectionType.Data, NcaContentType.Program);

                                    if (nca.Header.GetFsHeader(dataIndex).IsPatchSection())
                                    {
                                        patchNca = nca;
                                    }
                                    else
                                    {
                                        mainNca = nca;
                                    }
                                }
                            }
                        }
                        else if (System.IO.Path.GetExtension(sourceFile).ToLower() == ".nca")
                        {
                            mainNca = new Nca(_virtualFileSystem.KeySet, file.AsStorage());
                        }

                        if (mainNca == null)
                        {
                            Logger.PrintError(LogClass.Application, "Extraction failed. The main NCA was not present in the selected file.");

                            Gtk.Application.Invoke(delegate
                            {
                                GtkDialog.CreateErrorDialog("Extraction failed. The main NCA was not present in the selected file.");
                            });

                            return;
                        }

                        int index = Nca.GetSectionIndexFromType(ncaSectionType, mainNca.Header.ContentType);

                        IFileSystem ncaFileSystem = patchNca != null ? mainNca.OpenFileSystemWithPatch(patchNca, index, IntegrityCheckLevel.ErrorOnInvalid)
                                                                     : mainNca.OpenFileSystem(index, IntegrityCheckLevel.ErrorOnInvalid);

                        FileSystemClient fsClient = _virtualFileSystem.FsClient;

                        string source = DateTime.Now.ToFileTime().ToString().Substring(10);
                        string output = DateTime.Now.ToFileTime().ToString().Substring(10);

                        fsClient.Register(source.ToU8Span(), ncaFileSystem);
                        fsClient.Register(output.ToU8Span(), new LocalFileSystem(destination));

                        (Result? resultCode, bool canceled) = CopyDirectory(fsClient, $"{source}:/", $"{output}:/");

                        if (!canceled)
                        {
                            if (resultCode.Value.IsFailure())
                            {
                                Logger.PrintError(LogClass.Application, $"LibHac returned error code: {resultCode.Value.ErrorCode}");

                                Gtk.Application.Invoke(delegate
                                {
                                    _dialog?.Dispose();

                                    GtkDialog.CreateErrorDialog("Extraction failed. Read the log file for further information.");
                                });
                            }
                            else if (resultCode.Value.IsSuccess())
                            {
                                Gtk.Application.Invoke(delegate
                                {
                                    _dialog?.Dispose();

                                    MessageDialog dialog = new MessageDialog(null, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Ok, null)
                                    {
                                        Title          = "Ryujinx - NCA Section Extractor",
                                        Icon           = new Gdk.Pixbuf(Assembly.GetExecutingAssembly(), "Ryujinx.Ui.assets.Icon.png"),
                                        SecondaryText  = "Extraction has completed successfully.",
                                        WindowPosition = WindowPosition.Center
                                    };

                                    dialog.Run();
                                    dialog.Dispose();
                                });
                            }
                        }

                        fsClient.Unmount(source.ToU8Span());
                        fsClient.Unmount(output.ToU8Span());
                    }
                });

                extractorThread.Name         = "GUI.NcaSectionExtractorThread";
                extractorThread.IsBackground = true;
                extractorThread.Start();
            }
        }
Exemplo n.º 26
0
 private void Window_DeleteEvent(object sender, DeleteEventArgs e)
 {
     chooserDialog.Dispose();
     Application.Quit();
 }
Exemplo n.º 27
0
        static MenuBar CreateMenuBar(Window parent)
        {
            MenuItem open = new MenuItem("Open...");

            open.Activated += (object?sender, EventArgs e) =>
            {
                FileChooserDialog fcd = new FileChooserDialog("Open Project", parent, FileChooserAction.Open,
                                                              Stock.Open, ResponseType.Ok,
                                                              Stock.Cancel, ResponseType.Cancel);
                fcd.SelectMultiple = false;
                AddFilters(fcd);

                if (fcd.Run() == (int)ResponseType.Ok)
                {
                    try
                    {
                        FileManager.Load(fcd.Filename);

                        Console.WriteLine($"Successfully read and parsed project file { fcd.Filename }.");
                        Console.WriteLine($"- wires: { FileManager.Wires }");
                        Console.WriteLine($"- components: { FileManager.Components }");
                        Console.WriteLine($"- labels: { FileManager.Labels }");
                    }
                    catch (Exception err)
                    {
                        // FIXME: Do something if parse fails?

                        Output.WriteError($"Failed to read and parse project file { fcd.Filename }.", err);
                    }
                }

                fcd.Dispose();
            };

            MenuItem saveAs = new MenuItem("Save As...");

            saveAs.Activated += (object?sender, EventArgs e) =>
            {
                FileChooserDialog fcd = new FileChooserDialog("Save Project", parent, FileChooserAction.Open,
                                                              Stock.Save, ResponseType.Ok,
                                                              Stock.Cancel, ResponseType.Cancel);
                AddFilters(fcd);

                if (fcd.Run() == (int)ResponseType.Ok)
                {
                    try
                    {
                        FileManager.Save(fcd.Filename);

                        Console.WriteLine($"Successfully saved and parsed project file { fcd.Filename }.");
                        Console.WriteLine($"- wires: { FileManager.Wires }");
                        Console.WriteLine($"- components: { FileManager.Components }");
                        Console.WriteLine($"- labels: { FileManager.Labels }");
                    }
                    catch (Exception err)
                    {
                        // FIXME: Do something if parse fails?

                        Output.WriteError($"Failed to write and parse project file { fcd.Filename }.", err);
                    }
                }

                fcd.Dispose();
            };

            MenuItem save = new MenuItem("Save...");

            save.Activated += (object?sender, EventArgs e) =>
            {
                if (FileManager.IsNew)
                {
                    saveAs.Activate();
                }
                else
                {
                    FileManager.Save();
                }
            };

            Menu fileMenu = new Menu();

            fileMenu.Append(open);
            fileMenu.Append(save);
            fileMenu.Append(saveAs);

            MenuItem file = new MenuItem("File");

            file.AddEvents((int)Gdk.EventMask.AllEventsMask);
            file.Submenu = fileMenu;

            // FIXME: Hook up callbacks

            // FIXME: On windows (and Mac) there should be no delay
            // on the ability to close the menu when you've opened it.
            // Atm there is a delay after opening the menu and when
            // you can close it...

            MenuBar bar = new MenuBar();

            bar.Append(file);

            return(bar);
        }
Exemplo n.º 28
0
        private void HandleInstallerDialog(FileChooserDialog fileChooser)
        {
            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                MessageDialog dialog = null;

                try
                {
                    string filename = fileChooser.Filename;

                    fileChooser.Dispose();

                    var firmwareVersion = _contentManager.VerifyFirmwarePackage(filename);

                    if (firmwareVersion == null)
                    {
                        dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");

                        dialog.Text = "Firmware not found.";

                        dialog.SecondaryText = $"A valid system firmware was not found in {filename}.";

                        Logger.PrintError(LogClass.Application, $"A valid system firmware was not found in {filename}.");

                        dialog.Run();
                        dialog.Hide();
                        dialog.Dispose();

                        return;
                    }

                    var currentVersion = _contentManager.GetCurrentFirmwareVersion();

                    string dialogMessage = $"System version {firmwareVersion.VersionString} will be installed.";

                    if (currentVersion != null)
                    {
                        dialogMessage += $"This will replace the current system version {currentVersion.VersionString}. ";
                    }

                    dialogMessage += "Do you want to continue?";

                    dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Question, ButtonsType.YesNo, false, "");

                    dialog.Text          = $"Install Firmware {firmwareVersion.VersionString}";
                    dialog.SecondaryText = dialogMessage;

                    int response = dialog.Run();

                    dialog.Dispose();

                    dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.None, false, "");

                    dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";

                    dialog.SecondaryText = "Installing firmware...";

                    if (response == (int)ResponseType.Yes)
                    {
                        Logger.PrintInfo(LogClass.Application, $"Installing firmware {firmwareVersion.VersionString}");

                        Thread thread = new Thread(() =>
                        {
                            GLib.Idle.Add(new GLib.IdleHandler(() =>
                            {
                                dialog.Run();
                                return(false);
                            }));

                            try
                            {
                                _contentManager.InstallFirmware(filename);

                                GLib.Idle.Add(new GLib.IdleHandler(() =>
                                {
                                    dialog.Dispose();

                                    dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");

                                    dialog.Text = $"Install Firmware {firmwareVersion.VersionString}";

                                    dialog.SecondaryText = $"System version {firmwareVersion.VersionString} successfully installed.";

                                    Logger.PrintInfo(LogClass.Application, $"System version {firmwareVersion.VersionString} successfully installed.");

                                    dialog.Run();
                                    dialog.Dispose();

                                    return(false);
                                }));
                            }
                            catch (Exception ex)
                            {
                                GLib.Idle.Add(new GLib.IdleHandler(() =>
                                {
                                    dialog.Dispose();

                                    dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");

                                    dialog.Text = $"Install Firmware {firmwareVersion.VersionString} Failed.";

                                    dialog.SecondaryText = $"An error occured while installing system version {firmwareVersion.VersionString}." +
                                                           " Please check logs for more info.";

                                    Logger.PrintError(LogClass.Application, ex.Message);

                                    dialog.Run();
                                    dialog.Dispose();

                                    return(false);
                                }));
                            }
                            finally
                            {
                                RefreshFirmwareLabel();
                            }
                        });

                        thread.Name = "GUI.FirmwareInstallerThread";
                        thread.Start();
                    }
                    else
                    {
                        dialog.Dispose();
                    }
                }
                catch (Exception ex)
                {
                    if (dialog != null)
                    {
                        dialog.Dispose();
                    }

                    dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Info, ButtonsType.Ok, false, "");

                    dialog.Text = "Parsing Firmware Failed.";

                    dialog.SecondaryText = "An error occured while parsing firmware. Please check the logs for more info.";

                    Logger.PrintError(LogClass.Application, ex.Message);

                    dialog.Run();
                    dialog.Dispose();
                }
            }
            else
            {
                fileChooser.Dispose();
            }
        }
Exemplo n.º 29
0
        private void AddButton_Clicked(object sender, EventArgs args)
        {
            FileChooserDialog fileChooser = new FileChooserDialog("Select DLC files", this, FileChooserAction.Open, "Cancel", ResponseType.Cancel, "Add", ResponseType.Accept)
            {
                SelectMultiple = true,
                Filter         = new FileFilter()
            };

            fileChooser.SetPosition(WindowPosition.Center);
            fileChooser.Filter.AddPattern("*.nsp");

            if (fileChooser.Run() == (int)ResponseType.Accept)
            {
                foreach (string containerPath in fileChooser.Filenames)
                {
                    if (!File.Exists(containerPath))
                    {
                        return;
                    }

                    using (FileStream containerFile = File.OpenRead(containerPath))
                    {
                        PartitionFileSystem pfs = new PartitionFileSystem(containerFile.AsStorage());
                        bool containsDlc        = false;

                        _virtualFileSystem.ImportTickets(pfs);

                        TreeIter?parentIter = null;

                        foreach (DirectoryEntryEx fileEntry in pfs.EnumerateEntries("/", "*.nca"))
                        {
                            pfs.OpenFile(out IFile ncaFile, fileEntry.FullPath.ToU8Span(), OpenMode.Read).ThrowIfFailure();

                            Nca nca = TryCreateNca(ncaFile.AsStorage(), containerPath);

                            if (nca == null)
                            {
                                continue;
                            }

                            if (nca.Header.ContentType == NcaContentType.PublicData)
                            {
                                if ((nca.Header.TitleId & 0xFFFFFFFFFFFFE000).ToString("x16") != _titleId)
                                {
                                    break;
                                }

                                parentIter ??= ((TreeStore)_dlcTreeView.Model).AppendValues(true, "", containerPath);

                                ((TreeStore)_dlcTreeView.Model).AppendValues(parentIter.Value, true, nca.Header.TitleId.ToString("X16"), fileEntry.FullPath);
                                containsDlc = true;
                            }
                        }

                        if (!containsDlc)
                        {
                            GtkDialog.CreateErrorDialog("The specified file does not contain a DLC for the selected title!");
                        }
                    }
                }
            }

            fileChooser.Dispose();
        }
Exemplo n.º 30
0
 public void Dispose()
 {
     _chooserDialog?.Dispose();
     _fileFilter?.Dispose();
     Callback = null;
 }