Example #1
0
        private void PackagesListBtn2_Click(object sender, EventArgs e)
        {
            if (PackagesNameTxt.Text.Trim() == "")
            {
                MessageBox.Show("请输入包名");
                return;
            }
            this.PackagesListComboBox.Text = "";
            this.PackagesListComboBox.Items.Clear();
            PackagesCountTip.Text = String.Format("共{0}个", PackagesListComboBox.Items.Count);
            List <string> packages = null;
            string        r        = "";
            string        result   = "";

            r        = ExecCMD(String.Format("adb shell pm list packages {0}", PackagesNameTxt.Text.Trim()));
            result   = CmdHelper.GetCMDResult(r);
            packages = ADBCommand.GetPackagesList(result);

            foreach (var item in packages)
            {
                this.PackagesListComboBox.Items.Add(item);
                PackagesListComboBox.SelectedIndex = 0;
            }
            PackagesCountTip.Text = String.Format("共{0}个", PackagesListComboBox.Items.Count);
        }
Example #2
0
        public virtual void DeleteItems(List <string> lsDirs, List <string> lsFiles)
        {
            /*
             * foreach (string dir in lsDirs)
             * {
             *  ADBCommand command = new ADBCommand();
             *  CommandResult rez = command.DeleteObject(dir);
             * }
             * foreach (string file in lsFiles)
             * {
             *  ADBCommand command = new ADBCommand();
             *  CommandResult rez = command.DeleteObject(file);
             * }
             */
            List <FileOperation> lstItems = new List <FileOperation>();

            foreach (string dir in lsDirs)
            {
                FileOperation fo = new FileOperation();
                fo.Source = dir;
                lstItems.Add(fo);
            }
            foreach (string file in lsFiles)
            {
                FileOperation fo = new FileOperation();
                fo.Source = file;
                lstItems.Add(fo);
            }
            ADBCommand    command = new ADBCommand();
            CommandResult rez     = command.DeleteObjects(lstItems, true);
        }
Example #3
0
        public virtual FileObject[] GetAllFromFolder(string folder, ref string error)
        {
            List <FileObject> sFileNames = new List <FileObject>();

            /*
             * FileObject fo = new FileObject();
             * fo.Name = "test";
             * fo.IsFolder = true;
             * fo.Attr = "-rwxrwx--x";
             * fo.Perm1 = "root";
             * fo.IsLink = true;
             * sFileNames.Add(fo);
             *
             * FileObject fo1 = new FileObject();
             * fo1.Name = "test1";
             * fo1.IsFolder = true;
             *
             * sFileNames.Add(fo1);
             *
             * FileObject fo2 = new FileObject();
             * fo2.Name = "test.txt";
             * fo2.IsFolder = false;
             * fo2.Size = "100";
             * sFileNames.Add(fo2);
             *
             * FileObject fo3 = new FileObject();
             * fo3.Name = "test1.doc";
             * fo3.IsFolder = false;
             * fo2.Size = "200";
             * fo2.IsLink = true;
             * sFileNames.Add(fo3);
             */
            ADBCommand    command = new ADBCommand();
            CommandResult rez     = command.ListDirectory(folder);

            if (rez.IsSuccess)
            {
                try
                {
                    CommandResultHelper helper = new CommandResultHelper();
                    sFileNames = helper.GetItems(rez.Message, enGetFileType.FilesAndFolders);
                }
                catch (Exception)
                {
                }
                if (sFileNames.Count == 0)
                {
                    if (rez.Message.EndsWith(" Permission denied\r\n"))
                    {
                        error = rez.Message;
                    }
                }
            }
            else
            {
                error = rez.Message;
            }

            return(sFileNames.ToArray());
        }
Example #4
0
        public virtual void SetFolderName(IFolderObject folderObj, string sName)
        {
            string sOldFile = folderObj.PathString;
            string sOld     = string.Format("{0}/{1}", GetBaseFolder(), sOldFile);
            string sNew     = string.Format("{0}/{1}", GetBaseFolder(), sName);

            ADBCommand    command = new ADBCommand();
            CommandResult rez     = command.Rename(sOld, sNew);
        }
