public void Refresh(NwdPortableDevice device)
        {
            Files.Clear();

            if (device != null)
            {
                device.FillFolder(this);
            }
        }
Ejemplo n.º 2
0
        protected void ConvertNullsToEmptyStrings(NwdPortableDevice device)
        {
            if (device.Description == null)
            {
                device.Description = "";
            }

            if (device.Model == null)
            {
                device.Model = "";
            }

            if (device.DeviceType == null)
            {
                device.DeviceType = "";
            }

            if (device.FriendlyName == null)
            {
                device.FriendlyName = "";
            }
        }
Ejemplo n.º 3
0
        private void lvParent_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            object selected = lvParent.SelectedItem;

            if (selected is NwdPortableDevice)
            {
                lvChild.Items.Clear();

                NwdPortableDevice device = (NwdPortableDevice)selected;

                _currentDevice = device;

                if (device.RootFolder != null)
                {
                    foreach (NwdPortableDeviceObject pdo in
                            device.RootFolder.Files)
                    {
                        lvChild.Items.Add(pdo);
                    }
                }
            }
            else if (selected is NwdPortableDeviceFolder)
            {
                lvChild.Items.Clear();

                NwdPortableDeviceFolder folder =
                    (NwdPortableDeviceFolder)selected;

                folder.Refresh(_currentDevice);

                if (folder.Files != null)
                {
                    lvChild.Items.Clear();
                    foreach (NwdPortableDeviceObject pdo in folder.Files)
                    {
                        lvChild.Items.Add(pdo);
                    }
                }
                else
                {
                    MessageBox.Show("Files Null for Folder: " + folder.Name);
                }
            }
        }
Ejemplo n.º 4
0
        private IEnumerable<NwdUriProcessEntry> GetDeviceSynergyFiles(NwdPortableDevice device)
        {
            List<NwdPortableDeviceObject> lst = FindByUri("NWD/synergy/[*]");
            List<NwdUriProcessEntry> output =
                new List<NwdUriProcessEntry>();

            if (lst.Count > 0)
            {
                foreach (NwdPortableDeviceObject pdo in lst)
                {
                    if (pdo is NwdPortableDeviceFile)
                    {
                        NwdUri uri = new NwdUri("NWD/synergy/" + pdo.Name);
                        NwdUriProcessEntry pe =
                            new NwdUriProcessEntry(uri);

                        pe.DeviceObject = pdo;

                        output.Add(pe);
                    }
                }
            }

            return output;
        }
Ejemplo n.º 5
0
        private IEnumerable<NwdUriProcessEntry> GetDeviceHashedMedia(NwdPortableDevice device)
        {
            string uri = "NWD/config/FileHashIndex.txt";
            NwdPortableDeviceFile hashedMediaIndex =
                GetFirstFileByUri(uri);

            if (hashedMediaIndex == null)
            {
                Display.Message("[" + uri + "] not found");
                return new List<NwdUriProcessEntry>(); //empty list
            }
            else
            {
                Display.Message("found [" + uri + "]");

                //copy to local file system
                string localFilePath =
                    Configuration.NwdUriToLocalPath(uri);

                //Display.Message(localFilePath);

                string localDestinationFolder =
                    Path.GetDirectoryName(localFilePath);

                //Display.Message(localDestinationFolder);

                device.DownloadFile(hashedMediaIndex,
                                    localDestinationFolder);

                Display.Message("copied file to [" + localFilePath + "]");

                List<string> lineItems =
                    File.ReadAllLines(localFilePath).ToList();

                Display.Message("found " + lineItems.Count + " lineItems");

                Parser.Parser p = new Parser.Parser();
                List<NwdUri> lst = new List<NwdUri>();
                List<string> invalidPaths = new List<string>();

                foreach (string li in lineItems)
                {
                    string path = p.Extract("path", li);
                    string hash = p.Extract("sha1Hash", li);
                    List<string> whitelistedFolders =
                        new List<string>();
                    whitelistedFolders.Add("Pictures");
                    whitelistedFolders.Add("DCIM");
                    //NwdUri newUri = Configuration.NwdPathToNwdUri(path);
                    NwdUri newUri = Configuration.NwdPathToNwdUri(path, whitelistedFolders);
                    if (newUri != null)
                    {
                        newUri.Hash = hash;
                        newUri.Path = path;
                        lst.Add(newUri);
                    }
                    else
                    {
                        invalidPaths.Add(path);
                    }
                }

                var pathList = (from li in invalidPaths
                                select new
                                {
                                    Path = li
                                }).ToList();

                if (pathList.Count > 0)
                {
                    Display.Grid(invalidPaths.Count + " invalid paths skipped", lst, pathList);
                }
                else
                {
                    Display.Grid("0 invalid paths skipped", lst);
                }

                var processEntries =
                    (from nwdUri in lst
                     select new NwdUriProcessEntry(nwdUri)).ToList();

                return processEntries;
            }
        }
