{"id":1668,"date":"2016-12-15T17:03:16","date_gmt":"2016-12-15T16:03:16","guid":{"rendered":"http:\/\/eskerahn.dk\/?p=1668"},"modified":"2024-03-05T01:51:58","modified_gmt":"2024-03-05T00:51:58","slug":"get-newchanged-files-from-wpd-device-e-g-android-enhanced-version-of-christopher-geers-portabledevices","status":"publish","type":"post","link":"https:\/\/eskerahn.dk\/?p=1668","title":{"rendered":"Get new\/changed files from WPD-device, e.g. Android. Enhanced version of Christophe Geers&#8217; PortableDevices"},"content":{"rendered":"<p>I stumbled upon <a href=\"https:\/\/cgeers.wordpress.com\/2011\/08\/13\/wpd-transferring-content\/\" target=\"_blank\" rel=\"noopener noreferrer\">this nice project<\/a> by Christophe Geers.<\/p>\n<p>And edited and enhanced it to a tool that works a bit like an advanced REPLACE \/UPDATE\u00a0 to a tree on the PC based on the name of the device and the drives it exposes.<\/p>\n<p>It is an efficient way to get changed &amp; new files from a device to a PC.<\/p>\n<p><strong>Update: <\/strong>Now supports <strong>Exclude<\/strong> also.<\/p>\n<p>It works with a WPD connected device, e.g. an Android device USB-connected in MTP or PTP mode.<\/p>\n<p>Here an example of some of the tree generated<\/p>\n<p style=\"padding-left: 30px;\"><a href=\"https:\/\/eskerahn.dk\/?p=1668\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-1669\" src=\"https:\/\/eskerahn.dk\/wp-content\/uploads\/2016\/12\/PortableDeviceTreeExample.png\" alt=\"\" width=\"268\" height=\"319\" srcset=\"https:\/\/eskerahn.dk\/wp-content\/uploads\/2016\/12\/PortableDeviceTreeExample.png 268w, https:\/\/eskerahn.dk\/wp-content\/uploads\/2016\/12\/PortableDeviceTreeExample-126x150.png 126w, https:\/\/eskerahn.dk\/wp-content\/uploads\/2016\/12\/PortableDeviceTreeExample-252x300.png 252w\" sizes=\"auto, (max-width: 268px) 100vw, 268px\" \/><\/a><\/p>\n<p><strong>Most backup tools does NOT allow you to do an <span style=\"text-decoration: underline;\">incremental<\/span> backup, but they DO allow you to deselect e.g. images. So use this tool to do the incremental backup of the huge WPD-exposed stuff like the <span style=\"text-decoration: underline;\">images\/videos\/music<\/span>, and let your backup tool do backups of all the rest &#8211; and in more finite time than a total backup of everything every time &#8211; thus making it a bliss to take backups much more often&#8230;.<br \/>\n<\/strong><\/p>\n<p><!--more--><\/p>\n<p>The above picture is from my BB Priv on 6.0.1<\/p>\n<p>It also works on my Ancient Xperia Pro on ICS 4.0.1 (!) when connecting in MTP mode (*) , and a Samsung S8- on Oreo 8.0.0. Also tested working on the same S8- on 9.0 Pie, and the <a href=\"https:\/\/www.fxtec.com\/pro1\" target=\"_blank\" rel=\"noopener noreferrer\">FxTec Pro1<\/a> on 9.0 Pie.<\/p>\n<p>The actions on existing files can be handled by command line flags, by default, files on pc are overwritten if they are not the same size and date.<\/p>\n<p>IF the device is rooted (my Priv isn&#8217;t) it also tries to modify time-stamps on images on the device to the DateTaken stamp.<br \/>\nThis should help if you have copied files from a previous device (or from an old copy if the device has been reset)<\/p>\n<p>(If you copy files from a PC to a WPD device with the explorer the files get the stamp of the time they are copied NOT the stamp of the source files, making a total mess of e.g. image-history, This is a known issue using e.g. Android !!!)<\/p>\n<p>It is NOT a complete backup that is provided, since not all content is exposed through the WPD interface. E.g. your SMS and MMS messages and most apps data are NOT included.<\/p>\n<p>It is the same content you can find in a windows EXPLORER.<\/p>\n<p>But as you can not mount this as a drive letter, you can not make a simple REPLACE \/U, thus the need for something like this open source tool&#8230;., unless you want to copy everything, and manually handle conflicts for different&amp;equal files&#8230;<\/p>\n<p>It should be said that it is quite a task to find code that uses WPD that is not just displaying principles, but actually works(!). So again: <strong>Kudos to Christophe Geers<\/strong> his code only has a few very minor issues that needed to be corrected (it might well be that it would work flawlessly on 2011 devices).<\/p>\n<p>I have changed the principal behaviour from collecting the full tree initially, to handling each item as encountered through a call back &#8211; the original behaviour is stll in the code through an alternative call back.<\/p>\n<p>(2017-02-02) I found a strange bug on <a href=\"https:\/\/eskerahn.dk\/?p=1948\" target=\"_blank\" rel=\"noopener noreferrer\">WPD sometimes reporting wrong file-sizes<\/a>, and updated the program to handle\/recognise this. Unfortunately there are no good workaround, so currently it will do a binary compare of files with same date, but reported different sizes. And if the size is the only difference, it is output in a new output group (moving up 5&amp;6 to 6&amp;7 sorry)<\/p>\n<p>&nbsp;<\/p>\n<p>Due to the CallBack it would thus be quite easy to <span style=\"text-decoration: underline;\">change this tool<\/span> to something that does something else with the information collected.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>The C# source and project-files can be found here (Newest: v12, 2019-01-27)<br \/>\n<\/strong><\/p>\n<p><a href=\"https:\/\/eskerahn.dk\/wp-content\/uploads\/2016\/12\/PortableDevicesIncrementalCopy_V13.zip\">PortableDevicesIncrementalCopy_V13<\/a><\/p>\n<p>and executable, including Interop dll&#8217;s<\/p>\n<p><a href=\"https:\/\/eskerahn.dk\/wp-content\/uploads\/2016\/12\/PortableDevicesIncrementalCopy_EXE.zip\">PortableDevicesIncrementalCopy_EXE<\/a><\/p>\n<p>Please note that due to a(nother) bug in the Interop DLL generated, it MUST be compiled as x86 (Compiled in x64 or AnyCPU it works, but throws an exception on program-termination)<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>Please fell free to add any suggestions for additional or modified functionality in the comments below.<\/strong><\/span><\/p>\n<p>(No guarantee that it will be implemented though, if you want to fiddle with the code and need some info, also just ask)<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"text-decoration: underline;\"><strong>USAGE<\/strong><\/span><\/p>\n<p>Call the program with <strong>?<\/strong> for help on possible parameters.<\/p>\n<p>It currently defaults to copy to &#8220;<strong>c:\\MTP_DEVICES\\<\/strong>&#8221; (overridable by command line parameter) under which a directory for each connected device is created..<\/p>\n<pre style=\"padding-left: 30px;\">PortableDevicesIncrementalCopy\u00a0 see https:\/\/eskerahn.dk\/?p=1668\r\nPortableDevicesIncrementalCopy [DestFolderRoot] [NoLog] [IncludeFolderOutput]\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 [AlwaysCopy|IgnoreSize|IgnoreStamp|OverruleStamp] [ResLevelMax=n] [\/?]\r\n       [Excl {\\ | }]\r\n\u00a0\u00a0 DestFolderRoot, Default C:\\MTP_Devices\\\r\n\u00a0\u00a0 NoLog, Default a log file is created apart from the console output\r\n\u00a0\u00a0 IncludeFolderOutput : if set include lines with folder names\r\n\u00a0\u00a0 ResLevelMax= : defines the amount of output. Default=5\r\n\u00a0\u00a0\u00a0\u00a0 0 or higher: include (Copied)\r\n\u00a0\u00a0\u00a0\u00a0 1 or higher: include (Skip exists)\r\n\u00a0\u00a0\u00a0\u00a0 2 or higher: include (Skip exists sam siz)\r\n\u00a0\u00a0\u00a0\u00a0 3 or higher: include (Cmp: bin equ)\r\n\u00a0\u00a0\u00a0\u00a0 4 or higher: include (Cmp: bin equ older on device)\r\n\u00a0\u00a0\u00a0\u00a0 5 or higher: include (Wrong size reported by WPD, bin equ)\r\n\u00a0\u00a0\u00a0\u00a0 6 or higher: include (Skip exists sam siz &amp; dat)\r\n\u00a0\u00a0 PauseAtEnd : Yes you guessed it....\r\n\u00a0The next flags are mutually exclusive, checked in this order (default NONE)\r\n\u00a0\u00a0 AlwaysCopy : Always copy\r\n\u00a0\u00a0 IgnoreSize : Skip if file exist, ignore size\r\n\u00a0\u00a0 IgnoreStamp : Skip if same size, ignore stamp\r\n\u00a0\u00a0 OverruleStamp : Binary compare even if size and stamps matches\r\n Excl the rest is seen as exclude masks list, e.g. *cache*\\ *.tmp<\/pre>\n<p>&nbsp;<\/p>\n<p><del><strong>NOTE: Known bug in .NET<\/strong><\/del><br \/>\n<del> Multiple connected devices does not work due to .NET bug:<\/del><br \/>\n<del> Unfortunately .NET incorrectly requires WPD GetDevices to be called with a STRING and not an ARRAY of strings.<\/del><br \/>\n<del> There is an old 2006(?) workaround described several places including <a href=\"http:\/\/stackoverflow.com\/questions\/6162046\/enumerating-windows-portable-devices-in-c-sharp\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> , I can not get it to work (any more) though ;(<\/del><\/p>\n<p><del>So only one device can be handled at a time.<\/del><\/p>\n<p><strong>Update 2018-03-06.<\/strong> I FINALLY got the trick described to work. What I precisely did is described in FULL detail in a comment in PortableDeviceCollection.cs<br \/>\nNote that you may need to manually replace the wrong version of\u00a0 Interop.PortableDeviceApiLib.dll with the corrected one multiple times, also in bin and obj&#8230;<\/p>\n<p><strong>Note<\/strong> that I explicitly ignores portable devices that got a drive-letter attached, as there are SO many other ways to keep them synced. e.g. RoboCopy. So if you got a phone and a standard usb-key attached, only the phone is accessed.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Update 2019-01-27.<\/strong> Added the option to <strong>EXCLUDE<\/strong> files or folders, especially to exclude CACHE folders. Note the it only work on a general level, so you can not (currently) skip a specific mask one place and include it in another. That is &#8211;<em>Excl Myfolder\\*cache*<\/em> would not work as you would expect, but would skip nothing&#8230;.<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"font-size: 10pt;\"><strong>(*) Note on ICS<\/strong>. I experienced a WPD-lock-up after copying a lot of items. Restart of the program got stuck on the exact same item inside some deep cache folder, and only continued after a long time with an exception, hanging on the next files too&#8230; BUT it was the WPD also outside the program that got sick (could not access that file through windows explorer either). After unplugging the cable, restarting the Xperia Pro and reinserting the cable, a rerun fetched the rest&#8230; (a cable unplug and re-plug was not enough)<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I stumbled upon this nice project by Christophe Geers. And edited and enhanced it to a tool that works a bit like an advanced REPLACE \/UPDATE\u00a0 to a tree on the PC based on the name of the device and the drives it exposes. It is an efficient way to get changed &amp; new files [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,6],"tags":[],"class_list":["post-1668","post","type-post","status-publish","format-standard","hentry","category-compact-cameras","category-phonesphablets"],"_links":{"self":[{"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/posts\/1668","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1668"}],"version-history":[{"count":12,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/posts\/1668\/revisions"}],"predecessor-version":[{"id":3983,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=\/wp\/v2\/posts\/1668\/revisions\/3983"}],"wp:attachment":[{"href":"https:\/\/eskerahn.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1668"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1668"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/eskerahn.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1668"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}