📄 explorerdlg.cs
字号:
protected void OnClickMenuMRU3 (object sender, System.EventArgs e)
{
string l_strFTPServer = m_arrMRUConn[2].FTPServer ;
string l_strFTPUser = m_arrMRUConn[2].FTPUser;
ConnectToFTPServer(l_strFTPServer,l_strFTPUser);
}
protected void OnClickMenuMRU2 (object sender, System.EventArgs e)
{
string l_strFTPServer = m_arrMRUConn[1].FTPServer ;
string l_strFTPUser = m_arrMRUConn[1].FTPUser;
ConnectToFTPServer(l_strFTPServer,l_strFTPUser);
}
protected void OnClickMenuMRU1 (object sender, System.EventArgs e)
{
string l_strFTPServer = m_arrMRUConn[0].FTPServer ;
string l_strFTPUser = m_arrMRUConn[0].FTPUser;
ConnectToFTPServer(l_strFTPServer,l_strFTPUser);
}
/* Called from MRU List */
private void ConnectToFTPServer(string l_strFTPServer,string l_strFTPUser){
ConnectDlg dlg = new ConnectDlg(l_strFTPServer,l_strFTPUser,"");
dlg.ShowDialog();
if ( dlg.m_iDataFlag == 1 ) {
/* If OK is pressed then connect to FTP server */
this.Cursor = Cursors.WaitCursor;
m_strFTPAddress = dlg.m_strFTPServer;
m_strFTPUser = dlg.m_strFTPUserID;
m_strFTPPassword = dlg.m_strFTPPassword;
m_labelTreeView.Text = "No Folders to display";
m_labelTreeView.Refresh();
statusBarPanel1.Text = "Connecting to " + m_strFTPAddress + ". Please wait...";
m_statusBar.Refresh();
int l_iRetval = m_FTPClient.Connect(m_strFTPAddress,m_strFTPUser,m_strFTPPassword);
if ( l_iRetval == 0 ){
string l_strError = m_FTPClient.GetLastError();
this.Cursor = Cursors.Arrow;
MessageBox.Show(l_strError,"FTP Explorer - Error",MessageBox.IconStop);
m_bConnectedFlag = false;
ToggleMenuItems(0);
m_labelTreeView.Text = "Not connected";
m_labelListView.Text = "";
statusBarPanel1.Text = "";
statusBarPanel2.Text = "";
return ;
}
m_bConnectedFlag = true;
ToggleMenuItems(1);
statusBarPanel1.Text = "Connected to " + m_strFTPAddress;
m_statusBar.Refresh();
RefreshFolderView("ROOT","",m_tnRootNode);
string l_strFile = m_FTPClient.m_strList;
m_FTPClient.m_strList = "";
/* Disable all MRU Menu Items */
EnableMRUList(false);
this.Cursor = Cursors.Arrow;
}
}
protected void OnClickConfigure (object sender, System.EventArgs e)
{
int l_iSend = 0 ,l_iRecv = 0;
m_FTPClient.GetTimeOuts(out l_iSend,out l_iRecv);
char l_chDataTransfer = m_FTPClient.DataTransferMode;
ConfigureDlg dlg = new ConfigureDlg(l_chDataTransfer,l_iSend,l_iRecv,m_strLocalDirectory);
if ( dlg.ShowDialog() == DialogResult.OK ) {
l_chDataTransfer = dlg.m_chTransferMode;
int l_iSendTimeOut = dlg.m_iSendTimeout;
int l_iRecvTimeOut = dlg.m_iRecvTimeout;
m_FTPClient.SetTimeOuts(l_iSendTimeOut,l_iRecvTimeOut);
m_FTPClient.DataTransferMode = l_chDataTransfer;
/* TO BE REMOVED FROM PRODUCT */
if ( l_chDataTransfer == 'B' ) {
m_FTPClient.DataTransferMode = 'A';
MessageBox.Show("Binary Mode data transfer is not supported in Beta 1 Release","FTP Explorer",MessageBox.IconInformation);
}
m_strLocalDirectory = dlg.m_strClientPath;
statusBarPanel3.Text = m_strLocalDirectory;
}
}
protected void OnAfterSelectFolderView (object sender, System.WinForms.TreeViewEventArgs e)
{
this.Cursor = Cursors.WaitCursor;
//e.node.Nodes;
TreeNode l_tempNode = e.node;
if ( l_tempNode == m_tnRootNode ) {
/* If root node is clicked do not do anything */
this.Cursor = Cursors.Arrow;
return ;
}
/* Clear all child nodes first */
e.node.Nodes.Clear();
/* Populate Folder view */
string l_strCurDir = l_tempNode.Text;
string l_strFullPath = l_tempNode.FullPath;
l_strFullPath = l_strFullPath.Replace('\\','/');
RefreshFolderView(l_strFullPath,l_strCurDir,l_tempNode);
this.Cursor = Cursors.Arrow;
return;
}
protected void OnClickToolBar (object sender, System.WinForms.ToolBarButtonClickEventArgs e)
{
int l_iImageIndex = e.button.ImageIndex;
switch ( l_iImageIndex ) {
case 0 :
OnClickConnect(sender,e);
break;
case 1 :
OnClickDisconnect(sender,e);
break;
case 2 :
OnClickConfigure(sender,e);
break;
case 3 :
OnClickUploadFile(sender,e);
break;
case 4 :
OnClickDownloadFile(sender,e);
break;
case 5 :
OnClickRefresh(sender,e);
break;
case 6 :
OnClickSystemInfo(sender,e);
break;
case 7 :
OnClickAbout(sender,e);
break;
case 8 :
OnClickExit(sender,e);
break;
default:
break;
}
}
protected void OnClickAbout (object sender, System.EventArgs e)
{
AboutDlg dlg = new AboutDlg();
dlg.ShowDialog(this);
return;
}
protected void OnClickSystemInfo (object sender, System.EventArgs e)
{
string l_strServerInfo = "";
if ( m_bConnectedFlag == false ) {
l_strServerInfo = "Not connected to any FTP Service";
}
else {
int l_iOS = m_FTPClient.GetServerOS();
if ( l_iOS == 0 ) {
l_strServerInfo = "Unknown OS";
}
else if ( l_iOS == 1) {
l_strServerInfo = "Connected to FTP Service on \n";
l_strServerInfo += m_FTPClient.m_strServerType;
}
else if ( l_iOS == 2 ) {
l_strServerInfo = "Connected to FTP Service on \n";
l_strServerInfo += m_FTPClient.m_strServerType;
}
else if ( l_iOS == 3 ) {
l_strServerInfo = "Unknown OS";
}
}
SystemInfoDlg dlg = new SystemInfoDlg(l_strServerInfo);
dlg.ShowDialog(this);
}
protected void OnClickRefresh (object sender, System.EventArgs e)
{
this.Cursor = Cursors.WaitCursor;
/* When refresh is clicked the populate the entire structure */
RefreshFolderView("ROOT","",m_tnRootNode);
this.Cursor = Cursors.Arrow;
}
protected void OnClickDownloadFile (object sender, System.EventArgs e)
{
bool l_bFocused = m_lvFileView.ContainsFocus;
ListView.SelectedListItemCollection l_SelectedItemList = m_lvFileView.SelectedItems;
/* If Listview control is not in focus or nothing is selected */
if ( l_bFocused == false || l_SelectedItemList.Count == 0 ) {
MessageBox.Show("Select one or more files and then click download button","FTP Explorer",MessageBox.IconInformation);
return;
}
/* Get all items */
ListItem[] l_ListItemArray = l_SelectedItemList.All;
ListItem l_ListItemTemp = null;
DownloadFileData[] l_FileList = new DownloadFileData[l_SelectedItemList.Count];
string l_strSize = "";
int l_iSize = 0;
int l_iCount = 0;
foreach(object obj in l_ListItemArray) {
l_ListItemTemp = (ListItem) obj;
/* Get the File size */
/* Item 0 contains the size of the file */
l_strSize = l_ListItemTemp.GetSubItem(0);
try {
if ( l_strSize.Length > 0 ) {
l_iSize = int.Parse(l_strSize);
}
else {
l_iSize = 0;
}
}
catch ( FormatException e1 ) {
l_iSize = 0;
}
l_FileList[l_iCount] = new DownloadFileData();
l_FileList[l_iCount].FileSize = l_iSize;
l_FileList[l_iCount].LocalFileName = m_strLocalDirectory + l_ListItemTemp.Text;
l_FileList[l_iCount].ServerFileName = l_ListItemTemp.Text;
l_iCount++;
}
/* Check whether the same file exist in the current local directory */
string l_strMessage = "";
DownloadFileData l_TempObject;
l_iCount = 0;
foreach(object obj in l_FileList) {
l_TempObject = (DownloadFileData) obj;
/* Check whether the file exist or not */
File l_FileObj = new File(l_TempObject.LocalFileName );
if ( l_FileObj.Exists == true ) {
l_strMessage = "File " + l_TempObject.LocalFileName + " already exists in the local machine. Do you wish to overwrite ?";
if ( MessageBox.Show(l_strMessage,"FTP Explorer",MessageBox.OKCancel | MessageBox.IconQuestion ) == DialogResult.Cancel ) {
return;
}
}
l_iCount++;
}
this.Cursor = Cursors.WaitCursor;
/* Set the corresponding type here */
char l_CurrentMode = 'A';
char l_WantedMode = m_FTPClient.DataTransferMode;
int l_iRetval = 0;
if ( l_CurrentMode != l_WantedMode ) {
statusBarPanel2.Text = "Setting to Binary Transfer type...";
m_statusBar.Refresh();
l_iRetval = m_FTPClient.SetTransferType(l_WantedMode);
if (l_iRetval == 0 ) {
string l_strError = m_FTPClient.GetLastError();
this.Cursor = Cursors.Arrow;
MessageBox.Show(l_strError,"FTP Explorer",MessageBox.IconStop);
return;
}
}
m_progressBarFileStatus.Visible = true;
int l_iDownloadSize = 5120; /* 5K at a time */
int l_iFileSize = 0;
int l_iSkippedCount = 0;
int l_iDownloadCount = 0;
/* Download file here */
// Pass this array l_strarrFinalArray
foreach(object obj in l_FileList) {
l_TempObject = (DownloadFileData) obj;
l_iFileSize = l_TempObject.FileSize;
if (l_iFileSize == 0 ) {
l_iSkippedCount++;
continue;
}
/* Reset the Progress Bar Properties */
m_progressBarFileStatus.Minimum = 0;
m_progressBarFileStatus.Maximum = 0;
m_progressBarFileStatus.PerformStep();
/* Set Progress Bar properties */
m_progressBarFileStatus.Minimum = 0;
m_progressBarFileStatus.Maximum = l_iFileSize / l_iDownloadSize;
m_progressBarFileStatus.Step = 1;
statusBarPanel2.Text = "Now downloading '" + l_TempObject.ServerFileName + "' . Please wait...";
m_statusBar.Refresh();
/* Do the First Step here */
m_progressBarFileStatus.PerformStep();
m_progressBarFileStatus.Refresh();
/* Download file here */
l_iRetval = m_FTPClient.DownLoadFile(l_TempObject,l_WantedMode);
if ( l_iRetval == 0 ) {
string l_strErrorMessage = m_FTPClient.GetLastError();
l_strErrorMessage += ". Aborting the rest of process";
this.Cursor = Cursors.Arrow;
MessageBox.Show(l_strErrorMessage,"FTP Explorer",MessageBox.IconError);
/* Hide the Progress bar */
m_progressBarFileStatus.Visible = false;
/* Reset to 'A' type */
if ( l_CurrentMode != l_WantedMode ) {
this.Cursor = Cursors.WaitCursor;
statusBarPanel2.Text = "Setting to Ascii transfer type...";
m_statusBar.Refresh();
l_iRetval = m_FTPClient.SetTransferType(l_CurrentMode);
this.Cursor = Cursors.Arrow;
}
statusBarPanel2.Text = "Logged in as " + m_strFTPUser ;
return;
}
/* Do the Last Step here *
m_progressBarFileStatus.PerformStep();
m_progressBarFileStatus.Refresh();
*/
l_iDownloadCount++;
}
/* Set back to ASCII mode. ASCII mode is
* the default for LIST command
* */
if ( l_CurrentMode != l_WantedMode ) {
statusBarPanel2.Text = "Setting to Ascii transfer type...";
m_statusBar.Refresh();
l_iRetval = m_FTPClient.SetTransferType(l_CurrentMode);
}
l_strMessage = "";
if ( l_iSkippedCount > 0 ) {
l_strMessage = l_iDownloadCount + " file(s) downloaded successfully. " + l_iSkippedCount + " file(s) skipped due to zero length";
}
else {
l_strMessage = l_iDownloadCount + " file(s) downloaded successfully";
}
MessageBox.Show(l_strMessage,"FTP Explorer",MessageBox.IconInformation);
/* Hide the status bar */
m_progressBarFileStatus.Visible = false;
statusBarPanel2.Text = "Logged in as " + m_strFTPUser ;
m_statusBar.Refresh();
this.Cursor = Cursors.Arrow;
return;
}
protected void OnClickUploadFile (object sender, System.EventArgs e)
{
string l_strMessage = "Upload file functionality will be supported in Beta 2 release of FTP Explorer";
MessageBox.Show(l_strMessage,"FTP Explorer - Information",MessageBox.IconInformation);
}
protected void OnClickExit (object sender, System.EventArgs e)
{
if ( m_bConnectedFlag == true ) {
if ( MessageBox.Show("Do you wish to close the current session ?","FTP Explorer",MessageBox.IconStop | MessageBox.OKCancel | MessageBox.DefaultButton2) == DialogResult.OK ) {
statusBarPanel1.Text = "Closing connection. Please wait...";
m_statusBar.Refresh();
OnClickDisconnect(sender,e);
this.Close();
}
}
else {
this.Close();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -