Пример #1
0
        private static string ShowFileDialog(bool bSaveMode, string strTitle,
                                             string strSuggestedFileName, string strFilter, int iFilterIndex,
                                             string strDefaultExt, string strContext, bool bSecureDesktop)
        {
            if (bSecureDesktop)
            {
                FileBrowserForm fbf = new FileBrowserForm();
                fbf.InitEx(bSaveMode, strTitle, KPRes.SecDeskFileDialogHint, strContext);

                try
                {
                    DialogResult drF = fbf.ShowDialog();
                    return((drF == DialogResult.OK) ? fbf.SelectedFile : null);
                }
                finally { UIUtil.DestroyForm(fbf); }
            }

            if (bSaveMode)
            {
                SaveFileDialogEx sfd = UIUtil.CreateSaveFileDialog(strTitle,
                                                                   strSuggestedFileName, strFilter, iFilterIndex, strDefaultExt,
                                                                   strContext);
                DialogResult drS = sfd.ShowDialog();
                return((drS == DialogResult.OK) ? sfd.FileName : null);
            }

            OpenFileDialogEx ofd = UIUtil.CreateOpenFileDialog(strTitle,
                                                               strFilter, iFilterIndex, strDefaultExt, false, strContext);
            DialogResult drO = ofd.ShowDialog();

            return((drO == DialogResult.OK) ? ofd.FileName : null);
        }
Пример #2
0
        /// <summary>
        /// Les paramètres ont été sauvegardés
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SettingsSavingEventHandler(object sender, CancelEventArgs e)
        {
            TduModdingToolsSettings set = ((TduModdingToolsSettings)sender);

            // BUG_10, BUG_82 : la mise à jour du dossier racine doit rafraîchir la liste dans le browser
            if (MainForm.Instance != null &&
                !set.TduMainFolder.Equals(tduRoot))
            {
                // Updating Modding Library
                Tools.TduPath = set.TduMainFolder;

                FileBrowserForm browser = FileBrowserForm.Instance;

                if (browser != null && browser.Visible)
                {
                    browser.MainFolderChanged();
                }

                tduRoot = null;
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            try
            {
                AttachConsole(ATTACH_PARENT_PROCESS);

                Output.Print("MCrypt v" + Application.ProductVersion.ToString());
                Output.Print("Core load");

                Output.Print("- UI culture: " + Thread.CurrentThread.CurrentUICulture);

                if (Thread.CurrentThread.CurrentCulture.Name.Contains("fr"))
                {
                    Thread.CurrentThread.CurrentUICulture = new CultureInfo("fr");
                    Output.Print("- Set UI culture to: fr");
                }

                Output.Print("- Load UI styles");
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);

                Output.Print("- Resolve emebedded dlls");
                AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(FindDLL);


                Output.Print("- Initiate core variables");
                string    path;
                CryptMode mode;

                Output.Print("Successful core load");

                // Check for updates ///////////////////////////
                firstCheckUpdatesAsync();

                // Check for args //////////////////////////////
                Output.Print("Checking launch args...");
                if (args.Length == 0)
                {
                    Output.Print("No args > launching file browser interface.");

                    FileBrowserForm fBUI = new FileBrowserForm();
                    Application.Run(fBUI);

                    if (fBUI.Mode == CryptMode.Encrypt)
                    {
                        Output.Print("Running encrypt UI to file \"" + fBUI.Path + "\"");
                        Application.Run(new EncryptForm(fBUI.Path, false));
                    }
                    else if (fBUI.Mode == CryptMode.Decrypt)
                    {
                        Output.Print("Running decrypt UI to file \"" + fBUI.Path + "\"");
                        Application.Run(new DecryptForm(fBUI.Path, false));
                    }

                    return;
                }
                else if (args.Length >= 2)
                {
                    if (args[1] == "/E")
                    {
                        mode = CryptMode.Encrypt;
                    }
                    else if (args[1] == "/D")
                    {
                        mode = CryptMode.Decrypt;
                    }
                    else
                    {
                        mode = CryptMode.Auto;
                    }
                }
                else
                {
                    mode = CryptMode.Auto;
                }

                path = args[0];
                Output.Print("Set file path to \"" + path + "\"");

                // Check if object exists
                if (!File.Exists(args[0]) && !Directory.Exists(args[0]))
                {
                    Output.Print("Specified file does not exists. Exit program.", Level.Error);
                    return;
                }
                else if (mode == CryptMode.Auto) // if it exists and that no args impose crypt mode, determine it
                {
                    if (Files.IsPathDirectory(path))
                    {
                        Output.Print("Directory detected.");
                        mode = CryptMode.Encrypt;
                    }
                    else
                    {
                        Output.Print("File detected.");
                        mode = Files.GetCryptModeByExt(path);
                    }
                }
                Output.Print("Set crypt mode to \"" + mode.ToString() + "\"");

                // Get if it is for encryption or decryption
                if (mode == CryptMode.Encrypt)
                {
                    Output.Print("Running encrypt UI to object \"" + path + "\"");
                    Application.Run(new EncryptForm(path));
                }
                else if (mode == CryptMode.Decrypt)
                {
                    Output.Print("Running decrypt UI to object \"" + path + "\"");
                    Application.Run(new DecryptForm(path));
                }
            }
            catch (Exception ex)
            {
                runExceptionMessageHandler(ex);
            }
        }