Ejemplo n.º 6
0
        private void Retrieve(NwdPortableDevice device,
                              NwdPortableDeviceFolder folder,
                              ref NwdUri uri,
                              ref MultiMap<string, NwdPortableDeviceObject> found)
        {
            folder.Refresh(device);

            string nodeName = uri.PopNodeName();

            if (found.ContainsKey(uri.CurrentTraversalUri))
            {
                //used cached lookup
                foreach (NwdPortableDeviceObject pdo in found[uri.CurrentTraversalUri])
                {
                    ProcessPdo(device, pdo, ref uri, ref found);
                }
            }
            else
            {
                //use standard lookup
                if (folder.Files != null)
                {
                    foreach (NwdPortableDeviceObject pdo in folder.Files)
                    {
                        if (NwdUri.MatchNodeName(nodeName, pdo.Name))
                        {
                            ProcessPdo(device, pdo, ref uri, ref found);
                        }
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void Retrieve(NwdPortableDevice device,
                              NwdPortableDeviceFolder folder,
                              ref NwdUri uri,
                              ref List<NwdPortableDeviceObject> found)
        {
            folder.Refresh(device);

            string nodeName = uri.PopNodeName();

            if (folder.Files != null)
            {
                foreach (NwdPortableDeviceObject pdo in folder.Files)
                {
                    if (NwdUri.MatchNodeName(nodeName, pdo.Name))
                    {
                        if (uri.HasNodeKeysInStack())
                        {
                            if (pdo is NwdPortableDeviceFolder)
                            {
                                NwdPortableDeviceFolder nextFolder =
                                    (NwdPortableDeviceFolder)pdo;

                                //uri has one level popped, pass the modified uri and
                                //the newly found folder to the next level of recursion
                                Retrieve(device, nextFolder, ref uri, ref found);
                            }
                            else
                            {
                                //bad key (found name but not a folder and keystack isn't empty, so just return)

                                //do nothing
                            }
                        }
                        else
                        {
                            //finished
                            found.Add(pdo);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void ProcessPdo(NwdPortableDevice device,
                                NwdPortableDeviceObject pdo,
                                ref NwdUri uri,
                                ref MultiMap<string, NwdPortableDeviceObject> found)
        {
            if (uri.HasNodeKeysInStack())
            {
                if (pdo is NwdPortableDeviceFolder)
                {
                    NwdPortableDeviceFolder nextFolder =
                        (NwdPortableDeviceFolder)pdo;

                    found.Add(uri.CurrentTraversalUri, pdo);

                    //uri has one level popped, pass the modified uri and
                    //the newly found folder to the next level of recursion
                    Retrieve(device, nextFolder, ref uri, ref found);
                }
                else
                {
                    //bad key (found name but not a folder and keystack isn't empty, so just return)

                    //do nothing
                }
            }
            else
            {
                //finished
                found.Add(uri.CurrentTraversalUri, pdo);
            }
        }