Example #5
0
        private void Form1_Load(object sender, EventArgs e)
        {
            if (ADBCommand.CheckADB())
            {
                GetDevicesBtn_Click(null, null);
            }

            if (PackagesTypeComboBox.Items.Count >= 0)
            {
                PackagesTypeComboBox.SelectedIndex = 0;
            }
        }
Example #6
0
        public PreferencesForm()
        {
            InitializeComponent();

            DeviseAddr addr = new DeviseAddr();

            if (addr.IsValid())
            {
                tbIP.Text   = addr.IP;
                tbPort.Text = addr.PORT;
            }

            if (!string.IsNullOrEmpty(addr.ADBPath))
            {
                tbADB.Text = addr.ADBPath;
            }
            else
            {
                tbADB.Text = ADBRunner.FindADB();
            }

            if (!string.IsNullOrEmpty(addr.ConnectionType))
            {
                rbUSB.Checked = addr.ConnectionType.Equals("usb");
            }

            cbDevices.Items.Clear();
            ADBCommand    commandDev = new ADBCommand();
            CommandResult retDev     = commandDev.Devices();

            if (retDev.IsSuccess)
            {
                foreach (var str in retDev.Message.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                {
                    if (!string.IsNullOrEmpty(str))
                    {
                        string[] s = str.Split(' ');
                        if (s.Any())
                        {
                            cbDevices.Items.Add(s[0]);
                        }
                    }
                }
            }

            if (!string.IsNullOrEmpty(addr.UsbDevice))
            {
                if (cbDevices.Items.Contains(addr.UsbDevice))
                {
                    cbDevices.SelectedItem = addr.UsbDevice;
                }
            }
        }
 public MainWindowViewModel()
 {
     IsConnected    = false;
     ConnectCommand = new DelegateCommand((o) =>
     {
         Properties.Settings.Default.IpAddress = IpAddress;
         Properties.Settings.Default.Save();
         ADBCommand.ConnectServer(IpAddress);  IsConnected = true;
     });
     DisconnectCommand = new DelegateCommand((o) => { if (IsConnected == true)
                                                      {
                                                          ADBCommand.DisconnectServer();
                                                      }
                                                      IsConnected = false; });
     HomeCommand = new DelegateCommand((o) => { if (IsConnected == true)
                                                {
                                                    ADBCommand.ADBActionKey(ConsoleKey.Escape);
                                                }
                                       }, (o) => true);
     SelectCommand = new DelegateCommand((o) => { if (IsConnected == true)
                                                  {
                                                      ADBCommand.ADBActionKey(ConsoleKey.Enter);
                                                  }
                                         }, (o) => true);
     UpCommand = new DelegateCommand((o) => { if (IsConnected == true)
                                              {
                                                  ADBCommand.ADBActionKey(ConsoleKey.UpArrow);
                                              }
                                     }, (o) => true);
     DownCommand = new DelegateCommand((o) => { if (IsConnected == true)
                                                {
                                                    ADBCommand.ADBActionKey(ConsoleKey.DownArrow);
                                                }
                                       }, (o) => true);
     LeftCommand = new DelegateCommand((o) => { if (IsConnected == true)
                                                {
                                                    ADBCommand.ADBActionKey(ConsoleKey.LeftArrow);
                                                }
                                       }, (o) => true);
     RightCommand = new DelegateCommand((o) => { if (IsConnected == true)
                                                 {
                                                     ADBCommand.ADBActionKey(ConsoleKey.RightArrow);
                                                 }
                                        }, (o) => true);
     BackCommand = new DelegateCommand((o) => { if (IsConnected == true)
                                                {
                                                    ADBCommand.ADBActionKey(ConsoleKey.Backspace);
                                                }
                                       }, (o) => true);
 }
Example #8
0
        public virtual FileObject[] GetFoldersFromFolder(string folder)
        {
            List <FileObject> sFileNames = new List <FileObject>();

            ADBCommand    command = new ADBCommand();
            CommandResult rez     = command.ListDirectory(folder);

            if (rez.IsSuccess)
            {
                CommandResultHelper helper = new CommandResultHelper();
                sFileNames = helper.GetItems(rez.Message, enGetFileType.FoldersOnly);
            }

            return(sFileNames.ToArray());
        }
Example #9
0
        /// <summary>
        /// 获取设备按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GetDevicesBtn_Click(object sender, EventArgs e)
        {
            DevicesComboBox.Items.Clear();
            DeviceNumTip.Text = String.Format("共{0}个设备", DevicesComboBox.Items.Count);

            devices = ADBCommand.GetDevices();
            if (devices == null || devices.Count == 0)
            {
                return;
            }
            foreach (Device item in devices)
            {
                DevicesComboBox.Items.Add(String.Format("{0}_{1}_{2}", item.ID, item.status, item.model));
            }
            DevicesComboBox.SelectedIndex = 0;
            DeviceNumTip.Text             = String.Format("共{0}个设备", DevicesComboBox.Items.Count);
        }
Example #10
0
        private void PackagesListBtn_Click(object sender, EventArgs e)
        {
            this.PackagesListComboBox.Text = "";
            this.PackagesListComboBox.Items.Clear();
            PackagesCountTip.Text = String.Format("共{0}个", PackagesListComboBox.Items.Count);
            List <string> packages = null;
            string        r        = "";
            string        result   = "";

            switch (PackagesType)
            {
            case 0:    //第三方应用
                r = ExecCMD("adb shell pm list packages -3");
                break;

            case 1:    //所有应用
                r = ExecCMD("adb shell pm list packages");
                break;

            case 2:    //系统应用
                r = ExecCMD("adb shell pm list packages -s");
                break;

            default:
                break;
            }
            result   = CmdHelper.GetCMDResult(r);
            packages = ADBCommand.GetPackagesList(result);

            foreach (var item in packages)
            {
                this.PackagesListComboBox.Items.Add(item);
                PackagesListComboBox.SelectedIndex = 0;
            }
            PackagesCountTip.Text = String.Format("共{0}个", PackagesListComboBox.Items.Count);
        }
Example #11
0
        public virtual string CreateNewFolder(string path, string dirName)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = GetBaseFolder();
            }
            else
            {
                path = string.Format("{0}/{1}", GetBaseFolder(), path);
            }

            string name    = dirName;
            string current = name;
            int    i       = 0;

            FileObject[] fo = GetFoldersFromFolder(string.Format("{0}/.", path).Replace("//", "/"));

            while (fo.ToList().FirstOrDefault(x => x.Name == current) != null)
            {
                i++;
                current = String.Format("{0} {1}", name, i);
            }

            string sret = path.EndsWith("/") ? (path + current) : (path + "/" + current);

            ADBCommand    command = new ADBCommand();
            CommandResult rez     = command.CreateDirectory(sret);

            if (!rez.IsSuccess)
            {
                rez.ShowMessage();
                current = null;
            }

            return(current);
        }
