//深度清理之后需要恢复
 private void BeginToRestore()
 {
     string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
     appDataPath = appDataPath.Replace("\\", "/");
     string restorePath = appDataPath + "/Tenorshare/Temp/DeviceBackup/Restore";
     DirectoryInfo dir = new DirectoryInfo(appDataPath);
     if (!dir.Exists)
     {
         dir.Create();
     }
     m_iPhoneState = ManageiPhoneState.Restore;
     m_IDeviceBackUpEx.StartToRestore(restorePath);
 }
        public void StartToCleanFiles()
        {
            //m_timeElapsed = 0;
            //m_elapsedTimer.Start();
            m_iPhoneState = ManageiPhoneState.Clean;
            Dispatcher.Invoke(DispatcherPriority.Send, new Action(
                delegate()
                {
                    m_tbCount.Text = "0";
                    m_tbSize.Text = "0";
                    m_tbElapsed.Text = "00:00";
                }
                ));
            m_cleanTimer.Start();

            Console.WriteLine(m_totalSize + "--------------beginTotalSize");
            Console.WriteLine(m_totalCount + "--------------beginTotalCount");

            for(int i = 0;i < m_selectList.Count;i++)
            {
                m_IScanDeviceEx = m_IScanDeviceList[i];
                m_IScanDeviceEx.StartToClean();
                m_scanIndex = i;
                if (m_IScanDeviceEx.IsFinishScan())
                {
                    UInt64 size = 0;
                    int count = 0;
                    string fileSize = m_IScanDeviceEx.GetProcessInfo("fileSize");
                    string fileCount = m_IScanDeviceEx.GetProcessInfo("fileCount");
                    UInt64.TryParse(fileSize, out size);
                    Int32.TryParse(fileCount, out count);
                    Console.WriteLine(m_selectList[i].FileSize + "++++++++++++++++size");
                    Console.WriteLine(m_selectList[i].FileCount + "++++++++++++++++++count");
                    m_totalSize = m_totalSize - m_selectList[i].FileSize;
                    if (m_totalSize < 0)
                        m_totalSize = 0;
                    m_totalCount = m_totalCount - m_selectList[i].FileCount;
                    if (m_totalCount < 0)
                        m_totalCount = 0;
                    m_selectList[i].FileSize = size;
                    m_selectList[i].FileCount = count;
                    Console.WriteLine(m_totalSize + "--------------totalSize");
                    Console.WriteLine(m_totalCount + "--------------totalCount");

                    //Dispatcher.Invoke(DispatcherPriority.Normal, new Action(
                    //    delegate()
                    //    {
                    //        m_tbSize.Text = StringToSize(m_totalSize);
                    //        m_tbCount.Text = m_totalCount.ToString();
                    //    }
                    //    ));

                    this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (ThreadStart) delegate()
                        {
                            m_tbSize.Text = StringToSize(m_totalSize);
                            m_tbCount.Text = m_totalCount.ToString();
                        }
                    );
                }                                
            }
            
            if(m_haveToBackUp == true)
            {
                m_IDeviceBackUpEx.DeepCleanFinish();
                Tips = "Restoring data. Please do not disconnect device in the process of restore.";
                BeginToRestore();
                m_timeElapsed = 0;
                m_elapsedTimer.Start();
                m_restoreTimer.Start();
            }
        }
        private void BeginToScanFiles()
        {
            //m_IScanDeviceEx = new IScanDeviceEx(m_deviceID);
            //m_IScanDeviceEx.InitScanDevice();
            m_totalCount = 0;
            m_totalSize = 0;
            m_scanTimer.Start();
            m_iPhoneState = ManageiPhoneState.Scan;
            m_IScanDeviceList.Clear();
            bool initScan = false;
            
            if (m_selectList.Count != 0)
            {
                _365Care.ScanItemType itemType = new _365Care.ScanItemType();
                for (int i = 0; i < m_selectList.Count; i++)
                {
                    if (m_isStopScan)
                        break;

                    IScanDeviceEx IScanDeviceEx = new IScanDeviceEx(m_deviceID);
                    m_IScanDeviceEx = IScanDeviceEx;
                    if(initScan == false)
                    {
                        IScanDeviceEx.InitScanDevice();
                        initScan = true;
                    }
                    m_IScanDeviceList.Add(IScanDeviceEx);

                    m_scanIndex = i;
                    var file = m_selectList[i];
                    Console.WriteLine(file.FileName + "-----------------");
                    switch (file.FileName)
                    {
                        case "Log files":
                            itemType = _365Care.ScanItemType.CrashLogs;
                            Tips = "Log files";
                            break;
                        case "Photo & Video caches":
                            itemType = _365Care.ScanItemType.PhotoCaches;
                            Tips = "Photo & Video caches";
                            break;
                        case "iTunes radio caches":
                            itemType = _365Care.ScanItemType.RadioTemp;
                            Tips = "iTunes radio caches";
                            break;
                        case "Download temp files":
                            itemType = _365Care.ScanItemType.Downloads;
                            Tips = "Download temp files";
                            break;
                        case "App generated junk files":
                            itemType = _365Care.ScanItemType.AppCaches;
                            Tips = "App generated junk files";
                            break;
                        case "User Storage junk files":
                            itemType = _365Care.ScanItemType.UserStorage;
                            Tips = "User Storage junk files";
                            break;
                        case "Safari cache files":
                            itemType = _365Care.ScanItemType.WebAppCookies;
                            Tips = "Safari cache files";
                            break;
                        case "Safari history":
                            itemType = _365Care.ScanItemType.SafariHistory;
                            Tips = "Safari history";
                            break;
                        case "Safari Cookies":
                            itemType = _365Care.ScanItemType.Cookies;
                            Tips = "Safari Cookies";
                            break;
                        case "Call history":
                            itemType = _365Care.ScanItemType.CallingHistory;
                            Tips = "Call history";
                            break;
                        case "Message":
                            itemType = _365Care.ScanItemType.MSM;
                            Tips = "Message";
                            break;
                        case "iOS system junk files":
                            itemType = _365Care.ScanItemType.SurplusFiles;
                            Tips = "iOS system junk files";
                            break;
                        case "iOS notifications":
                            itemType = _365Care.ScanItemType.Notifications;
                            Tips = "iOS notifications";
                            break;
                        case "Active apps":
                            itemType = _365Care.ScanItemType.BackgroundRunningApps;
                            Tips = "Active apps";
                            break;
                        case "App residual files":
                            itemType = _365Care.ScanItemType.AppRemainFiles;
                            Tips = "App residual files";
                            break;
                        case "Webmail caches":
                            itemType = _365Care.ScanItemType.WebmailCaches;
                            Tips = "Webmail caches";
                            break;
                        case "iOS tune-up":
                            itemType = _365Care.ScanItemType.SpeedUp;
                            Tips = "iOS tune-up";
                            break;
                        default:
                            break;
                    }

                    //if (file.FileName.Equals("App generated junk files"))
                    //{
                    //    for (int j = (int)itemType; j < (int)_365Care.ScanItemType.AppTempFiles + 1; j++)
                    //    {
                    //        if (m_isStopScan)
                    //            break;
                    //        ScanDevice(j);
                    //    }
                    //}
                    //else if(file.FileName.Equals("iOS tune-up"))
                    //{
                    //    continue;
                    //}
                    //else
                    //{
                    //    ScanDevice((int)itemType);
                    //}
                    ScanDevice((int)itemType);

                }

            }

        }
        private SpeedUpDetialsPage()
        {
            InitializeComponent();
            InitAllFileDataList();

            m_dataGridView.ItemsSource = m_allFileDataList;
            m_selectList = new ObservableCollection<ClearFilesData>();
            m_IScanDeviceList = new List<IScanDeviceEx>();

            m_elapsedTimer = new DispatcherTimer();
            m_elapsedTimer.Interval = TimeSpan.FromSeconds(1);
            m_elapsedTimer.Tick += SetTimeElapsed;

            m_backUpTimer = new DispatcherTimer();
            m_backUpTimer.Interval = TimeSpan.FromMilliseconds(100);
            m_backUpTimer.Tick += SetBackUpProgress;

            m_scanTimer = new DispatcherTimer();
            m_scanTimer.Interval = TimeSpan.FromMilliseconds(100);
            m_scanTimer.Tick += SetScanProgress;

            m_cleanTimer = new DispatcherTimer();
            m_cleanTimer.Interval = TimeSpan.FromMilliseconds(100);
            m_cleanTimer.Tick += SetCleanProgress;

            m_restoreTimer = new DispatcherTimer();
            m_restoreTimer.Interval = TimeSpan.FromMilliseconds(100);
            m_restoreTimer.Tick += SetRestoreProgress;

            Tips = "Deep clean up junk files and free up extra space to accelerate iOS device.";

            m_iPhoneState = new ManageiPhoneState();
        }
 public void StartToScan()
 {
     //m_selectList.Clear();
     //foreach(var file in m_allFileDataList)
     //{
     //    if(file.IsSelect)
     //    {
     //        m_selectList.Add(file);
     //    }
     //}
     //if(m_selectList.Count == 0)
     //{
     //    MessageBox.Show("Please select any item firstly");
     //    return;
     //}
     m_timeElapsed = 0;
     m_elapsedTimer.Start();
     m_tbCount.Text = "0";
     m_tbSize.Text = "0";
     m_progressBar.Value = 0;
     m_isStopScan = false;
     m_haveToBackUp = false;
     foreach (var item in m_selectList)
     {
         string scanName = item.FileName;
         if (scanName.Equals("Safari cache files") || scanName.Equals("Safari history") || scanName.Equals("Safari Cookies") || scanName.Equals("Call history") || scanName.Equals("Message") ||
             scanName.Equals("iOS system junk files") || scanName.Equals("iOS notifications") || scanName.Equals("iOS tune-up") || scanName.Equals("Active apps") || scanName.Equals("App residual files") || scanName.Equals("Webmail caches"))
         {
             m_haveToBackUp = true;
             break;
         }
     }
     if (m_haveToBackUp)
     {
         //开始备份文件,之后才能扫描
         m_backUpTimer.Start();
         Tips = "Backing up data. Please wait...";
         m_iPhoneState = ManageiPhoneState.BackUp;
         Action scanInfo = new Action(StartToBackUp);
         scanInfo.BeginInvoke(null, scanInfo);
         //StartToBackUp();
     }
     else
     {
         //直接扫描文件,不需要备份
         //BeginToScanFiles();
         m_iPhoneState = ManageiPhoneState.Scan;
         Action scanInfo = new Action(BeginToScanFiles);
         scanInfo.BeginInvoke(null, scanInfo);
     }
 }