Ejemplo n.º 1
0
        public static void OpenProject()
        {
            OpenFileDialog fileDialog = new OpenFileDialog();

            fileDialog.InitialDirectory = Config.LastVisitedPath;

            fileDialog.Title       = "Open a project";
            fileDialog.Multiselect = false;

            fileDialog.Filter     = "DocMaker Project (*.dmprj)|*.dmprj";
            fileDialog.DefaultExt = "dmprj";

            if (fileDialog.ShowDialog() == DialogResult.OK)
            {
                //Save last opened directory
                Config.LastVisitedPath = Path.GetDirectoryName(fileDialog.FileName);

                if (!File.Exists(fileDialog.FileName))
                {
                    Funcs.Error("Project file not found !");
                    return;
                }

                if (changeList.Count > 0)
                {
                    DialogResult dr = Funcs.Question_YNC("Do you want to save changes before opening the file ?");

                    if (dr == DialogResult.Cancel)
                    {
                        return;
                    }

                    if (dr == DialogResult.Yes)
                    {
                        SaveProject();
                    }
                }

                // Save the file
                projectLoadedFromFile = true;
                projectFile           = fileDialog.FileName;
                projectTitle          = Path.GetFileName(projectFile);

                try
                {
                    InitializeComponents();

                    fileHandler = new BinaryFileHandler(projectFile, BinaryFileHandler.FileMode.READ);

                    Paper.LoadPaper();
                    Fonts.LoadFonts();
                    Languages.LoadLanguages();

                    Resources.LoadResources();
                    Objects.LoadObjects();

                    fileHandler.Close();
                }
                catch (Exception ex)
                {
                    Funcs.Error("Error while loading the project file.\n" + ex.Message);
                    fileHandler.Close(); // Force closing file

                    NewProject();
                }
            }
        }