예제 #1
0
        /// <summary>
        /// Constructeur principal
        /// </summary>
        /// <param name="dbFileName">Nom du fichier de bases de données à charger</param>
        internal DBResource(string dbFileName)
        {
            _FileName       = dbFileName;
            _CurrentCulture = (DB.Culture)Enum.Parse(typeof(DB.Culture), File2.GetExtensionFromFilename(_FileName).ToUpper());

            // Lecture
            _ReadData();
        }
예제 #2
0
파일: BNK.cs 프로젝트: djey47/tdumt
        /// <summary>
        /// Changes name of specified packed file
        /// </summary>
        /// <param name="packedFilePath"></param>
        /// <param name="newPackedFileName"></param>
        public void RenamePackedFile(string packedFilePath, string newPackedFileName)
        {
            try
            {
                if (!string.IsNullOrEmpty(packedFilePath) && !string.IsNullOrEmpty(newPackedFileName))
                {
                    // Extension check
                    string packedFileName = GetPackedFileName(packedFilePath);
                    string oldExtension   = File2.GetExtensionFromFilename(packedFileName);
                    string newExtension   = File2.GetExtensionFromFilename(newPackedFileName);

                    if (oldExtension != null &&
                        newExtension != null &&
                        !oldExtension.Equals(newExtension, StringComparison.InvariantCultureIgnoreCase))
                    {
                        throw new Exception(_ERROR_RENAMING_EXTENSIONS);
                    }

                    // Name check
                    if (GetPackedFilesPaths(newPackedFileName).Count > 0)
                    {
                        throw new Exception(string.Format(_FORMAT_ERROR_PACKED_FILE_NAME_EXISTS, newPackedFileName));
                    }

                    // Getting packed file...
                    PackedFile packedFile = _GetPackedFile(packedFilePath);

                    if (packedFile.exists)
                    {
                        _RenamePackedFile(packedFile, newPackedFileName);
                    }
                    else
                    {
                        throw new Exception(string.Format(_FORMAT_ERROR_PACKED_FILE_NOT_EXISTS, packedFilePath));
                    }
                }
                else
                {
                    throw new Exception("Forbidden operation.");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to rename packed file: " + packedFilePath + "\r\n" + ex.Message, ex);
            }
        }
예제 #3
0
        /// <summary>
        /// Permet la sélection d'un fichier de remplacement
        /// </summary>
        /// <param name="defaultFileName">Nom de fichier par défaut</param>
        /// <returns>Le chemin du fichier sélectionné, null si l'opération a été annulée</returns>
        private string _SelectReplacementFile(string defaultFileName)
        {
            string returnedFileName = null;

            // Paramètres de la boîte de sélection
            string fileExtension = File2.GetExtensionFromFilename(defaultFileName);

            openFileDialog.Filter = string.Concat(GuiConstants.MakeSelectionFilter(fileExtension, ""), "|",
                                                  GuiConstants.FILTER_ALL_FILES);
            openFileDialog.FileName = defaultFileName;
            openFileDialog.Title    = string.Format(_TITLE_REPLACE_SELECTION, defaultFileName);

            // Mémorisation du dernier emplacement
            if (_LastReplaceLocation == null)
            {
                // EVO_102: default location
                if (string.IsNullOrEmpty(Program.ApplicationSettings.DefaultEditNewFilesFolder))
                {
                    _LastReplaceLocation = bnkStatusLabel.Text;
                }
                else
                {
                    _LastReplaceLocation = Program.ApplicationSettings.DefaultEditNewFilesFolder;
                }
            }

            openFileDialog.InitialDirectory = _LastReplaceLocation;

            // Ouverture fenêtre
            DialogResult dr = openFileDialog.ShowDialog(this);

            if (dr == DialogResult.OK)
            {
                // Mémorisation du dernier emplacement
                FileInfo selectedFileInfo = new FileInfo(openFileDialog.FileName);
                _LastReplaceLocation = selectedFileInfo.DirectoryName;

                returnedFileName = openFileDialog.FileName;
            }

            return(returnedFileName);
        }
예제 #4
0
        /// <summary>
        /// Returns list of packed file names having specified extension
        /// </summary>
        /// <param name="extension">extension of searched files, NOT including point. If set to null or empty, all files are returned.</param>
        /// <returns></returns>
        public Collection <string> GetPackedFilesPathsByExtension(string extension)
        {
            Collection <string> resultList = new Collection <string>();

            // Parcours de la liste de fichiers
            foreach (PackedFile anotherFile in _FileList)
            {
                if (anotherFile.fileName != null &&
                    !anotherFile.fileName.StartsWith(_PADDING_FILE_NAME) &&
                    !anotherFile.fileName.StartsWith(_UNKNOWN_FILE_NAME))
                {
                    string anotherExtension = File2.GetExtensionFromFilename(anotherFile.fileName);

                    if (string.IsNullOrEmpty(extension) ||
                        extension.Equals(anotherExtension, StringComparison.InvariantCultureIgnoreCase))
                    {
                        resultList.Add(anotherFile.filePath);
                    }
                }
            }
            return(resultList);
        }
예제 #5
0
        private void fileEditToolStripButton_Click(object sender, EventArgs e)
        {
            // Clic sur le bouton d'édition
            Cursor = Cursors.WaitCursor;

            // EVO 45 : gestion de plusieurs demandes d'édition
            int successCount = 0;

            foreach (string currentPackedFileName in _GetSelectedFilePaths())
            {
                try
                {
                    // Affiche la fenêtre d'édition
                    if (!_EditTasksWindow.Visible)
                    {
                        editTasksToolStripMenuItem.Checked = true;
                        editTasksToolStripMenuItem_Click(sender, new EventArgs());
                    }

                    // Création de la tâche d'édition et ajout à la liste
                    _EditPackedFile(currentPackedFileName);

                    successCount++;
                }
                catch (Exception ex)
                {
                    string    message = string.Format(_ERROR_SHOW_OR_EDIT_FAILED, _WORD_EDIT, File2.GetExtensionFromFilename(currentPackedFileName));
                    Exception newEx   = new Exception(message, ex);

                    MessageBoxes.ShowError(this, newEx);
                }
            }

            if (successCount > 0)
            {
                string message = string.Format(_STATUS_EDIT_SUCCESS, successCount);

                StatusBarLogManager.ShowEvent(this, message);
            }

            Cursor = Cursors.Default;
        }
예제 #6
0
        private void fileOpenToolStripButton_Click(object sender, EventArgs e)
        {
            // Click on 'Open' button
            foreach (string currentPackedFilePath in _GetSelectedFilePaths())
            {
                Cursor = Cursors.WaitCursor;

                try
                {
                    _ViewPackedFile(currentPackedFilePath);
                }
                catch (Exception ex)
                {
                    string message = string.Format(_ERROR_SHOW_OR_EDIT_FAILED, _WORD_OPEN, File2.GetExtensionFromFilename(currentPackedFilePath))
                                     + Environment.NewLine
                                     + ex.Message;

                    MessageBoxes.ShowError(this, new Exception(message, ex));
                }
                finally
                {
                    Cursor = Cursors.Default;
                }
            }
        }
예제 #7
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);
        }