Пример #4
0
        /// <summary>
        /// Génére le menu contextuel relatif à la vue concernée
        /// </summary>
        /// <param name="baseForm">Form de base</param>
        /// <param name="args">Parameters : expected [0] viewType, [1] fileName</param>
        /// <returns></returns>
        public ContextMenuStrip CreateContextMenu(Form baseForm, params object[] args)
        {
            // Parameters
            ViewType viewType = (ViewType)args[0];
            string   fileName = args[1] as string;

            ContextMenuStrip contextMenu   = new ContextMenuStrip();
            string           fileExtension = File2.GetExtensionFromFilename(fileName);
            FileBrowserForm  browserForm   = baseForm as FileBrowserForm;

            if (browserForm == null)
            {
                return(contextMenu);
            }

            // Récupère l'éditeur par défaut pour le fichier
            string defaultEditor = FileHandler.DefaultEditor;

            if (!string.IsNullOrEmpty(fileExtension))
            {
                try
                {
                    FileHandler f = FileHandler.GetHandler(fileName);

                    // On récupère l'éditeur par réflexion
                    if (f != null)
                    {
                        PropertyInfo pi = f.GetType().GetProperty(_PROPERTY_NAME_DEFAULT_EDITOR);

                        defaultEditor = (string)pi.GetValue(f.GetType(), null);
                    }
                }
                catch (Exception ex)
                {
                    // Erreur silencieuse
                    string message = string.Format(_ERROR_DEFAULT_EDITOR, fileExtension);

                    Exception2.PrintStackTrace(new Exception(message, ex));
                }
            }

            if (viewType == ViewType.FileList)
            {
                // Liste de fichiers

                // Selon l'extension
                if (fileExtension != null)
                {
                    switch (fileExtension.ToUpper())
                    {
                    case "":
                        // Commandes communes
                        // EVO_149: Backup
                        contextMenu.Items.Add(_MENU_ITEM_BACKUP, null, browserForm.BackupTarget);
                        contextMenu.Items.Add(new ToolStripSeparator());
                        break;

                    case LibraryConstants.EXTENSION_BNK_FILE:
                        // Extract
                        contextMenu.Items.Add(_MENU_ITEM_EXTRACT_ALL, null, browserForm.ExtractAllBnkTarget);
                        contextMenu.Items.Add(new ToolStripSeparator());
                        // Backup
                        contextMenu.Items.Add(_MENU_ITEM_BACKUP, null, browserForm.BackupTarget);
                        contextMenu.Items.Add(new ToolStripSeparator());
                        break;

                    case LibraryConstants.EXTENSION_BACKUP:
                        // Restore
                        contextMenu.Items.Add(_MENU_ITEM_RESTORE, null, browserForm.RestoreTarget);
                        contextMenu.Items.Add(new ToolStripSeparator());
                        break;

                    default:
                        // Open
                        contextMenu.Items.Add(string.Format(_MENU_ITEM_OPEN, defaultEditor), null,
                                              browserForm.OpenFileTarget);
                        contextMenu.Items.Add(new ToolStripSeparator());
                        // Backup
                        contextMenu.Items.Add(_MENU_ITEM_BACKUP, null, browserForm.BackupTarget);
                        contextMenu.Items.Add(new ToolStripSeparator());
                        break;
                    }
                    // Commandes communes : Delete, Properties
                    contextMenu.Items.Add(_MENU_ITEM_DELETE, null, browserForm.DeleteFileTarget);
                    // EVO_65 : properties
                    contextMenu.Items.Add(new ToolStripSeparator());
                    contextMenu.Items.Add(_MENU_ITEM_PROPERTIES, null, browserForm.PropertiesTarget);
                }
            }
            else if (viewType == ViewType.ContentListFlat || viewType == ViewType.ContentListHierarchical)
            {
                // BNK contents
                contextMenu.Items.Add(_MENU_ITEM_REPLACE_KEEP, null, browserForm.ReplaceKeepNameTarget);
                contextMenu.Items.Add(_MENU_ITEM_REPLACE_RENAME, null, browserForm.ReplaceRenameTarget);
                contextMenu.Items.Add(new ToolStripSeparator());
                contextMenu.Items.Add(_MENU_ITEM_EXTRACT, null, browserForm.ExtractBnkTarget);
                if (browserForm._SelectedPackedFilesCount == 1)
                {
                    contextMenu.Items.Add(_MENU_ITEM_RENAME, null, browserForm.RenameTarget);
                }
                //contextMenu.Items.Add(string.Format(_MENU_ITEM_OPEN_PACKED, defaultEditor), null, browserForm.ViewContentTarget);
                contextMenu.Items.Add(string.Format(_MENU_ITEM_EDIT_PACKED, defaultEditor), null, browserForm.EditContentTarget);

                /*contextMenu.Items.Add(new ToolStripSeparator());
                 * contextMenu.Items.Add(_MENU_ITEM_DELETE, null, browserForm.DeletePackedTarget);*/
                // EVO_65: properties
                contextMenu.Items.Add(new ToolStripSeparator());
                contextMenu.Items.Add(_MENU_ITEM_PROPERTIES, null, browserForm.PackedPropertiesTarget);
            }
            else if (viewType == ViewType.FolderTree)
            {
                // Arborescence de dossiers

                // Pas de clic droit géré
            }

            return(contextMenu);
        }