예제 #1
0
        /// <summary>
        /// Opens esc file
        /// </summary>
        private void Open(string filename)
        {
            var initialDirectory = string.Empty;

            if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.RecentLocationProject))
            {
                initialDirectory = Properties.Settings.Default.RecentLocationProject;
            }

            if (string.IsNullOrWhiteSpace(filename) || filename == "open")
            {
                filename = FileManagement.OpenFileDialog(initialDirectory).FileName;
            }


            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }

            FuturamaSysModel t;

            try
            {
                t = FileManagement.OpenSystemFile(filename);
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Could't open file", MessageBoxButton.OK, MessageBoxImage.Error,
                                MessageBoxResult.OK);
                return;
            }

            Properties.Settings.Default.RecentLocationProject = Path.GetDirectoryName(filename);

            if (LibraryData.SystemIsOpen)
            {
                if (!Close())
                {
                    return;
                }
            }

            FileName = filename;

            LibraryData.OpenSystem(t);

            _comViewModel.UpdateConnections();
            RaisePropertyChanged(() => InstallerVersion);
            _recentFilesLogic.AddFile(filename);
            AddMainUnitsToTab();
            AddConnections();
            SelectedTab = TabCollection.FirstOrDefault(i => i.Id == 0);
        }