Example #1
0
        public static IPhoneBackup New(DirectoryInfo path)
        {
            try
            {
                string    filename = System.IO.Path.Combine(path.FullName, "Info.plist");
                PListRoot root     = PListRoot.Load(filename);
                PListDict dict     = root.Root as PListDict;

                IPhoneBackup backup = new IPhoneBackup();
                backup.Path = path.FullName;

                foreach (var p in dict)
                {
                    switch (p.Key)
                    {
                    case "Device Name":
                        backup.DeviceName = p.Value().ToString();
                        break;

                    case "Display Name":
                        backup.DisplayName = p.Value().ToString();
                        break;

                    case "Last Backup Date":
                        backup.LastBackupDate = p.Value().ToString();
                        break;
                    }
                }
                return(backup);
            }
            catch (Exception e)
            {
                throw new FileLoadException("No backup at " + path, e);
            }
        }
        public MMSAnalyzer(IPhoneBackup backup, IPhoneFile file)
        {
            _backup = backup;
            _file = file;

            InitializeComponent();
        }
        public SelectBackupForm(IPhoneBackup[] backups)
        {
            InitializeComponent();

            foreach (IPhoneBackup b in backups)
            {
                listBackups.Items.Add(b);
            }
        }
        public HashInfo(IPhoneBackup backup, IPhoneFile file)
        {
            InitializeComponent();

            FileInfo fileInfo = FileManager.Current.GetOriginalFile(backup, file);
            Text = "Hash information [" + file.Path + "]";
            lblFileName.Text = file.Path;
            lblMd5.Text = Util.MD5File(fileInfo);
            lblSha1.Text = Util.SHA1File(fileInfo);
        }
        public ImageAnalyzer(IPhoneBackup backup)
        {
            _backup = backup;
            _worker = new BackgroundWorker();
            _worker.DoWork += new DoWorkEventHandler(_worker_DoWork);
            _worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_worker_RunWorkerCompleted);
            _worker.ProgressChanged += new ProgressChangedEventHandler(_worker_ProgressChanged);
            _worker.WorkerReportsProgress = true;
            _worker.WorkerSupportsCancellation = true;

            this.FormClosing += new FormClosingEventHandler(ImageAnalyzer_FormClosing);
            InitializeComponent();

            if (_backup != null)
                this.Text += " [" + _backup.DisplayName + "]";
        }
