public void MissingBackupFileExceptionTest()
        {
            MissingBackupFileException ex             = new MissingBackupFileException("C:\\somepath\\somefile.dat");
            MissingBackupFileException exUnserialized = (MissingBackupFileException)SerializeUnserialize(ex);

            Assert.AreEqual(ex.Filename, exUnserialized.Filename);
        }
Example #2
0
        public static IEnumerable <IPhoneDeviceInfo> GetDevicesInfo()
        {
            List <IPhoneDeviceInfo> phoneDevices = new List <IPhoneDeviceInfo>();
            RegistryKey             shellFolders = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders");
            string       appDataPath             = (string)shellFolders.GetValue("AppData");
            const string backupSubfolder         = @"Apple Computer\MobileSync\Backup\";

            string backupPath = Path.Combine(appDataPath, backupSubfolder);

            string[] subDirs;
            try
            {
                subDirs = Directory.GetDirectories(backupPath);
            }
            catch (DirectoryNotFoundException ex)
            {
                throw new MissingBackupPathException(backupPath, ex);
            }

            if (subDirs.Length == 0)
            {
                throw new NoBackupsFoundException(backupPath);
            }

            MissingBackupFileException missingFileException = null;

            foreach (string subDir in subDirs)
            {
                string infoXmlPath = Path.Combine(subDir, "Info.plist");
                if (!File.Exists(infoXmlPath))
                {
                    //
                    // Ignore missing info.plist file directories if a valid directory is eventually found, but
                    // if nothing is ever found, save the info to throw an exception.
                    //

                    if (missingFileException == null)
                    {
                        missingFileException = new MissingBackupFileException(infoXmlPath);
                    }
                    continue;
                }
                phoneDevices.Add(ReadPhoneDeviceInfo(infoXmlPath));
            }

            if (phoneDevices.Count == 0)
            {
                if (missingFileException != null)
                {
                    throw missingFileException;
                }
                else
                {
                    throw new NoBackupsFoundException(backupPath);
                }
            }

            return(phoneDevices);
        }