Example #12
0
        public virtual CommandResult Copy(string sDestination, List <string> lItems, ref List <string> folders, ref List <string> files)
        {
            if (lItems.Count > 0)
            {
                bool bRealFolder = false;

                try
                {
                    DirectoryInfo diF = new DirectoryInfo(sDestination);
                    if (diF.Exists)
                    {
                        bRealFolder = true;
                    }
                }
                catch (Exception)
                {
                }

                string sDestinationFolder = bRealFolder ? sDestination : string.Format("{0}/{1}", GetBaseFolder(), sDestination).Replace("//", "/");

                string itemCheck = lItems[0];
                if (itemCheck.StartsWith("[virtualfolder]") || itemCheck.StartsWith("[virtualfile]"))
                {
                    List <FileOperation> lstItems = new List <FileOperation>();
                    foreach (string item in lItems)
                    {
                        string sFullName = item.Substring(item.IndexOf('\\') + 1);
                        string sItem     = string.Format("{0}{1}{2}", GetBaseFolder(), FD, sFullName);

                        string sName = sFullName.Substring(sFullName.LastIndexOf(FD[0]) + 1);
                        sName = sName.Replace(":", "_");

                        string sDest = string.Empty;
                        if (bRealFolder)
                        {
                            sDest = string.Format("{0}{1}{2}", sDestinationFolder, "\\", sName);
                        }
                        else
                        {
                            sDest = string.Format("{0}", sDestinationFolder);
                        }

                        //string sDest = string.Format("{0}{1}{2}", sDestinationFolder, bRealFolder? "\\" : "/", sName);

                        if (item.StartsWith("[virtualfolder]"))
                        {
                            FileOperation fo = new FileOperation();
                            fo.Source      = sItem.Replace("//", "/") + (bRealFolder ? "/" : "");
                            fo.Destination = sDest;
                            fo.IsFolder    = true;

                            lstItems.Add(fo);

                            folders.Add(sName);
                        }
                        if (item.StartsWith("[virtualfile]"))
                        {
                            FileOperation fo = new FileOperation();
                            fo.Source      = sItem.Replace("//", "/");
                            fo.Destination = sDest;
                            fo.IsFolder    = false;

                            lstItems.Add(fo);

                            files.Add(sName);
                        }
                    }
                    ADBCommand    command = new ADBCommand();
                    CommandResult rez     = command.Copy(lstItems, bRealFolder ? enCopyType.Pull : enCopyType.Copy, true);
                    return(rez);
                }
                else
                {
                    List <FileOperation> lstItems = new List <FileOperation>();
                    foreach (string item in lItems)
                    {
                        string sName = item.Substring(item.LastIndexOf('\\') + 1);

                        FileInfo      fi    = new FileInfo(item);
                        bool          bFile = fi.Exists;
                        DirectoryInfo di    = new DirectoryInfo(item);
                        bool          bDir  = di.Exists;
                        string        sPath = string.Empty;

                        bool isFolderEmpty = false;

                        if (bFile)
                        {
                            sPath = string.Format("{0}/{1}", sDestinationFolder, sName).Replace("//", "/");
                            files.Add(sName);
                        }
                        else
                        {
                            if (bDir)
                            {
                                isFolderEmpty = IsDirectoryEmpty(item);
                                sPath         = string.Format("{0}/{1}", sDestinationFolder, sName).Replace("//", "/");
                                folders.Add(sName);
                            }
                        }

                        FileOperation fo = new FileOperation();
                        fo.IsFolder      = bDir;
                        fo.Destination   = sPath;
                        fo.Source        = item;
                        fo.IsFolderEmpty = isFolderEmpty;
                        lstItems.Add(fo);
                    }

                    ADBCommand    command = new ADBCommand();
                    CommandResult rez     = command.Copy(lstItems, enCopyType.Push, true);
                    return(rez);
                }
            }
            return(null);
        }