Example #6
0
        public static IPhoneBackup[] Load(string path)
        {
            DirectoryInfo       d       = new DirectoryInfo(path);
            List <IPhoneBackup> backups = new List <IPhoneBackup>();

            foreach (DirectoryInfo sd in d.EnumerateDirectories())
            {
                try
                {
                    IPhoneBackup backup = New(sd);
                    backups.Add(backup);
                }
                catch (FileLoadException ex)
                {
                    Logger.DebugException(ex.Message, ex);
                }
            }

            return(backups.ToArray());
        }
        /// <summary>
        /// Return a file copy from a temp folder
        /// 
        /// The path will be /Temp/$$idb$/{dir}/{fileName} (or random i.e. Path.GetTempFileName())
        /// 
        /// if verify == true the file from source and the destination hashes will be compared
        /// if the comparsion fail. An IOExcetion is raised.
        /// </summary>
        /// <param name="backup"></param>
        /// <param name="file"></param>
        /// <param name="random"></param>
        /// <param name="dir"></param>
        /// <param name="verify">Verify the files after copy (using md5)</param>
        /// <exception cref="IOException">
        /// Thrown if file copy failed or that the copy cannot be verified
        /// </exception>
        /// <returns></returns>
        public FileInfo GetWorkingFile(string dir, IPhoneBackup backup, IPhoneFile file, bool random, bool verify = true)
        {
            lock (_lock)
            {
                if (!_init)
                    Init();

                string tempPath = Path.Combine(Path.GetTempPath(), BasePath, dir);
                if (!Directory.Exists(tempPath))
                    Directory.CreateDirectory(tempPath);

                FileInfo dest = new FileInfo(Path.GetTempFileName());
                if (!random)
                    dest = new FileInfo(Path.Combine(tempPath, GetFileName(file)));

                FileInfo src = GetOriginalFile(backup, file);
                string srcHash = "", destHash = "";
                if (verify)
                    srcHash = Util.MD5File(src);

                // Dont copy if it exist..
                if (File.Exists(dest.FullName) && Util.MD5File(dest) == srcHash)
                    return dest;

                // if we dent copy to the src
                if (src != dest)
                    File.Copy(src.FullName, dest.FullName, true);

                if (verify)
                {
                    destHash = Util.MD5File(dest);
                    if (srcHash != destHash)
                    {
                        Clean(dest.FullName);
                        throw new IOException("File copy failed. Reason: Hashes do not match!!");
                    }
                }
                return dest;
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <param name="random"></param>
 /// <returns></returns>
 public FileInfo GetWorkingFile(IPhoneBackup backup, IPhoneFile file, bool random)
 {
     return GetWorkingFile("", backup, file, random);
 }
 /// <summary>
 /// This returns a random file in a temporary location with the file
 /// name as Tuple.
 /// 
 /// Item1 = correct fileName
 /// Item2 = the fileInfo about the random file created
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <returns></returns>
 public Tuple<string, FileInfo> GetRandomFile(IPhoneBackup backup, IPhoneFile file)
 {
     FileInfo fileInfo = GetWorkingFile(backup, file, true);
     string name = GetFileName(file);
     return Tuple.Create(name, fileInfo);
 }
 public FileInfo GetOriginalFile(IPhoneBackup backup, IPhoneFile file)
 {
     string src = Path.Combine(backup.Path, file.Key);
     return new FileInfo(src);
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <param name="dest"></param>
 public void Copy(IPhoneBackup backup, IPhoneFile file, FileInfo dest)
 {
     Copy(backup, file, dest.FullName);
 }
 public IPhoneBackupSelectedArgs(IPhoneBackup selected)
 {
     Selected = selected;
 }
 /// <summary>
 /// Build a list of backups for as a tool strip
 /// </summary>
 /// <param name="backups"></param>
 /// <returns></returns>
 private ToolStripItem[] PopulateBackupChangeList(IPhoneBackup[] backups)
 {
     List<ToolStripItem> items = new List<ToolStripItem>();
     foreach (IPhoneBackup b in backups)
     {
         ToolStripMenuItem itm = new ToolStripMenuItem(b.ToString());
         itm.Tag = b;
         itm.Click += delegate(object se, EventArgs arg)
         {
             ToolStripMenuItem me = se as ToolStripMenuItem;
             if (me != null)
             {
                 SelectBackup(me.Tag as IPhoneBackup);
             }
         };
         items.Add(itm);
     }
     return items.ToArray();
 }
 private void OnSelectedBackup(IPhoneBackup backup)
 {
     if (SelectedBackup != null)
     {
         SelectedBackup(this, new IPhoneBackupSelectedArgs(backup));
     }
 }
        public void SelectBackup(IPhoneBackup backup)
        {
            folderList.Items.Clear();
            fileList.Items.Clear();

            OnSelectedBackup(backup);

            UpdateTitle(backup.DisplayName);

            FileManager fm = FileManager.Current;
            List<IPhoneApp> apps = backup.GetApps();
            foreach (var app in apps)
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Tag = app;
                lvi.Text = app.Name;
                lvi.SubItems.Add(app.Files != null ? app.Files.Count.ToString() : "N/A");
                folderList.Items.Add(lvi);
            }
        }
 /// <summary>
 /// Returns a non random file
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <returns></returns>
 public FileInfo GetWorkingFile(IPhoneBackup backup, IPhoneFile file)
 {
     return GetWorkingFile(backup, file, false);
 }
        /// <summary>
        /// Get a working file in the directory Temp/${InvokingClassName}/filename
        /// 
        /// This to avoid confilcts but a will to retain the name
        /// </summary>
        /// <param name="backup"></param>
        /// <param name="file"></param>
        /// <returns></returns>
        public FileInfo GetWorkingFileCurrentClass(IPhoneBackup backup, IPhoneFile file)
        {
            StackTrace trace = new StackTrace();
            StackFrame frame = trace.GetFrame(1);
            Type klass = frame.GetMethod().ReflectedType;

            return GetWorkingFile(string.Format("${0}", klass.Name), backup, file, false);
        }
        public static IPhoneBackup New(DirectoryInfo path)
        {
            try
            {
                string filename = System.IO.Path.Combine(path.FullName, "Info.plist");
                PListRoot root = PListRoot.Load(filename);
                PListDict dict = root.Root as PListDict;

                IPhoneBackup backup = new IPhoneBackup();
                backup.Path = path.FullName;

                foreach (var p in dict)
                {
                    switch (p.Key)
                    {
                        case "Device Name":
                            backup.DeviceName = p.Value().ToString();
                            break;
                        case "Display Name":
                            backup.DisplayName = p.Value().ToString();
                            break;
                        case "Last Backup Date":
                            backup.LastBackupDate = p.Value().ToString();
                            break;
                    }
                }
                return backup;
            }
            catch (Exception e)
            {
                throw new FileLoadException("No backup at " + path, e);
            }
        }
 private void btnOk_Click(object sender, EventArgs e)
 {
     Selected = listBackups.SelectedItem as IPhoneBackup;
     Close();
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="backup"></param>
 /// <param name="file"></param>
 /// <param name="dest"></param>
 public void Copy(IPhoneBackup backup, IPhoneFile file, string dest)
 {
     lock (_lock)
     {
         string src = Path.Combine(backup.Path, file.Key);
         dest = Path.Combine(dest, GetFileName(file));
         if (src != dest)
             File.Copy(src, dest, true);
     }
 }