public override void Execute()
    {
        Validate(Parameters);
        string path = Parameters[1];

        FSManager.CreateDirectory(path);
    }
Пример #2
0
 /// <summary>
 /// Repopulates the desktop icon list view.
 /// </summary>
 private void SetupIcons()
 {
     _desktopIconsView.ClearItems();
     if (!_fs.DirectoryExists("/home/Desktop"))
     {
         _fs.CreateDirectory("/home/Desktop");
     }
     foreach (var dir in _fs.GetDirectories("/home/Desktop"))
     {
         if (_futils.GetNameFromPath(dir).StartsWith("."))
         {
             continue;
         }
         var diritem = new ListViewItem();
         diritem.Tag      = dir;
         diritem.Value    = _futils.GetNameFromPath(dir);
         diritem.ImageKey = "folder";
         _desktopIconsView.AddItem(diritem);
     }
     foreach (var dir in _fs.GetFiles("/home/Desktop"))
     {
         if (_futils.GetNameFromPath(dir).StartsWith("."))
         {
             continue;
         }
         var diritem = new ListViewItem();
         diritem.Tag      = dir;
         diritem.Value    = _futils.GetNameFromPath(dir);
         diritem.ImageKey = _futils.GetMimeType(dir);
         if (_desktopIconsView.GetImage(diritem.ImageKey) == null)
         {
             _desktopIconsView.SetImage(diritem.ImageKey, _futils.GetMimeIcon(diritem.ImageKey));
         }
         _desktopIconsView.AddItem(diritem);
     }
 }
Пример #3
0
        /// <inheritdoc/>
        public void Run(ConsoleContext console, Dictionary <string, object> arguments)
        {
            string dir = arguments["<directory>"].ToString();

            if (!dir.StartsWith("/"))
            {
                dir = console.WorkingDirectory + "/" + dir;
            }
            string abs = _futils.Resolve(dir);

            if (_fs.DirectoryExists(abs))
            {
                console.WriteLine($"mkdir: Directory already exists: {abs}");
                return;
            }
            _fs.CreateDirectory(abs);
        }
