public void ShowWindow(object objWindow)
        {
            if (objWindow is WindowsControllerParam newWindowParam)
            {
                newWindowParam = (WindowsControllerParam)objWindow;
                switch (newWindowParam.NewWindowStr)
                {
                case "SettingsWindow":
                {
                    SettingsWindow settingsWindow = new SettingsWindow();
                    if (newWindowParam.Parameters is ViewModelClient)
                    {
                        settingsWindow.DataContext = (ViewModelClient)newWindowParam.Parameters;
                    }
                    settingsWindow.Show();
                    break;
                }

                case "FileViewerWindow":
                {
                    FileViewerWindow fileViewer = new FileViewerWindow();

                    if (newWindowParam.Parameters is FileViewerVm)
                    {
                        fileViewer.DataContext = (FileViewerVm)newWindowParam.Parameters;
                    }
                    else
                    {
                        MessageBox.Show("WindowsController: Error in type of data context for FileViewerWindow!");
                    }

                    fileViewer.Show();
                    break;
                }

                default:
                {
                    MessageBox.Show("Windows name was not founded in WindowsController swtich!");
                    break;
                }
                }
            }
        }
Beispiel #2
0
        //private enum PathTypes { PT_ABSOLUTE, PT_RELATIVE };
        private void openPath(string path)
        {
            path = UsefulThings.clearExcessSeparators(path);
            try
            {
                path = UsefulThings.clearExcessSeparators(path);
                string tmpPathWithoutLast, tmpLast;
                UsefulThings.detachLastFilename(path, out tmpPathWithoutLast, out tmpLast);
                uint       newCluster;
                FileHeader fh;
                if (path.Equals(fsctrl.CurrDir))
                {
                    newCluster = fsctrl.CurrDirCluster;
                    fh         = new FileHeader("", "", (byte)FileHeader.FlagsList.FL_DIRECTORY, 0, 0); //требуется лишь только, чтобы у заголовка был флаг "директория"
                }
                else if (tmpPathWithoutLast.Equals(fsctrl.CurrDir))
                {
                    FileHeader tmpFH = fsctrl.getFileHeader(tmpLast, fsctrl.CurrDirCluster, true);
                    if (tmpFH == null)
                    {
                        throw new InvalidPathException(path);
                    }
                    newCluster = tmpFH.FirstCluster;
                    fh         = fsctrl.getFileHeader(tmpLast, fsctrl.CurrDirCluster, true);
                }
                else
                {
                    if (path.Equals(""))
                    {
                        newCluster = fsctrl.SuperBlock.RootOffset / fsctrl.SuperBlock.ClusterSize;
                    }
                    else
                    {
                        FileHeader tmpFH = fsctrl.getFileHeader(path, true);
                        if (tmpFH == null)
                        {
                            throw new InvalidPathException(path);
                        }
                        newCluster = tmpFH.FirstCluster;
                    }
                    fh = fsctrl.getFileHeader(path, true);
                }

                if (!path.Equals("") && fh == null)
                {
                    throw new InvalidPathException(path);
                }
                if (path.Equals("") || fh.IsDirectory)
                {
                    byte[] dir = fsctrl.readFile(path, true);
                    wrapPanel.Children.Clear();
                    while (dir.Length > 0)
                    {
                        FileHeader currFH = new FileHeader(dir);
                        addFileView(currFH);
                        dir = dir.Skip(FileHeader.SIZE).ToArray();
                    }
                    fsctrl.CurrDir        = path;
                    fsctrl.CurrDirCluster = newCluster;
                    addressEdit.Text      = fsctrl.CurrDir.Length > 0 ? fsctrl.CurrDir : "/";
                    selection             = null;
                    if (fsctrl.CurrDir.Equals(""))
                    {
                        backImg.IsEnabled = false;
                    }
                    else
                    {
                        backImg.IsEnabled = true;
                    }
                }
                else
                {
                    FileViewerWindow fvw = new FileViewerWindow(fh, UsefulThings.ENCODING.GetString(fsctrl.readFile(fh, true)));
                    fvw.Title = fh.NamePlusExtensionWithoutZeros;
                    fvw.ShowDialog();
                    if (fvw.IsChanged && MessageBox.Show("Файл был изменён. Сохранить изменения?", "Подтвердите действие",
                                                         MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        fsctrl.rewriteFile(fsctrl.CurrDir, fh, UsefulThings.ENCODING.GetBytes(fvw.textField.Text), true);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                openPath(fsctrl.CurrDir);
            }
        }