Example #1
0
        private void DoDirectoryDelete(
            ListViewItem item
            )
        {
            FileBrowserNode node   = base.TreeNode as FileBrowserNode;
            DialogResult    result = MessageBox.Show("Are you sure that you want to delete the directory called: " + item.Text + "?",
                                                     "File Browser",
                                                     MessageBoxButtons.YesNo);

            if (result == DialogResult.Yes)
            {
                string   path  = node.Path + PathSeparator + item.Text;
                WinError error = FileClient.FileClient.DeleteDirectory(path);

                if (error == WinError.NO_ERROR)
                {
                    TreeNode[] removedItem = node.Nodes.Find(item.Text, false);
                    if (removedItem.Length > 0)
                    {
                        removedItem[0].Remove();
                    }

                    lvFilePage.BeginUpdate();
                    lvFilePage.Items.Remove(item);
                    lvFilePage.EndUpdate();
                    Refresh();
                }
                else
                {
                    string message = "Delete directory operation failed. Error: " + error.ToString();
                    MessageBox.Show(message, "Could not remove directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        private void cm_OnRename(object sender, EventArgs e)
        {
            if (_currentNode != null &&
                _selectedNode != null &&
                _currentNode == _selectedNode)
            {
                FileBrowserNode node    = _currentNode as FileBrowserNode;
                FileBrowserNode parent  = _currentNode.Parent as FileBrowserNode;
                string          newName = "";

                if (node != null &&
                    parent != null)
                {
                    // Determine destingation to copy to
                    RenameDialog renameDialog = new RenameDialog(node.Name, RenameDialog.RENAME_OPERATION.RENAME_DIRECTORY, this);

                    if (renameDialog.ShowDialog() == DialogResult.OK)
                    {
                        newName = renameDialog.GetName();

                        WinError error = FileClient.FileClient.MoveDirectory(parent.Path, parent.Path, node.Name, newName, true);

                        if (error != WinError.NO_ERROR)
                        {
                            string message = "Rename directory operation failed. Error: " + error.ToString();
                            MessageBox.Show(message, "Could not rename directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
        private void cm_OnCreateFolder(object sender, EventArgs e)
        {
            if (_currentNode != null &&
                _selectedNode != null &&
                _currentNode == _selectedNode)
            {
                FileBrowserNode node    = _currentNode as FileBrowserNode;
                string          newName = "";

                if (node != null)
                {
                    // Determine destingation to copy to
                    RenameDialog renameDialog = new RenameDialog("New Folder", RenameDialog.RENAME_OPERATION.NEW_FOLDER_NAME, this);

                    if (renameDialog.ShowDialog() == DialogResult.OK)
                    {
                        newName = node.Path + PathSeparator + renameDialog.GetName();

                        WinError error = FileClient.FileClient.CreateDirectory(newName);

                        if (error != WinError.NO_ERROR)
                        {
                            string message = "Create directory operation failed. Error: " + error.ToString();
                            MessageBox.Show(message, "Could not create new directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }
        private void cm_OnDelete(object sender, EventArgs e)
        {
            if (_currentNode != null &&
                _selectedNode != null &&
                _currentNode == _selectedNode)
            {
                FileBrowserNode node   = _currentNode as FileBrowserNode;
                DialogResult    result = MessageBox.Show("Are you sure that you want to delete the directory called: " + node.Name + "?",
                                                         "File Browser",
                                                         MessageBoxButtons.YesNo);

                if (result == DialogResult.Yes)
                {
                    WinError error = FileClient.FileClient.DeleteDirectory(node.Path);

                    if (error != WinError.NO_ERROR)
                    {
                        string message = "Delete directory operation failed. Error: " + error.ToString();
                        MessageBox.Show(message, "Could not remove directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        node.Remove();
                    }
                }
            }
        }
Example #5
0
        private void DoFileMove(
            ListViewItem item
            )
        {
            FileBrowserNode node        = base.TreeNode as FileBrowserNode;
            string          destination = "";

            // Determine destingation to move to
            SelectDestinationDialog destinationDialog = new SelectDestinationDialog(node.Path, SelectDestinationDialog.SELECT_DESTINATION_OPERATION.MOVE_FILE, plugin);

            if (destinationDialog.ShowDialog() == DialogResult.OK)
            {
                destination = destinationDialog.GetPath() + PathSeparator + item.Text;

                string   path  = node.Path + PathSeparator + item.Text;
                WinError error = FileClient.FileClient.MoveFile(path, destination);

                if (error == WinError.NO_ERROR)
                {
                    lvFilePage.BeginUpdate();
                    lvFilePage.Items.Remove(item);
                    lvFilePage.EndUpdate();
                    Refresh();
                }
                else
                {
                    string message = "Move file operation failed. Error: " + error.ToString();
                    MessageBox.Show(message, "Could not move file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #6
0
        private void DoFileCopy(
            ListViewItem item
            )
        {
            FileBrowserNode node        = base.TreeNode as FileBrowserNode;
            string          destination = "";

            // Determine destingation to copy to
            SelectDestinationDialog destinationDialog = new SelectDestinationDialog(node.Path, SelectDestinationDialog.SELECT_DESTINATION_OPERATION.COPY_FILE, plugin);

            if (destinationDialog.ShowDialog() == DialogResult.OK)
            {
                destination = destinationDialog.GetPath() + PathSeparator + item.Text;

                string   path  = node.Path + PathSeparator + item.Text;
                WinError error = FileClient.FileClient.CopyFile(path, destination, true);

                if (error == WinError.ERROR_FILE_EXISTS)
                {
                    destination = destinationDialog.GetPath() + PathSeparator + "Copy of " + item.Text;
                    error       = FileClient.FileClient.CopyFile(path, destination, true);
                }

                if (error == WinError.NO_ERROR)
                {
                    Refresh();
                }
                else
                {
                    string message = "Copy file operation failed. Error: " + error.ToString();
                    MessageBox.Show(message, "Could not copy file", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        /// <summary>
        /// Called to query the context menu.
        /// </summary>
        /// <param name="hMenu">The handle to the parent menu.</param>
        /// <param name="indexMenu">The index of the menu.</param>
        /// <param name="idCmdFirst">The first command ID.</param>
        /// <param name="idCmdLast">The last command ID.</param>
        /// <param name="uFlags">The flags.</param>
        /// <returns>An HRESULT indicating success.</returns>
        int IContextMenu.QueryContextMenu(IntPtr hMenu, uint indexMenu, int idCmdFirst, int idCmdLast, CMF uFlags)
        {
            //  Log this key event.
            Log(string.Format("Query Context Menu for items {0}", string.Join(", ", SelectedItemPaths)));

            //  If we've got the defaultonly flag, we're done.
            if (uFlags.HasFlag(CMF.CMF_DEFAULTONLY))
            {
                return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, 0));
            }

            //  Set the first item id.
            var firstItemId = (uint)idCmdFirst;

            //  Use the native context menu wrapper to build the context menu.
            uint lastItemId = 0;

            try
            {
                nativeContextMenuWrapper.ResetNativeContextMenu();
                lastItemId = nativeContextMenuWrapper.BuildNativeContextMenu(hMenu, firstItemId, contextMenuStrip.Value.Items);
            }
            catch (Exception exception)
            {
                //  Log the exception.
                LogError("An exception occured building the context menu.", exception);

                //  Return the failure.
                return(WinError.E_FAIL);
            }

            //  Return success, passing the the last item ID plus one (which will be the next command id).
            //  MSDN documentation is flakey here - to be explicit we need to return the count of the items added plus one.
            return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, (lastItemId - firstItemId) + 1));
        }
        private List <NETRESOURCE> GetChildNetResources(
            ResourceScope dwScope,
            ResourceType dwType,
            ResourceUsage dwUsage,
            NETRESOURCE NetResource
            )
        {
            WinError           error  = WinError.NO_ERROR;
            IntPtr             handle = new IntPtr();
            List <NETRESOURCE> nrList = new List <NETRESOURCE>();

            error = FileClient.FileClient.BeginEnumNetResources(dwScope,
                                                                dwType,
                                                                dwUsage,
                                                                NetResource,
                                                                out handle);

            if (error == WinError.NO_ERROR)
            {
                error = FileClient.FileClient.EnumNetResources(handle, out nrList);

                FileClient.FileClient.EndEnumNetResources(handle);
            }

            return(nrList);
        }
Example #9
0
        /*
         * RemoveDirectory - Removes an empty directory file from a local or remote file system.
         */
        public static WinError RemoveDirectory(
            string lpDirectoryName
            )
        {
            bool     deleted = false;
            WinError error   = 0;

            if (useWindowsDlls)
            {
                deleted = InteropWindows.RemoveDirectory(lpDirectoryName);

                if (!deleted)
                {
                    error = (WinError)Marshal.GetLastWin32Error();
                }
            }
            else
            {
                deleted = InteropLikewise.RemoveDirectory(lpDirectoryName);

                if (!deleted)
                {
                    error = (WinError)InteropLikewise.GetLastError();
                }
            }

            return(error);
        }
Example #10
0
        /*
         * CreateDirectory - Creates a new directory file on a local or remote file system.
         */
        public static WinError CreateDirectory(
            string lpDirectoryName
            )
        {
            bool     created            = false;
            WinError error              = 0;
            IntPtr   securityDescriptor = new IntPtr(0);

            if (useWindowsDlls)
            {
                created = InteropWindows.CreateDirectory(lpDirectoryName, securityDescriptor);

                if (!created)
                {
                    error = (WinError)Marshal.GetLastWin32Error();
                }
            }
            else
            {
                created = InteropLikewise.CreateDirectory(lpDirectoryName);

                if (!created)
                {
                    error = (WinError)InteropLikewise.GetLastError();
                }
            }

            return(error);
        }
Example #11
0
        private void DoDirectoryCopy(
            ListViewItem item
            )
        {
            FileBrowserNode node = base.TreeNode as FileBrowserNode;

            // Determine destingation to copy to
            SelectDestinationDialog destinationDialog = new SelectDestinationDialog(node.Path, SelectDestinationDialog.SELECT_DESTINATION_OPERATION.COPY_DIRECTORY, plugin);

            if (destinationDialog.ShowDialog() == DialogResult.OK)
            {
                WinError error = FileClient.FileClient.CopyDirectory(node.Path, destinationDialog.GetPath(), item.Text, item.Text, true);

                if (error == WinError.ERROR_FILE_EXISTS ||
                    error == WinError.ERROR_ALREADY_EXISTS)
                {
                    error = FileClient.FileClient.CopyDirectory(node.Path, destinationDialog.GetPath(), item.Text, "Copy of " + item.Text, true);
                }

                if (error == WinError.NO_ERROR)
                {
                    Refresh();
                }
                else
                {
                    string message = "Copy directory operation failed. Error: " + error.ToString();
                    MessageBox.Show(message, "Could not copy directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #12
0
        /*
         * GetFileSecurity - Get the file security descriptor object
         */
        public static WinError GetFileSecurity(
            string lpFilename
            )
        {
            WinError Winerror            = WinError.ERROR_SUCCESS;
            IntPtr   pSecurityDescriptor = new IntPtr(0);
            uint     lpnLengthNeeded     = 0;

            if (useWindowsDlls)
            {
                Winerror = InteropWindows.GetFileSecurity(lpFilename,
                                                          SecurityDescriptorApi.SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION |
                                                          SecurityDescriptorApi.SECURITY_INFORMATION.GROUP_SECURITY_INFORMATION |
                                                          SecurityDescriptorApi.SECURITY_INFORMATION.DACL_SECURITY_INFORMATION,
                                                          ref pSecurityDescriptor,
                                                          0,
                                                          out lpnLengthNeeded);

                if ((int)Winerror == 122) //Insufficient buffer
                {
                    Winerror = InteropWindows.GetFileSecurity(lpFilename,
                                                              SecurityDescriptorApi.SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION |
                                                              SecurityDescriptorApi.SECURITY_INFORMATION.GROUP_SECURITY_INFORMATION |
                                                              SecurityDescriptorApi.SECURITY_INFORMATION.DACL_SECURITY_INFORMATION,
                                                              ref pSecurityDescriptor,
                                                              lpnLengthNeeded,
                                                              out lpnLengthNeeded);
                    SecurityDescriptor.objectType = System.IO.File.Exists(lpFilename) ?
                                                    SecurityDescriptorApi.SE_OBJECT_TYPE.SE_FILE_OBJECT :
                                                    SecurityDescriptorApi.SE_OBJECT_TYPE.SE_DIR_OBJECT;

                    if (Winerror != 0)
                    {
                        goto error;
                    }
                }
            }
            else
            {
                Winerror = WinError.ERROR_INVALID_PARAMETER;
            }

            if (Winerror == WinError.ERROR_EXTENDED_ERROR)
            {
                Winerror = (WinError)Marshal.GetLastWin32Error();
            }

cleanup:

            if (pSecurityDescriptor != IntPtr.Zero)
            {
                SecurityDescriptorApi.CloseHandle(pSecurityDescriptor);
            }

            return(Winerror);

error:

            goto cleanup;
        }
Example #13
0
        public static WinError SetFileSecurity(
            string lpFilename,
            IntPtr pSecurityDescriptor)
        {
            WinError Winerror = WinError.ERROR_SUCCESS;

            if (useWindowsDlls)
            {
                Winerror = InteropWindows.SetFileSecurity(
                    lpFilename,
                    SecurityDescriptorApi.SECURITY_INFORMATION.DACL_SECURITY_INFORMATION |
                    SecurityDescriptorApi.SECURITY_INFORMATION.GROUP_SECURITY_INFORMATION |
                    SecurityDescriptorApi.SECURITY_INFORMATION.OWNER_SECURITY_INFORMATION,
                    pSecurityDescriptor);

                if (Winerror != 0)
                {
                    goto cleanup;
                }
            }

error:

            return(Winerror);

cleanup:

            goto error;
        }
Example #14
0
        /*
         * CopyFile - Copy a file to/from a local or remote file system.
         */
        public static WinError CopyFile(
            string lpExistingFileName,
            string lpNewFileName,
            bool bFailIfExists
            )
        {
            bool     copied = false;
            WinError error  = 0;

            if (useWindowsDlls)
            {
                copied = InteropWindows.CopyFile(lpExistingFileName, lpNewFileName, bFailIfExists);

                if (!copied)
                {
                    error = (WinError)Marshal.GetLastWin32Error();
                }
            }
            else
            {
                copied = InteropLikewise.CopyFile(lpExistingFileName, lpNewFileName, bFailIfExists);

                if (!copied)
                {
                    error = (WinError)InteropLikewise.GetLastError();
                }
            }

            return(error);
        }
Example #15
0
        /*
         * BeginEnumNetResources - Begin search for connections. Options to find connected, connectable, remembered locations.
         */
        public static WinError BeginEnumNetResources(
            ResourceScope dwScope,
            ResourceType dwType,
            ResourceUsage dwUsage,
            NETRESOURCE pNetResource,
            out IntPtr enumHandle
            )
        {
            WinError error = WinError.ERROR_SUCCESS;

            if (useWindowsDlls)
            {
                error = InteropWindows.WNetOpenEnum(dwScope, dwType, dwUsage, pNetResource, out enumHandle);
            }
            else
            {
                error      = WinError.ERROR_INVALID_PARAMETER;
                enumHandle = new IntPtr(0);
            }

            if (error == WinError.ERROR_EXTENDED_ERROR)
            {
                error = (WinError)Marshal.GetLastWin32Error();
            }

            return(error);
        }
Example #16
0
        /*
         * MoveFile - Move a file to/from a local or remote file system.
         */
        public static WinError MoveFile(
            string lpExistingFileName,
            string lpNewFileName
            )
        {
            bool     moved = false;
            WinError error = 0;

            if (useWindowsDlls)
            {
                moved = InteropWindows.MoveFile(lpExistingFileName, lpNewFileName);

                if (!moved)
                {
                    error = (WinError)Marshal.GetLastWin32Error();
                }
            }
            else
            {
                moved = InteropLikewise.MoveFile(lpExistingFileName, lpNewFileName);

                if (!moved)
                {
                    error = (WinError)InteropLikewise.GetLastError();
                }
            }

            return(error);
        }
Example #17
0
        /*
         * CreateConnection - Adds a connection to a network SMB file share. Optional credentials
         * can be passed, otherwise default will be used for connection.
         */
        public static WinError CreateConnection(
            string networkName,
            string username,
            string password
            )
        {
            WinError    error       = WinError.ERROR_SUCCESS;
            NETRESOURCE netResource = new NETRESOURCE();

            netResource.dwScope       = ResourceScope.RESOURCE_GLOBALNET;
            netResource.dwType        = ResourceType.RESOURCETYPE_DISK;
            netResource.dwDisplayType = ResourceDisplayType.RESOURCEDISPLAYTYPE_SHARE;
            netResource.dwUsage       = ResourceUsage.RESOURCEUSAGE_ALL;
            netResource.pRemoteName   = networkName;

            if (useWindowsDlls)
            {
                error = InteropWindows.WNetAddConnection2(netResource, password, username, 0);
            }
            else
            {
                error = InteropLikewise.WNetAddConnection2(netResource, password, username, 0);
            }

            return(error);
        }
Example #18
0
        /*
         * DeleteFile - Deletes a file from a local or remote file system.
         */
        public static WinError DeleteFile(
            string lpFileName
            )
        {
            bool     deleted = false;
            WinError error   = 0;

            if (useWindowsDlls)
            {
                deleted = InteropWindows.DeleteFile(lpFileName);

                if (!deleted)
                {
                    error = (WinError)Marshal.GetLastWin32Error();
                }
            }
            else
            {
                deleted = InteropLikewise.DeleteFile(lpFileName);

                if (!deleted)
                {
                    error = (WinError)InteropLikewise.GetLastError();
                }
            }

            return(error);
        }
 void ShowWinError(string str)
 {
     try
     {
         ShowAlarm(str);
         WinError.GetWinInst().ShowError(str);
     }
     catch (Exception ex)
     {
     }
 }
Example #20
0
        /// <summary>
        /// Add commands to a shortcut menu.
        /// </summary>
        /// <param name="hMenu">A handle to the shortcut menu.</param>
        /// <param name="iMenu">
        /// The zero-based position at which to insert the first new menu item.
        /// </param>
        /// <param name="idCmdFirst">
        /// The minimum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="idCmdLast">
        /// The maximum value that the handler can specify for a menu item ID.
        /// </param>
        /// <param name="uFlags">
        /// Optional flags that specify how the shortcut menu can be changed.
        /// </param>
        /// <returns>
        /// If successful, returns an HRESULT value that has its severity value set
        /// to SEVERITY_SUCCESS and its code value set to the offset of the largest
        /// command identifier that was assigned, plus one.
        /// </returns>
        public int QueryContextMenu(
            IntPtr hMenu,
            uint iMenu,
            uint idCmdFirst,
            uint idCmdLast,
            uint uFlags)
        {
            // If uFlags include CMF_DEFAULTONLY then we should not do anything.
            if (((uint)CMF.CMF_DEFAULTONLY & uFlags) != 0)
            {
                return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0, 0));
            }

            MENUINFO mnfo = new MENUINFO();

            mnfo.cbSize  = (UInt32)Marshal.SizeOf(mnfo);
            mnfo.fMask   = MIM.MIM_STYLE;
            mnfo.dwStyle = MNS.MNS_CHECKORBMP;
            NativeMethods.SetMenuInfo(hMenu, ref mnfo);

            // Use either InsertMenu or InsertMenuItem to add menu items.
            MENUITEMINFO mii = new MENUITEMINFO();

            mii.cbSize = (uint)Marshal.SizeOf(mii);
            mii.fMask  = MIIM.MIIM_BITMAP | MIIM.MIIM_STRING | MIIM.MIIM_FTYPE |
                         MIIM.MIIM_ID | MIIM.MIIM_STATE;
            mii.wID        = idCmdFirst + IDM_DISPLAY;
            mii.fType      = MFT.MFT_STRING;
            mii.dwTypeData = this.menuText;
            mii.fState     = MFS.MFS_ENABLED;
            mii.hbmpItem   = this.menuBmp;
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu, true, ref mii))
            {
                return(Marshal.GetHRForLastWin32Error());
            }

            // Add a separator.
            MENUITEMINFO sep = new MENUITEMINFO();

            sep.cbSize = (uint)Marshal.SizeOf(sep);
            sep.fMask  = MIIM.MIIM_TYPE;
            sep.fType  = MFT.MFT_SEPARATOR;
            if (!NativeMethods.InsertMenuItem(hMenu, iMenu + 1, true, ref sep))
            {
                return(Marshal.GetHRForLastWin32Error());
            }

            // Return an HRESULT value with the severity set to SEVERITY_SUCCESS.
            // Set the code value to the offset of the largest command identifier
            // that was assigned, plus one (1).
            return(WinError.MAKE_HRESULT(WinError.SEVERITY_SUCCESS, 0,
                                         IDM_DISPLAY + 1));
        }
Example #21
0
        /// <summary>
        /// Called to query the context menu.
        /// </summary>
        /// <param name="hMenu">The handle to the parent menu.</param>
        /// <param name="indexMenu">The index of the menu.</param>
        /// <param name="idCmdFirst">The first command ID.</param>
        /// <param name="idCmdLast">The last command ID.</param>
        /// <param name="uFlags">The flags.</param>
        /// <returns>An HRESULT indicating success.</returns>
        HResult IContextMenu.QueryContextMenu(IntPtr hMenu, uint indexMenu, int idCmdFirst, int idCmdLast, CMF uFlags)
        {
            //  Log this key event.
            Log(string.Format("Query Context Menu for items: {0}{1}", Environment.NewLine, string.Join(Environment.NewLine, SelectedItemPaths)));

            //  If we've got the defaultonly flag, we're done.
            if (uFlags.HasFlag(CMF.CMF_DEFAULTONLY))
            {
                return(WinError.MAKE_HResult(WinError.SEVERITY_SUCCESS, 0, 0));
            }

            //  Before we build the context menu, determine whether we need to show it.
            try
            {
                //  If we can't show the menu, return false.
                if (!CanShowMenu())
                {
                    return(HResult.S_FALSE);
                }
            }
            catch (Exception exception)
            {
                //  We can't show the menu.
                LogError("An exception ocurred determining whether the context menu should be shown.", exception);

                //  Return the failure.
                return(HResult.E_FAIL);
            }

            //  Set the first item id.
            var firstItemId = (uint)idCmdFirst;

            //  Use the native context menu wrapper to build the context menu.
            uint lastItemId = 0;

            try
            {
                nativeContextMenuWrapper.ResetNativeContextMenu();
                lastItemId = nativeContextMenuWrapper.BuildNativeContextMenu(hMenu, firstItemId, contextMenuStrip.Value.Items);
            }
            catch (Exception exception)
            {
                //  DebugLog the exception.
                LogError("An exception occured building the context menu.", exception);

                //  Return the failure.
                return(HResult.E_FAIL);
            }

            //  Return success, passing the the last item ID plus one (which will be the next command id).
            //  MSDN documentation is flakey here - to be explicit we need to return the count of the items added plus one.
            return(WinError.MAKE_HResult(WinError.SEVERITY_SUCCESS, 0, (lastItemId - firstItemId) + 1));
        }
Example #22
0
        /*
         * EnumNetResources - Continue search for connections.
         */
        public static WinError EnumNetResources(
            IntPtr enumHandle,
            out List <NETRESOURCE> NetResources
            )
        {
            WinError           error  = WinError.ERROR_SUCCESS;
            List <NETRESOURCE> nrList = new List <NETRESOURCE>();
            int         cEntries      = -1;
            int         bufferSize    = 16384;
            IntPtr      ptrBuffer     = Marshal.AllocHGlobal(bufferSize);
            NETRESOURCE nr;

            for (; ;)
            {
                cEntries   = -1;
                bufferSize = 16384;

                if (useWindowsDlls)
                {
                    error = InteropWindows.WNetEnumResource(enumHandle, ref cEntries, ptrBuffer, ref bufferSize);
                }
                else
                {
                    error = WinError.ERROR_INVALID_PARAMETER;
                }

                if ((error != WinError.NO_ERROR) || (cEntries < 1))
                {
                    if (error == WinError.ERROR_NO_MORE_ITEMS)
                    {
                        error = WinError.NO_ERROR;
                    }
                    break;
                }

                Int32 ptr = ptrBuffer.ToInt32();
                for (int i = 0; i < cEntries; i++)
                {
                    nr = (NETRESOURCE)Marshal.PtrToStructure(new IntPtr(ptr), typeof(NETRESOURCE));

                    nrList.Add(nr);
                    ptr += Marshal.SizeOf(nr);
                }
            }

            Marshal.FreeHGlobal(ptrBuffer);

            NetResources = nrList;
            return(error);
        }
Example #23
0
        private void DoDirectoryMove(
            ListViewItem item
            )
        {
            FileBrowserNode node = base.TreeNode as FileBrowserNode;

            // Determine destingation to move to
            SelectDestinationDialog destinationDialog = new SelectDestinationDialog(node.Path, SelectDestinationDialog.SELECT_DESTINATION_OPERATION.MOVE_DIRECTORY, plugin);

            if (destinationDialog.ShowDialog() == DialogResult.OK)
            {
                string   path  = node.Path + PathSeparator + item.Text;
                WinError error = FileClient.FileClient.MoveDirectory(node.Path,
                                                                     destinationDialog.GetPath(),
                                                                     item.Text,
                                                                     item.Text,
                                                                     true);

                if (error == WinError.ERROR_FILE_EXISTS ||
                    error == WinError.ERROR_ALREADY_EXISTS)
                {
                    error = FileClient.FileClient.MoveDirectory(node.Path,
                                                                destinationDialog.GetPath(),
                                                                item.Text,
                                                                "Copy of " + item.Text,
                                                                true);
                }

                if (error == WinError.NO_ERROR)
                {
                    TreeNode[] removedItem = node.Nodes.Find(item.Text, false);
                    if (removedItem.Length > 0)
                    {
                        removedItem[0].Remove();
                    }

                    lvFilePage.BeginUpdate();
                    lvFilePage.Items.Remove(item);
                    lvFilePage.EndUpdate();
                    Refresh();
                }
                else
                {
                    string message = "Move directory operation failed. Error: " + error.ToString();
                    MessageBox.Show(message, "Could not move directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        void InitMotionCtler()
        {
            if (!ParMotionCtrler.P_I.IsEnable)
            {
                return;
            }
            //包括初始化IO模块
            LogicMotionCtler.L_I.InitModule();
            DmcResult result = LogicMotionCtler.L_I.Dmc_card_init();

            //板卡初始化之后初始化实deng例
            InitLight();
            InitAirCylider();

            if (result.resultType == ResultType.OK)
            {
                ParMotionCtrler.P_I.IsInitialized = true;

                if (WinMsgBox.ShowMsgBox("开始按照既定的顺序\n执行回零?"))
                {
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        this.gdRoot.Children.Add(uiShield);
                    }));

                    ShowState("打开气缸,等待气缸到达限位");
                    g_AirCyliderUpDown.OnAirCylinder(4000);
                    ShowState("气缸已打开,开始回零");


                    LogicMotionCtler.L_I.Home();
                    this.Dispatcher.Invoke(new Action(() =>
                    {
                        this.gdRoot.Children.Remove(uiShield);
                    }));

                    ShowState("回零动作结束,已回到初始位!");
                }
                else
                {
                    ShowState("已拒绝回零!");
                }
            }
            else
            {
                WinError.GetWinInst().ShowError("控制卡初始化失败!\n" + result.resultInfo);
            };
        }
Example #25
0
        /*
         * DeleteConnection - Cancel a connection to a network SMB file share.
         */
        public static WinError DeleteConnection(
            string networkName
            )
        {
            WinError error = WinError.ERROR_SUCCESS;

            if (useWindowsDlls)
            {
                error = InteropWindows.WNetCancelConnection2(networkName, 0, true);
            }
            else
            {
                error = InteropLikewise.WNetCancelConnection2(networkName, 0, true);
            }

            return(error);
        }
Example #26
0
        private void cm_OnDisconnectShare(object sender, EventArgs e)
        {
            string name = null;

            if (_currentNode != null &&
                _selectedNode != null &&
                _currentNode == _selectedNode)
            {
                name = _currentNode.Name;

                WinError error = FileClient.FileClient.DeleteConnection(name);

                // Update the RemoteShares list (for systems missing WNetEnumResource API
                RemoteShares.Remove(name);

                this._pluginNode.Nodes.Remove(this._pluginNode.Nodes.Find(name, true)[0]);
                RefreshNetworkTreeNode();
            }
        }
Example #27
0
        private void cm_OnMove(object sender, EventArgs e)
        {
            if (_currentNode != null &&
                _selectedNode != null &&
                _currentNode == _selectedNode)
            {
                FileBrowserNode node   = _currentNode as FileBrowserNode;
                FileBrowserNode parent = _currentNode.Parent as FileBrowserNode;

                // Determine destingation to copy to
                SelectDestinationDialog destinationDialog = new SelectDestinationDialog(node.Path, SelectDestinationDialog.SELECT_DESTINATION_OPERATION.MOVE_DIRECTORY, this);

                if (destinationDialog.ShowDialog() == DialogResult.OK)
                {
                    WinError error = FileClient.FileClient.MoveDirectory(parent.Path,
                                                                         destinationDialog.GetPath(),
                                                                         node.Name,
                                                                         node.Name,
                                                                         true);

                    if (error == WinError.ERROR_FILE_EXISTS ||
                        error == WinError.ERROR_ALREADY_EXISTS)
                    {
                        error = FileClient.FileClient.MoveDirectory(parent.Path,
                                                                    destinationDialog.GetPath(),
                                                                    node.Name,
                                                                    "Copy of " + node.Name,
                                                                    true);
                    }

                    if (error != WinError.NO_ERROR)
                    {
                        string message = "Move directory operation failed. Error: " + error.ToString();
                        MessageBox.Show(message, "Could not move directory", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        _currentNode.Remove();
                    }
                }
            }
        }
Example #28
0
        private void txtErrCode_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (e.KeyChar == (char)13)
                {
                    string strErrCode = txtErrCode.Text.Trim().ToLower();
                    if (strErrCode == "")
                    {
                        return;
                    }

                    listView1.Items.Clear();

                    StringBuilder sb = new StringBuilder(1024);

                    for (int i = 0; i < werr.dicErrInfo.Count; i++)
                    {
                        uint uDicCode = (uint)werr.dicErrInfo.GetKey(i);

                        if (strErrCode == uDicCode.ToString().ToLower() || strErrCode == uDicCode.ToString("x"))
                        {
                            WinError.FormatMessage(WinError.FORMAT_MESSAGE_FROM_SYSTEM, IntPtr.Zero, uDicCode, 0, sb, sb.Capacity, IntPtr.Zero);

                            string strValue = werr.dicErrInfo.GetByIndex(i) as string;

                            ListViewItem item = new ListViewItem(strValue);

                            item.SubItems.Add(uDicCode.ToString());
                            item.SubItems.Add(uDicCode.ToString());
                            item.SubItems.Add("0x" + uDicCode.ToString("x8"));
                            item.SubItems.Add(sb.ToString());

                            listView1.Items.Add(item);
                        }
                    }
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
Example #29
0
        /*
         * EndEnumNetResources - End search for connections.
         */
        public static WinError EndEnumNetResources(
            IntPtr enumHandle
            )
        {
            WinError error = WinError.ERROR_SUCCESS;

            if (useWindowsDlls)
            {
                error = InteropWindows.WNetCloseEnum(enumHandle);
            }
            else
            {
                error = WinError.ERROR_INVALID_PARAMETER;
            }

            if (error == WinError.ERROR_EXTENDED_ERROR)
            {
                error = (WinError)Marshal.GetLastWin32Error();
            }

            return(error);
        }
Example #30
0
        /// <summary>
        /// 判断算法处理结果的正确性
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        protected bool DealTypeResult(BaseResult result)
        {
            try
            {
                //如果为错误
                if (result.LevelError_e == LevelError_enum.Error)
                {
                    string level      = result.LevelError_e.ToString();
                    string type       = result.TypeErrorProcess_e.ToString();
                    string annotation = result.Annotation;
                    string info       = string.Format("{0},类型:{1};{2}", level, type, annotation);

                    switch (result.TypeErrorProcess_e)
                    {
                    case TypeErrorProcess_enum.OutMemory:
                        WinError.GetWinInst().ShowError(info + ",请重新启动软件!");
                        break;

                    case TypeErrorProcess_enum.CameraImageError:
                        WinError.GetWinInst().ShowError(info + ",请重新启动软件,检测相机连接!");
                        break;

                    default:
                        g_UCAlarm.AddInfo(info);
                        break;
                    }

                    return(false);
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.L_I.WriteError(NameClass, ex);
                return(false);
            }
        }