Пример #4
0
 internal void EnsureProperEnvironment()
 {
     try
     {
         _fs.SetBackend(new AsyncServerFSBackend());
         foreach (var dir in requiredPaths)
         {
             if (!_fs.DirectoryExists(dir))
             {
                 _fs.CreateDirectory(dir);
             }
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #5
0
        /// <inheritdoc/>
        public FileManager(WindowSystem _winsys) : base(_winsys)
        {
            AddChild(_places);
            AddChild(_files);
            AddChild(_back);
            AddChild(_forward);
            AddChild(_path);
            AddChild(_search);
            AddChild(_searchButton);
            AddChild(_newFolder);
            _places.AddChild(_placesView);
            _files.AddChild(_filesView);
            Width = 800;
            Height = 600;
            Title = "File browser";

            AddChild(_open);
            AddChild(_openField);

            _newFolder.Text = "New folder";
            _newFolder.Click += (o, a) =>
            {
                string folderPath = _currentDirectory;
                _infobox.PromptText("New folder", "Please enter a name for your new folder.", (name) =>
                {
                    string fullPath = (folderPath.EndsWith("/")) ? folderPath + name : folderPath + "/" + name;
                    _fs.CreateDirectory(fullPath);
                    _needsReset = true;
                }, (proposedName)=>
                {
                    if(string.IsNullOrWhiteSpace(proposedName))
                    {
                        _infobox.Show("New folder", "Your folder's name must not be blank.");
                        return false;
                    }

                    foreach(char c in proposedName)
                    {
                        if (char.IsLetterOrDigit(c))
                            continue;
                        if (c == '_' || c == ' ' || c == '-' || c == '.')
                            continue;
                        _infobox.Show("Invalid path character", "Your new folder's name contains an invalid character. Valid characters include any letter or number as well as '.', '_', '-' or a space.");
                        return false;
                    }

                    string fullPath = (folderPath.EndsWith("/")) ? folderPath + proposedName : folderPath + "/" + proposedName;
                    if(_fs.DirectoryExists(fullPath) || _fs.FileExists(fullPath))
                    {
                        _infobox.Show("New folder", "A folder or file already exists with that name.");
                        return false;
                    }

                    return true;
                });
            };

            _placesView.ItemClicked += (item) =>
            {
                if (_placesView.SelectedIndex == -1)
                    return;
                var path = item?.Tag?.ToString();
                if(path != _currentDirectory)
                {
                    _pastLocs.Push(_currentDirectory);
                    _futureLocs.Clear();
                    _currentDirectory = path;
                    _needsReset = true;
                }
            };

            _back.Click += (o, a) =>
            {
                if (_pastLocs.Count > 0)
                {
                    _futureLocs.Push(_currentDirectory);
                    _currentDirectory = _pastLocs.Pop();
                    _needsReset = true;
                }
            };
            _forward.Click += (o, a) =>
            {
                if (_futureLocs.Count > 0)
                {
                    _pastLocs.Push(_currentDirectory);
                    _currentDirectory = _futureLocs.Pop();
                    _needsReset = true;
                }
            };

            foreach(var shelldir in _os.GetShellDirs())
            {
                var lvitem = new ListViewItem();
                lvitem.Value = shelldir.FriendlyName;
                lvitem.Tag = shelldir.Path;
                lvitem.ImageKey = lvitem.Tag.ToString();
                if (shelldir.Texture != null)
                    _placesView.SetImage(lvitem.ImageKey, shelldir.Texture);
                _placesView.AddItem(lvitem);
            }

            _filesView.SetImage("directory", _plexgate.Content.Load<Texture2D>("UIIcons/folder"));

            _filesView.SelectedIndexChanged += (o, a) =>
            {
                if(_filesView.SelectedItem != null)
                {
                    _openField.Text = _filesView.SelectedItem.Value.ToString();
                }
            };
            _filesView.ItemClicked += (item) =>
            {
                if (_fs.DirectoryExists(item.Tag.ToString()))
                {
                    _futureLocs.Clear();
                    _pastLocs.Push(_currentDirectory);
                    _currentDirectory = item.Tag.ToString();
                    _needsReset = true;
                }
                else
                {
                    if (_isDialog)
                    {
                        open(item.Tag.ToString());
                        return;
                    }
                    if(!_utils.OpenFile(item.Tag.ToString()))
                    {
                        _infobox.Show("Can't open file", "File Manager couldn't find a program that can open that file!");
                    }
                    return;
                }
            };
            _open.Click += (o, a) =>
            {
                string path = _openField.Text;
                if (path.StartsWith("/"))
                    path = _futils.Resolve(path);
                else
                    path = _futils.Resolve(_currentDirectory + "/" + path);
                if (_isSaving == false)
                {
                    if (_fs.FileExists(path))
                    {
                        open(path);
                        return;
                    }
                    Enabled = false;
                    _infobox.Show("File not found.", $"The system could not find the file specified: {path}", () =>
                    {
                        Enabled = true;
                    });
                }
                else
                {
                    open(path);
                }
            };
            _searchButton.Click += (o, a) =>
            {
                _filesView.Filter = _search.Text;
                if (_filesView.VisibleItems.Length == 0)
                {
                    _statusHead.Text = "No results found";
                    _statusDescription.Text = $"Your search \"{_search.Text}\" did not return any results.";
                    _statusDescription.Visible = true;
                    _statusHead.Visible = true;
                }
                else
                {
                    _statusHead.Visible = false;
                    _statusDescription.Visible = false;
                }
            };
            _search.KeyEvent += _search_KeyEvent;

            AddChild(_statusHead);
            AddChild(_statusDescription);
        }