Example #13
0
        public virtual void ExploreMenuItem_Click(object sender, EventArgs e)
        {
            if (Verb.Equals(ConsoleVerb))
            {
                ConsoleForm cf = new ConsoleForm();
                cf.ShowDialog();
            }
            else
            if (Verb.Equals(PreferencesVerb))
            {
                ContextMenuEventArgs c = (ContextMenuEventArgs)e;

                //NativeWindow nativeWindow = new NativeWindow();
                //nativeWindow.AssignHandle(c.CommandInfo.hwnd);

                PreferencesForm pf = new PreferencesForm();
                pf.ShowDialog();
            }
            else if (Verb.Equals(ConnectVerb))
            {
                DeviseAddr addr = new DeviseAddr();
                if (!string.IsNullOrEmpty(addr.ConnectionType) && addr.ConnectionType.Equals("usb") &&
                    !string.IsNullOrEmpty(addr.UsbDevice))
                {
                    //ADBCommand commandD = new ADBCommand();
                    //CommandResult retD = commandD.Disconnect(true);
                }
                else
                {
                    ADBCommand    commandD = new ADBCommand();
                    CommandResult retD     = commandD.Disconnect();
                }

                ADBCommand    command = new ADBCommand();
                CommandResult ret     = command.Connect();
                ret.ShowMessage();
                ADBCommand    commandDev = new ADBCommand();
                CommandResult retDev     = commandDev.Devices();
                if (retDev.IsSuccess)
                {
                    Dictionary <string, string> dicDev = new Dictionary <string, string>();
                    foreach (var str in retDev.Message.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries))
                    {
                        if (!string.IsNullOrEmpty(str))
                        {
                            string[] s = str.Split(' ');
                            if (s.Any())
                            {
                                string sDevType = string.Empty;
                                if (s.Length > 1)
                                {
                                    sDevType = s[1];
                                }
                                if (!dicDev.ContainsKey(s[0]))
                                {
                                    dicDev.Add(s[0], sDevType);
                                }
                            }
                        }
                    }

                    if (dicDev.Count == 0)
                    {
                        MessageBox.Show("List of devices attached - is empty",
                                        "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    if (!dicDev.ContainsKey(commandDev.CurrentDevice()))
                    {
                        MessageBox.Show("List of devices attached - does not contain selected device",
                                        "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }

                    if (dicDev.ContainsKey(commandDev.CurrentDevice()) && dicDev[commandDev.CurrentDevice()].Equals("unauthorized"))
                    {
                        MessageBox.Show("Please authorize this computer on dialog in device,\r\nAnd after that, click Ok button to continue",
                                        "Warning! " + retDev.Message.Replace("\t", " - "), MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    IntPtr pParrent = ItemIdList.Create(null, _folderObj.PathData).Ptr;
                    Shell32.SHChangeNotify(ShellChangeEvents.UpdateDir,
                                           ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                                           pParrent,
                                           IntPtr.Zero);
                    Marshal.FreeCoTaskMem(pParrent);
                }
            }
            else if (Verb.Equals(DisconnectVerb))
            {
                ADBCommand    command = new ADBCommand();
                CommandResult ret     = command.Disconnect();
                ret.ShowMessage();

                IntPtr pParrent = ItemIdList.Create(null, _folderObj.PathData).Ptr;
                Shell32.SHChangeNotify(ShellChangeEvents.UpdateDir,
                                       ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                                       pParrent,
                                       IntPtr.Zero);
                Marshal.FreeCoTaskMem(pParrent);
            }
            else if (Verb.Equals(InstallApkVerb))
            {
                ADBCommand    command = new ADBCommand();
                CommandResult ret     = command.Install(_folderObj.PathString);
                ret.ShowMessage();
            }
            else if (Verb.Equals(CreateScreenshotVerb))
            {
                ADBCommand    command = new ADBCommand();
                CommandResult ret     = command.CreateScreenShot(_folderObj.PathString);
                ret.ShowMessage();
                // MessageBox.Show("Create Screenshot to: " + _folderObj.PathString);
            }
            else if (Verb.Equals(InfoVerb))
            {
                StringCollection sc = new StringCollection();

                PermissionsForm pf = new PermissionsForm();
                pf.SetData(_items, _folderObj);
                pf.ShowDialog();

                /*
                 * if (_folderObj.GetParrent() != null)
                 * {
                 *  _folderObj.GetParrent().RefreshItems(_items);
                 * }
                 */
                //_folderObj.RefreshItems(_items);
            }
            else if (Verb.Equals(NewFolderVerb))
            {
                _folderObj.NewFolder();
            }
            else if (Verb.Equals(RenameVerb))
            {
                using (Malloc m = Shell32.GetMalloc())
                {
                    byte[][]      clone = (byte[][])fqPidl.Clone();
                    List <byte[]> lsn   = clone.ToList();
                    lsn.RemoveAt(lsn.Count - 1);
                    clone = lsn.ToArray();
                    ItemIdList itemIdList       = ItemIdList.Create(m, fqPidl);
                    ItemIdList itemIdListFolder = ItemIdList.Create(m, clone);
                    Shell32.SHOpenFolderAndSelectItems(itemIdListFolder.Ptr, 1, new[] { itemIdList.Ptr }, Shell32.OFASI_EDIT);
                }
            }
            else if (Verb.Equals(CopyVerb))
            {
                DataObject       dobj      = new DataObject();
                List <string>    file_list = new List <string>();
                StringCollection sc        = new StringCollection();
                foreach (IFolderObject folderObject in _items)
                {
                    string sAdd = ((folderObject.Attributes & FolderAttributes.Folder) == FolderAttributes.Folder)
                            ? "[virtualfolder]"
                            : "[virtualfile]";
                    file_list.Add(string.Format("{0}{1}\\{2}", sAdd, CodePath.Code(folderObject.PathData), folderObject.PathString));
                    sc.Add(string.Format("{0}{1}\\{2}", sAdd, CodePath.Code(folderObject.PathData), folderObject.PathString));
                    //sc.Add(folderObject.PathString);
                    //file_list.Add(string.Format("{0}\\{1}", sAdd, folderObject.PathString));
                }
                dobj.SetData(DataFormats.FileDrop, (System.String[])file_list.ToArray());
                dobj.SetData(typeof(StringCollection), sc);
                Clipboard.SetDataObject(dobj, false);
                //Clipboard.SetFileDropList(sc);
            }
            else if (Verb.Equals(PasteLinkVerb))
            {
                List <string> lFiles = new List <string>();
                if (_folderObj.DataObject != null)
                {
                    DataObject       dobj = _folderObj.DataObject;
                    StringCollection z    = (StringCollection)dobj.GetData(typeof(StringCollection));
                    foreach (string s in z)
                    {
                        if (s.StartsWith("[virtualfolder]") || s.StartsWith("[virtualfile]"))
                        {
                            lFiles.Add(s);
                        }
                    }

                    lFiles.Add(_folderObj.PathString);
                    _folderObj.CopyItems(null, lFiles);

                    _folderObj.DataObject = null;
                }
                else
                if (Clipboard.ContainsData("DataObject"))
                {
                    DataObject       dobj = (DataObject)Clipboard.GetDataObject();
                    StringCollection z    = (StringCollection)dobj.GetData(typeof(StringCollection));
                    if (z != null)
                    {
                        foreach (string s in z)
                        {
                            if (s.StartsWith("[virtualfolder]"))
                            {
                                lFiles.Add(s);
                            }
                        }

                        lFiles.Add(_folderObj.PathString);
                        _folderObj.CopyItems(null, lFiles);
                    }
                }
            }
            else if (Verb.Equals(PasteVerb))
            {
                List <string> lFiles = new List <string>();
                //only for external
                if (Clipboard.ContainsFileDropList())
                {
                    StringCollection files = Clipboard.GetFileDropList();
                    foreach (string file in files)
                    {
                        if (!file.StartsWith("[virtualfolder]") && !file.StartsWith("[virtualfile]"))
                        {
                            lFiles.Add(file);
                        }
                    }
                }

                if (_folderObj.DataObject != null)
                {
                    DataObject       dobj = _folderObj.DataObject;
                    StringCollection z    = (StringCollection)dobj.GetData(typeof(StringCollection));
                    foreach (string s in z)
                    {
                        lFiles.Add(s);
                    }
                    _folderObj.DataObject = null;
                }
                else
                if (Clipboard.ContainsData("DataObject"))
                {
                    DataObject       dobj = (DataObject)Clipboard.GetDataObject();
                    StringCollection z    = (StringCollection)dobj.GetData(typeof(StringCollection));
                    if (z != null)
                    {
                        foreach (string s in z)
                        {
                            lFiles.Add(s);
                        }
                        //lFiles = DataObjectHelper.GetFiles(dobj);
                    }
                }

                string sr = string.Empty;
                foreach (string file in lFiles)
                {
                    sr += file + "\r\n";
                }
                sr += "to\r\n" + _folderObj.PathString;
                //MessageBox.Show(sr);
                Debug.WriteLine(sr);
                _folderObj.CopyItems(_folderObj, lFiles);
            }
            else if (Verb.Equals(DeleteVerb))
            {
                _folderObj.DeleteItems(_items);
            }
            else
            {
                using (Malloc m = Shell32.GetMalloc())
                {
                    ContextMenuEventArgs c = (ContextMenuEventArgs)e;

                    ShellExecuteInfo sei = new ShellExecuteInfo();
                    sei.cbSize = (uint)Marshal.SizeOf(typeof(ShellExecuteInfo));
                    sei.fMask  = ShellExecuteOptions.IdList | ShellExecuteOptions.ClassName;
                    ItemIdList itemIdList = ItemIdList.Create(m, fqPidl);
                    sei.lpIDList = itemIdList.Ptr;
                    sei.lpClass  = "folder";
                    sei.hwnd     = c.CommandInfo.hwnd;
                    sei.nShow    = c.CommandInfo.nShow;
                    sei.lpVerb   = Verb;

                    int result = Shell32.ShellExecuteEx(ref sei);

                    //m.Free(itemIdList.Ptr);

                    if (result == 0)
                    {
                        int lastError = Marshal.GetLastWin32Error();
                        throw new Exception("ShellExecuteEx failed; last error = " + lastError);
                    }
                }
            }
        }
Example #14
0
        private void btnApply_Click(object sender, EventArgs e)
        {
            lvResult.Items.Clear();

            bool   bRemount        = false;
            string sCommandRemount = null;

            ADBRunner runner = new ADBRunner();

            foreach (IFolderObject item in Items)
            {
                string spath = string.Format("/{0}", item.PathString);
                spath = spath.Replace(" ", "\\ ")
                        .Replace("(", "\\(")
                        .Replace(")", "\\)")
                        .Replace("'", "\\'")
                        .Replace("&", "\\&");

                string sAttr  = null;
                string sOwner = null;
                string sGroup = null;
                GetAttributeOwnerGroup(Items[0], ref sAttr, ref sOwner, ref sGroup);

                if (cbApplyOwnerGroup.Checked)
                {
                    if (!string.IsNullOrEmpty(cbOwner.Text) || !string.IsNullOrEmpty(cbGroup.Text))
                    {
                        if (!cbOwner.Text.Equals(sOwner) || !cbGroup.Text.Equals(sGroup))
                        {
                            string sCommandOwnerGroup = tbOwnerGroup.Text;
                            sCommandOwnerGroup = sCommandOwnerGroup.Replace("[DIR]", spath);
                            sCommandOwnerGroup = sCommandOwnerGroup.Replace("[OWNER]", !string.IsNullOrEmpty(cbOwner.Text) ? cbOwner.Text : sOwner);
                            sCommandOwnerGroup = sCommandOwnerGroup.Replace("[GROUP]", !string.IsNullOrEmpty(cbGroup.Text) ? cbGroup.Text : sGroup);
                            bool bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandOwnerGroup), CommandDialog.None, false);
                            AddResult(string.Format("/{0}", item.PathString), sCommandOwnerGroup, runner.strMessage);
                            if ((cbRemount.Checked) && (runner.strMessage.Contains("Read-only file system")))
                            {
                                sCommandRemount = tbRemount.Text;
                                string sParrent = spath.Substring(0, spath.LastIndexOf('/') + 1);
                                sCommandRemount = sCommandRemount.Replace("[DIR]", sParrent);
                                bret            = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandRemount), CommandDialog.None, false);
                                AddResult("Remount to RW", "", "");
                                AddResult(string.Format("/{0}", item.PathString), sCommandRemount, runner.strMessage);
                                if (string.IsNullOrEmpty(runner.strMessage))
                                {
                                    bRemount = true;
                                }
                                bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandOwnerGroup), CommandDialog.None, false);
                                AddResult(string.Format("/{0}", item.PathString), sCommandOwnerGroup, runner.strMessage);
                            }
                        }
                        else
                        {
                            AddResult(string.Format("/{0}", item.PathString), "Owner & Group not changed", "Skeep");
                        }
                    }
                }

                if (cbApplyPerm.Checked)
                {
                    string sCommandPerm = tbPermissions.Text;
                    sCommandPerm = sCommandPerm.Replace("[DIR]", spath);
                    sCommandPerm = sCommandPerm.Replace("[OCTAL]", int.Parse(GetOctal()).ToString());
                    bool bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandPerm), CommandDialog.None, false);
                    AddResult(string.Format("/{0}", item.PathString), sCommandPerm, runner.strMessage);
                    if ((cbRemount.Checked) && (runner.strMessage.Contains("Read-only file system")))
                    {
                        sCommandRemount = tbRemount.Text;
                        string sParrent = spath.Substring(0, spath.LastIndexOf('/') + 1);
                        sCommandRemount = sCommandRemount.Replace("[DIR]", sParrent);
                        bret            = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandRemount), CommandDialog.None, false);
                        AddResult("Remount to RW", "", "");
                        AddResult(string.Format("/{0}", item.PathString), sCommandRemount, runner.strMessage);
                        if (string.IsNullOrEmpty(runner.strMessage))
                        {
                            bRemount = true;
                        }
                        bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandPerm), CommandDialog.None, false);
                        AddResult(string.Format("/{0}", item.PathString), sCommandPerm, runner.strMessage);
                    }
                }
            }

            if (bRemount && !string.IsNullOrEmpty(sCommandRemount))
            {
                sCommandRemount = sCommandRemount.Replace(",rw ", ",ro ");
                bool bret = runner.LaunchProcess(ADBCommand.SelectDevice(sCommandRemount), CommandDialog.None, false);
                AddResult("Remount back to RO", sCommandRemount, runner.strMessage);
            }

            if (Items.Any())
            {
                if (_folderObj != null && _folderObj.ShellView != null)
                {
                    _folderObj.ShellView.Refresh();

                    foreach (IFolderObject item in Items)
                    {
                        List <byte[]> ls = new List <byte[]>();
                        ls.Add(item.PathData[item.PathData.Length - 1]);
                        int rt = _folderObj.ShellView.SelectItem(
                            ItemIdList.Create(null, (byte[][])ls.ToArray().Clone()).Ptr,
                            _SVSIF.SVSI_SELECT | _SVSIF.SVSI_SELECTIONMARK);
                    }
                }

                /*
                 * IntPtr pDelObj = ItemIdList.Create(null, Items[0].PathData).Ptr;
                 * Shell32.SHChangeNotify(ShellChangeEvents.Delete,
                 *  ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                 *  pDelObj,
                 *  IntPtr.Zero);
                 * Marshal.FreeCoTaskMem(pDelObj);
                 */
                /*
                 * List<byte[]> bt = ((byte[][])(Items[0].PathData.Clone())).ToList();
                 * //bt.RemoveAt(bt.Count - 1);
                 * //bt.RemoveAt(bt.Count - 1);
                 * IntPtr pParrent = ItemIdList.Create(null, bt.ToArray()).Ptr;
                 * Shell32.SHChangeNotify(ShellChangeEvents.UpdateDir,
                 *           ShellChangeFlags.IdList | ShellChangeFlags.Flush,
                 *           pParrent,
                 *           IntPtr.Zero);
                 * Marshal.FreeCoTaskMem(pParrent);
                 */
            }

            MessageBox.Show("Operation Complete!\r\nClick 'Details' button to view result log", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);

            //DialogResult = DialogResult.OK;

            //Close();
            //-s 127.0.0.1:62001 shell "su -c 'chmod 777 /data/local/tmp'"
            //-s 127.0.0.1:62001 shell "su -c 'chown root.root /data/local/tmp'"
            //-s 127.0.0.1:62001 shell "su -c 'mount -o remount,rw /'"
        }