예제 #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);
        }
예제 #2
0
        public static void PreviewItem(PictureFileItem item)
        {
            string path = null;

            if (!item.IsRemote)
            {
                path = item.Path;
            }
            else
            {
                if (item.TempPath != null)
                {
                    path = item.TempPath;
                }
                else
                {
                    Task.Run(() =>
                    {
                        item.IsLoading = true;

                        int bytesRead, bytesTotalRead = 0;

                        using (var client = new TcpClient())
                        {
                            client.Connect(TransferViewModel.device.Address, 8000);

                            using (var ns = client.GetStream())
                            {
                                byte[] buffer = Encoding.UTF8.GetBytes("receive:" + item.Path);

                                ns.Write(buffer, 0, buffer.Length);
                                ns.Flush();

                                buffer = new byte[8192];

                                item.TempPath = Path.ChangeExtension(Path.GetTempFileName(),
                                                                     Path.GetExtension(item.Path));

                                var sw = new Stopwatch();
                                sw.Start();

                                using (var stream = File.OpenWrite(item.TempPath))
                                {
                                    while ((bytesRead = ns.Read(buffer, 0, buffer.Length)) > 0)
                                    {
                                        stream.Write(buffer, 0, bytesRead);
                                        bytesTotalRead += bytesRead;

                                        if (sw.ElapsedMilliseconds >= 200)
                                        {
                                            item.Progress = 100 * bytesTotalRead / (double)item.Size;
                                            sw.Restart();
                                        }
                                    }
                                }

                                Process.Start(item.TempPath);
                            }
                        }

                        item.IsLoading = false;
                    });
                }
            }

            if (path != null)
            {
                Process.Start(path);
            }
        }
예제 #3
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);
            }
        }