Esempio n. 1
0
        public async void NavigateRemote(string path)
        {
            RemotePath = path;
            RemoteFiles.Clear();

            var json = await SendCommand("list:" + path);

            JArray array;

            try { array = JArray.Parse(json); }
            catch { return; }

            var temp = new List <FileItem>();

            foreach (var obj in array)
            {
                var rpath  = obj.Value <string>("path");
                var folder = obj.Value <bool>("folder");


                if (!folder && mss.currentItem != null && mss.currentItem.Path.Equals(rpath))
                {
                    temp.Add(mss.currentItem);
                    continue;
                }

                var name = obj.Value <string>("name");


                long size = 0;
                if (!folder)
                {
                    size = obj.Value <long>("size");
                }

                var ext = Path.GetExtension(name).ToUpper();
                if (ext.Length > 0)
                {
                    ext = ext.Substring(1);
                }

                var date = new DateTime(1970, 1, 1, 0, 0, 0);
                date = date.AddMilliseconds(obj.Value <long>("date"));

                FileItem item;

                if (MusicFileItem.IsMusicFile(rpath))
                {
                    item = new MusicFileItem();
                }
                else if (PictureFileItem.IsPictureFile(rpath))
                {
                    item = new PictureFileItem();
                }
                else
                {
                    item = new FileItem();
                }

                item.Model     = this;
                item.Path      = rpath;
                item.Name      = name;
                item.Size      = size;
                item.Extension = folder ? "FOLDER" : ext;
                item.Date      = date.ToString();
                item.IsFolder  = folder;
                item.IsRemote  = true;

                temp.Add(item);
            }

            temp.Sort(new Comparison <FileItem>((t1, t2) =>
            {
                if (t1.IsFolder && !t2.IsFolder)
                {
                    return(-1);
                }
                else if (!t1.IsFolder && t2.IsFolder)
                {
                    return(1);
                }
                return(string.Compare(t1.Name, t2.Name, true));
            }));

            RemoteFiles = new ObservableCollection <FileItem>(temp);
        }
Esempio n. 2
0
        public void NavigateLocal(string path)
        {
            if (path == "/")
            {
                NavigateLocalHome();
                return;
            }

            LocalPath = path;
            LocalDrive.Clear();

            var di = new DirectoryInfo(path);

            if (!di.Exists)
            {
                return;
            }

            var dirs = di.EnumerateDirectories();

            foreach (var dir in dirs)
            {
                if (dir.Attributes.HasFlag(FileAttributes.Hidden |
                                           FileAttributes.System))
                {
                    continue;
                }

                LocalDrive.Add(new FileItem()
                {
                    Model     = this,
                    Path      = dir.FullName,
                    Name      = dir.Name,
                    Extension = "FOLDER",
                    Date      = dir.LastWriteTime.ToString(),
                    IsFolder  = true
                });
            }

            var files = di.EnumerateFiles();

            foreach (var file in files)
            {
                if (file.Attributes.HasFlag(FileAttributes.Hidden |
                                            FileAttributes.System))
                {
                    continue;
                }

                FileItem item;

                if (MusicFileItem.IsMusicFile(file.FullName))
                {
                    item = new MusicFileItem();
                }
                else if (PictureFileItem.IsPictureFile(file.FullName))
                {
                    item = new PictureFileItem();
                }
                else
                {
                    item = new FileItem();
                }

                item.Model     = this;
                item.Path      = file.FullName;
                item.Name      = file.Name;
                item.Size      = file.Length;
                item.Extension = file.Extension.Length >= 1 ? file.Extension.Substring(1).ToUpper() : "";
                item.Date      = file.LastWriteTime.ToString();
                item.IsFolder  = false;

                LocalDrive.Add(item);
            }
        }