📄 filebrowser.cpp
字号:
return NULL;
#endif
}
int RefreshConnection()
{
if(g_fServerBrowsable)
{
g_SelectionDisabled = TRUE;
TreeView_DeleteAllItems(g_hTreeWnd);
//delete all DIR_NODES
DIRNODE_LIST *pTemp = g_pNodeList;
while(pTemp)
{
DIRNODE_LIST *pDel = pTemp;
pTemp = pTemp->pNext;
if(pDel->pItem)
{
if(pDel->pItem->pFileName)
delete [] pDel->pItem->pFileName;
if(pDel->pItem->pPath)
delete [] pDel->pItem->pPath;
delete pDel->pItem;
}
delete pDel;
}
g_pNodeList = 0;
g_htiParentNode = 0;
if(FAILED(RefreshDirectory(szRequestDir, g_htiParentNode)))
SendMessage(g_hWnd,WM_COMMAND,ID_DEVICE_DISCONNECT,0);
g_SelectionDisabled = FALSE;
}
return 0;
}
DWORD WINAPI GetFile(LPVOID lpParam)
{
if(g_SelectedNode && !g_SelectedNode->fDir )
{
if(IDYES == MessageBox(g_hWnd, L"Do you want to fetch this file?", L"Question.", MB_YESNO))
{
dwBytesTotal = g_SelectedNode->dwSize;
if(FAILED(FetchFile(g_SelectedNode->pFileName, g_SelectedNode->pPath)))
{
MessageBox(g_hWnd, L"An error occured in transmission.", L"Error", MB_OK);
}
dwBytesTotal = 0xFFFFFFFF;
}
}
else if(g_SelectedNode && g_SelectedNode->fDir)
MessageBox(g_hWnd, L"Please select a file", L"Error", MB_OK);
else
MessageBox(g_hWnd, L"Please select a leaf on the tree", L"Error", MB_OK);
return 0;
}
DWORD WINAPI PutFile(LPVOID lpParam)
{
if(!g_SelectedNode)
{
MessageBox(g_hWnd, L"No directory selected.", L"Please Select Directory", MB_OK);
}
else
{
if(SUCCEEDED(SendFile()))
{
SendMessage(g_hWnd,WM_COMMAND,ID_DEVICE_REFRESH,0);
}
else
{
MessageBox(g_hWnd, L"Sending failed -- are you connected?", L"Send Error", MB_OK);
SendMessage(g_hWnd,WM_COMMAND,ID_DEVICE_DISCONNECT,0);
}
}
return 0;
}
int DeleteNode()
{
//make sure they want to delete the file/directory
if(IDYES != MessageBox(g_hWnd, _T("Do you want to delete this file/directory?"), _T("Are you sure?"), MB_YESNO))
{
return 0;
}
if(!g_SelectedNode)
{
MessageBox(g_hWnd, L"No please select a leaf on the tree.", L"Please Select Node", MB_OK);
}
else
{
HRESULT hr;
IStream *myStream = 0;
IHeaderCollection *pHeaderCollection = 0;
//get a header collection
hr = CoCreateInstance(CLSID_HeaderCollection,
NULL,
CLSCTX_INPROC_SERVER,
IID_IHeaderCollection,
(void **)&pHeaderCollection);
if(SUCCEEDED(hr))
{
if(g_SelectedNode->fDir)
{
//go back to the root directory
hr = g_pObexDevice->SetPath(L"\\", SETPATH_FLAG_DONT_CREATE, 0);
//loop until we at the directory we want to delete
// start by removing all leading \'s
TCHAR *pItem = g_SelectedNode->pPath;
while(SUCCEEDED(hr) && pItem)
{
if(*pItem != '\\')
break;
else
pItem ++;
}
while(SUCCEEDED(hr) && pItem)
{
TCHAR *pTemp = pItem;
pTemp = wcschr(pItem, L'\\');
if(!pTemp)
break;
*pTemp = NULL;
pTemp ++;
hr = g_pObexDevice->SetPath(pItem, SETPATH_FLAG_DONT_CREATE, 0);
pItem = pTemp;
}
if(!pItem)
{
ASSERT(FALSE);
hr = E_FAIL;
}
if(SUCCEEDED(hr))
hr = pHeaderCollection->AddName(pItem);
}
else
{
//go back to the root directory
hr = g_pObexDevice->SetPath(L"\\", SETPATH_FLAG_DONT_CREATE, 0);
//go to the our directory
if(SUCCEEDED(hr))
hr = g_pObexDevice->SetPath(g_SelectedNode->pPath, SETPATH_FLAG_DONT_CREATE, 0);
//add the name of our file
if(SUCCEEDED(hr))
hr = pHeaderCollection->AddName(g_SelectedNode->pFileName);
}
}
if(SUCCEEDED(hr)) {
hr = g_pObexDevice->Put(pHeaderCollection, &myStream);
}
if(myStream) {
//
// Commit the stream to catch any errors that may happen on the
// final packet
if(SUCCEEDED(hr))
hr = myStream->Commit(0);
myStream->Release();
}
if(FAILED(hr)) {
MessageBox(g_hWndStatus, L"Write Failed -- could the server be in read-only mode?", L"Error", MB_OK);
}
if(pHeaderCollection)
pHeaderCollection->Release();
if(FAILED(hr))
MessageBox(g_hWnd, L"An error occured deleting node.", L"Error occured", MB_OK);
//update
SendMessage(g_hWnd,WM_COMMAND,ID_DEVICE_REFRESH,0);
}
return 0;
}
int CreateDirectory()
{
if(!g_SelectedNode)
{
MessageBox(g_hWnd, L"No directory selected as root.", L"Please Select Directory", MB_OK);
}
else
{
if(!g_pObexDevice)
{
MessageBox(g_hWnd, L"You are not connected.", L"Please Connect", MB_OK);
return 0;
}
//prompt for a new directory
if(DialogBox(g_hInst, MAKEINTRESOURCE(IDD_ADD_DIRECTORY), g_hWnd, AddDirectoryDlgProc))
{
InvalidateRect(g_hWnd, NULL, TRUE);
}
if(szNewDirName[0] != NULL)
{
if(!g_pObexDevice ||
FAILED(g_pObexDevice->SetPath(g_SelectedNode->pPath, 0, 0)) ||
FAILED(g_pObexDevice->SetPath(szNewDirName, 0, 0))) {
MessageBox(g_hWnd, L"Creating directory failed -- could the device be in read-only mode?", L"Send Error", MB_OK);
}
SendMessage(g_hWnd,WM_COMMAND,ID_DEVICE_REFRESH,0);
}
}
return 0;
}
int ConfigureServer()
{
if(DialogBox(g_hInst, MAKEINTRESOURCE(IDD_CONFIG_SERVER), g_hWnd, ConfigServerDlgProc))
{
InvalidateRect(g_hWnd, NULL, TRUE);
}
return 0;
}
int ConfigureClient()
{
if(DialogBox(g_hInst, MAKEINTRESOURCE(IDD_CONFIG_CLIENT), g_hWnd, ConfigClientDlgProc))
{
InvalidateRect(g_hWnd, NULL, TRUE);
}
return 0;
}
int GetVCard()
{
if(g_fConnectedTo != CONNECTED_INBOX)
MessageBox(g_hWnd, L"To fetch a default vCard you must be connected to a default inbox", L"Error", MB_OK);
else if(FAILED(FetchFileByMimeType("text/x-vCard", L"default.vcf")))
{
MessageBox(g_hWnd, L"Error fetching vCard from inbox", L"Error", MB_OK);
SendMessage(g_hWnd,WM_COMMAND,ID_DEVICE_DISCONNECT,0);
}
HINSTANCE hDll = LoadLibrary (L"obexvcrd.dll");
if (NULL != hDll)
{
//get a pointer to the DLL's function
OBEXClientPFunct clientPFunct = (OBEXClientPFunct)GetProcAddress (hDll, _T("OBEXInboxClient"));
if (clientPFunct)
{
//pass off the filename
__try
{
WCHAR saveFile[MAX_PATH];
swprintf(saveFile, L"%s\\default.vcf", szStorageDir);
if(clientPFunct(saveFile))
{
MessageBox(g_hWnd, L"An error occured writing vCard --- it is stored in the filesystem as default.vcd",L"Status", MB_OK);
}
else
{
MessageBox(g_hWnd, L"The vCard has been placed into your contacts",L"Status", MB_OK);
}
}
__except (1)
{
}
}
//free the lib
FreeLibrary(hDll);
}
return 0;
}
int ShutDownAndExit()
{
if(g_pObexDevice)
{
g_pObexDevice->Release();
g_pObexDevice = 0;
}
if(g_pObex)
{
g_pObex->Shutdown();
g_pObex->Release();
}
CoUninitialize();
PostQuitMessage(0);
return 0;
}
int Disconnect()
{
g_SelectionDisabled = TRUE;
if(g_pObexDevice)
{
g_pObexDevice->Release();
g_pObexDevice = 0;
}
TreeView_DeleteAllItems(g_hTreeWnd);
//delete all DIR_NODES
DIRNODE_LIST *pTemp = g_pNodeList;
while(pTemp)
{
DIRNODE_LIST *pDel = pTemp;
pTemp = pTemp->pNext;
if(pDel->pItem)
{
if(pDel->pItem->pFileName)
delete [] pDel->pItem->pFileName;
if(pDel->pItem->pPath)
delete [] pDel->pItem->pPath;
delete pDel->pItem;
}
delete pDel;
}
g_pNodeList = 0;
g_htiParentNode = 0;
g_SelectionDisabled = FALSE;
return 0;
}
int Connect(int wParam)
{
if(g_pObexDevice == NULL)
{
//setup the service masks
ULONG ulServiceMask = 0;
if(ID_CONNECT_FB == LOWORD(wParam))
ulServiceMask |= FB_LISTEN_MASK;
if(ID_CONNECT_INBOX == LOWORD(wParam))
ulServiceMask |= INBOX_LISTEN_MASK;
if(ChooseService(g_hInst, g_hWnd, g_pObex, &g_pObexDevice, ulServiceMask) && g_pObexDevice)
{
HCURSOR hCurOld;
hCurOld = SetCursor(LoadCursor(NULL, IDC_WAIT));
IHeaderEnum *pHeaderEnum = 0;
OBEX_HEADER *obHeader;
ULONG ulHeadersFetched;
IHeaderCollection *pHeaderCollection = 0;
//get a header collection
HRESULT hr = CoCreateInstance(CLSID_HeaderCollection,
NULL,
CLSCTX_INPROC_SERVER,
IID_IHeaderCollection,
(void **)&pHeaderCollection);
ASSERT(pHeaderCollection && g_pObexDevice);
if(ID_CONNECT_FB == LOWORD(wParam))
pHeaderCollection->AddTarget(sizeof (CLSID_FileExchange_NetOrder),(UCHAR *)&CLSID_FileExchange_NetOrder);
//now, using the object, connect up
if(szClientPassword[0] != 0)
hr = g_pObexDevice->Connect(szClientPassword,0,pHeaderCollection);
else
hr = g_pObexDevice->Connect(NULL,0,pHeaderCollection);
g_fServerBrowsable = FALSE; //assume we can't browse for now
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -