/// <summary> /// Use try with this ctor. /// </summary> /// <param name="sort_criteria"></param> /// <param name="reverse"></param> /// <param name="net_path"></param> public WnetResourceList(int sort_criteria, bool reverse, string net_path) : base(sort_criteria, reverse) { resource_root = WinApiWNETwrapper.GetResourceInfo(net_path); internal_comparer = new InternalComparer(sort_criteria, reverse); internal_list = new SortedList <NETRESOURCE, object>(internal_comparer); }
public void FillInfo(NETRESOURCE resource) { try { resource_intern = WinApiWNETwrapper.GetResourceInfo(resource.lpRemoteName); Text = resource_intern.lpRemoteName; textBoxRemoteName.Text = resource_intern.lpRemoteName; textBoxDisplayType.Text = resource_intern.dwDisplayType.ToString(); textBoxResourceType.Text = resource_intern.dwType.ToString(); textBoxResourceComment.Text = resource_intern.lpComment; textBoxProviderName.Text = resource_intern.lpProvider; } catch (Exception ex) { errorProvider1.SetIconAlignment(textBoxRemoteName, ErrorIconAlignment.MiddleLeft); errorProvider1.SetError(textBoxRemoteName, ex.Message); //Messages.ShowException(ex); } var netinfo = new NETINFOSTRUCT(); try { netinfo = WinApiWNETwrapper.GetNetworkInfo(resource_intern.lpProvider); textBoxNetworkProviderType.Text = netinfo.wNetType.ToString(); textBoxNetworkProviderVersion.Text = string.Format("0x{0:X}", netinfo.dwProviderVersion); } catch (Exception ex) { errorProvider1.SetIconAlignment(textBoxNetworkProviderType, ErrorIconAlignment.MiddleLeft); errorProvider1.SetError(textBoxNetworkProviderType, ex.Message); } if ((resource_intern.dwDisplayType == ResourceDisplayType.SERVER) && (netinfo.wNetType == NetworkType.LANMAN)) { fill_netserver_page(); tabControl1.TabPages.Remove(tabPageShareInfo); } else if ((resource_intern.dwDisplayType == ResourceDisplayType.SHARE) || (resource_intern.dwDisplayType == ResourceDisplayType.SHAREADMIN)) { fill_share_page(); tabControl1.TabPages.Remove(tabPageFilesInfo); tabControl1.TabPages.Remove(tabPageServerInfo); tabControl1.TabPages.Remove(tabPageSessionInfo); tabControl1.TabPages.Remove(tabPageTransportInfo); } else { tabControl1.TabPages.Remove(tabPageShareInfo); tabControl1.TabPages.Remove(tabPageFilesInfo); tabControl1.TabPages.Remove(tabPageServerInfo); tabControl1.TabPages.Remove(tabPageSessionInfo); tabControl1.TabPages.Remove(tabPageTransportInfo); } }
private void jump_to(mFilePanel target_panel) { var dial = new JumpToDialog(); dial.Text = Options.GetLiteral(Options.LANG_WHERE_TO_JUMP); if (dial.ShowDialog() != DialogResult.OK) { return; } var path = dial.textBoxPath.Text; FileCollectionBase new_source = null; try { //parse path if (path.StartsWith(@"\\")) { //assume smb path var target_res = WinApiWNETwrapper.GetResourceInfo(path); if (target_res.dwDisplayType == netCommander.WNet.ResourceDisplayType.SHARE) { //it is network share - show directory list new_source = new DirectoryList(0, false, path); } else if ((target_res.dwUsage & ResourceUsage.CONTAINER) != ResourceUsage.CONTAINER) { //target_res is not container - try show parent target_res = WinApiWNETwrapper.GetParentResource(target_res); new_source = new WnetResourceList(0, false, target_res); } else { //show target_resource new_source = new WnetResourceList(0, false, target_res); } }//end of stratsWith("\\") brunch else { new_source = new DirectoryList(0, false, path); } //now refill source new_source.MainWindow = this; new_source.Refill(); target_panel.Source = new_source; target_panel.Refresh(); } catch (Exception ex) { Messages.ShowException(ex, string.Format(Options.GetLiteral(Options.LANG_CANNOT_SHOW_0), path)); } }
public override void GetChildCollection(int index, ref FileCollectionBase new_collection, ref bool use_new, ref string preferred_focused_text) { if (index == 0) { //return container from wnet try { NETRESOURCE container = WinApiWNETwrapper.GetParentResource(server_ref); WnetResourceList wnet_list = new WnetResourceList(SortCriteria, SortReverse, container); preferred_focused_text = server_ref.lpRemoteName; wnet_list.Refill(); use_new = true; new_collection = wnet_list; } catch (Exception ex) { Messages.ShowException(ex); } return; } //else return DirectoryList try { string target_dir = string.Format ("{0}\\{1}", server_ref.lpRemoteName, internal_list.Keys[index - 1].shi1_netname); DirectoryList dir_list = new DirectoryList(SortCriteria, SortReverse, target_dir); dir_list.Refill(); use_new = true; new_collection = dir_list; } catch (Exception ex) { Messages.ShowException(ex); } return; }
public override void GetChildCollection (int index, ref FileCollectionBase new_collection, ref bool use_new, ref string preferred_focused_text) { if (!GetItemIsContainer(index)) { use_new = false; return; } NETRESOURCE target_container = new NETRESOURCE(); if (index == 0) { //go up to container of resourse_root //cache valid? if (parent_cache != null) { //fill from cache internal_list.Clear(); foreach (NETRESOURCE res in parent_cache.ResourceList) { internal_list.Add(res, null); } preferred_focused_text = resource_root.lpRemoteName; resource_root = parent_cache.ResourceRoot; parent_cache = parent_cache.ParentCache; OnAfterRefill(); use_new = false; return; } //workaround. //Wnet throws exception while getting parent of resource like 'Microsoft Windows Network' if ((resource_root.lpRemoteName == null) || (resource_root.dwDisplayType == ResourceDisplayType.NETWORK)) { target_container = WinApiWNETwrapper.RootNetresource; } else { target_container = WinApiWNETwrapper.GetParentResource(resource_root); } preferred_focused_text = resource_root.lpRemoteName; //set new resource_root resource_root = target_container; //and fill Refill(); //and return use_new = false; return; }//end of UP brunch //else go to down target_container = internal_list.Keys[index - 1]; //case disk share - switch to DirectoryList if (target_container.dwType == ResourceType.DISK) { //switch to DirectoryList DirectoryList new_source = new DirectoryList (SortCriteria, SortReverse, target_container.lpRemoteName); new_source.MainWindow = MainWindow; try { new_source.Refill(); use_new = true; new_collection = new_source; } catch (Win32Exception win5_ex) { if (win5_ex.NativeErrorCode == 5) //access denied { //try to establish connection with creds if (establish_connection(target_container)) { try { //and retry new_source.Refill(); use_new = true; new_collection = new_source; } catch (Exception ex) { Messages.ShowException(ex); } } } else { Messages.ShowException(win5_ex); } } catch (Exception ex) { Messages.ShowException(ex); } return; } //prepare parent cache InternalCache new_cache = new InternalCache(target_container); new_cache.ParentCache = parent_cache; new_cache.ResourceList.AddRange(internal_list.Keys); new_cache.ResourceRoot = resource_root; try { resource_root = target_container; use_new = false; Refill(); parent_cache = new_cache; } catch (Exception ex) { Messages.ShowException(ex); } return; }
protected override void internal_refill() { List <NETRESOURCE> new_list = new List <NETRESOURCE>(); //create enumerator WnetResourceEnumerator res_enum = null; try { OnLongOperaion("Wait while scanning network...", true); res_enum = new WnetResourceEnumerator (resource_root, ResourceScope.GLOBALNET, ResourceType.ANY, ResourceUsage.NONE); OnLongOperaion("Scanning completed.", false); } catch (Win32Exception win_ex) { if (win_ex.NativeErrorCode == 5) //access denied { //try to establish connection with net credetials if (establish_connection(resource_root)) { //retry res_enum = new WnetResourceEnumerator (resource_root, ResourceScope.GLOBALNET, ResourceType.ANY, ResourceUsage.NONE); } else { throw win_ex; } } else { throw win_ex; } } finally { OnLongOperaion("Completed", false); } //fill foreach (NETRESOURCE one_res in res_enum) { new_list.Add(one_res); } //case if resourse_root is SMB server - add hidden shares if ((resource_root.dwDisplayType == ResourceDisplayType.SERVER) && (WinApiWNETwrapper.GetNetworkInfo(resource_root.lpProvider).wNetType == NetworkType.LANMAN)) { //retrieve fake hidden NETRESOURCEs OnLongOperaion("Wait while scanning hidden resources...", true); NETRESOURCE[] hidden_resources = get_hidden_resources(resource_root); OnLongOperaion("Scanning completed.", false); new_list.AddRange(hidden_resources); } //fill work list internal_list.Clear(); foreach (NETRESOURCE one_res in new_list) { internal_list.Add(one_res, null); } }