📄 phonelistbox.cs
字号:
{
string functionReturnValue = null;
functionReturnValue = "";
if (m_wState == Common.PHONELIST_STATE_PHONELIST)
{
// phone list is shown
int index = SelectedIndex;
if (index != -1)
{
// there is a selected item
functionReturnValue = m_strSerialNumbers[index];
}
}
else
{
// user is browsing phone content
functionReturnValue = m_strCurrentSN;
}
return functionReturnValue;
}
//===================================================================
// GetCurrentFriendlyName
//
// Returns friendly name of currently selected phone
//
//===================================================================
public string GetCurrentFriendlyName()
{
string functionReturnValue = null;
functionReturnValue = "";
if (m_wState == Common.PHONELIST_STATE_PHONELIST)
{
// phone list is shown
int index = SelectedIndex;
if (index != -1)
{
// there is a selected item
functionReturnValue = m_strFriendlyNames[index];
}
}
else
{
// user is browsing phone content
functionReturnValue = m_strCurrentFriendlyName;
}
return functionReturnValue;
}
//===================================================================
// GetState
//
// Returns current state of listbox
// (PHONELIST_STATE_PHONELIST or PHONELIST_STATE_PHONECONTENT)
//
//===================================================================
public int GetState()
{
return m_wState;
}
//===================================================================
// SetState
//
// Sets current state of listbox
//
//===================================================================
public void SetState(int wState)
{
m_wState = wState;
}
private string GetFreeMemoryString(CONADefinitions.CONAPI_DEVICE pDevice)
{
string functionReturnValue = null;
int hFS=0;
int iMedia=0;
int iDeviceID=0;
int ret=0;
Int64 iFreeMem = -1;
Int64 iUsedMem = -1;
Int64 iTotalMem = -1;
double dFreeMem= 0.0;
double dUsedMem = 0.0;
double dTotalMem = 0.0;
functionReturnValue = "";
// Create FS connection
iMedia = CONADefinitions.API_MEDIA_ALL;
ret = CONAFileSystem.CONAOpenFS(pDevice.pstrSerialNumber, ref iMedia, ref hFS, ref iDeviceID);
if (ret != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONAOpenFS", ret);
if (ret == PCCSErrors.CONA_OK)
{
// refreshing memory values
ret = CONAFileSystem.CONARefreshDeviceMemoryValues(hFS);
if (ret != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONARefreshDeviceMemoryValues", ret);
functionReturnValue = PCCAPIUtils.Long2MediaString(iMedia);
string strMemoryTypes = "";
ret = CONAFileSystem.CONAGetMemoryTypes(hFS, ref strMemoryTypes);
if (ret == PCCSErrors.CONA_OK)
{
string[] strMemoryTypeArray = strMemoryTypes.Split((','));
foreach (string strType in strMemoryTypeArray)
{
// Getting memory of connected device
ret = CONAFileSystem.CONAGetMemoryValues(hFS, strType, ref iFreeMem, ref iTotalMem, ref iUsedMem);
if (ret != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONAGetMemoryValues", ret);
if (ret == PCCSErrors.CONA_OK)
{
functionReturnValue += "; " + strType + ": ";
if (iFreeMem != -1)
{
dFreeMem = iFreeMem;
functionReturnValue += "Free " + string.Format("{0:F}", dFreeMem / 1024 / 1024) + " MB";
}
if (iTotalMem != -1 & iFreeMem != 1)
{
dUsedMem = iUsedMem;
dTotalMem = iTotalMem;
functionReturnValue += ", used " + String.Format("{0:F}", dUsedMem / 1024 / 1024);
functionReturnValue += "/" + String.Format("{0:F}", dTotalMem / 1024 / 1024) + " MB";
}
}
}
}
else
{
PCCAPIUtils.ShowErrorMessage("CONAGetMemoryTypes", ret);
}
ret = CONAFileSystem.CONACloseFS(hFS);
if (ret != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONACloseFS", ret);
}
return functionReturnValue;
}
//===================================================================
// ListAllPhones
//
// Adds all connected phones to list box
//
//===================================================================
public void ListAllPhones()
{
try
{
short i = 0;
int ret = 0;
int piCount = 0;
Int64 iPtr = 0;
IntPtr buffer = IntPtr.Zero;
IntPtr ptr = IntPtr.Zero;
string strText = "";
CONADefinitions.CONAPI_DEVICE[] pDevices;
Common.MainForm.Timer1.Enabled = false;
m_wState = Common.PHONELIST_STATE_PHONELIST;
ResetContent();
m_strCurrentFolder = "";
// Querying count of connected devices
ret = CONADeviceManagement.CONAGetDeviceCount(m_hDMHandle, ref piCount);
if (ret != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONAGetDeviceCount", ret);
if (ret == PCCSErrors.CONA_OK & piCount > 0)
{
pDevices = null;
pDevices = new CONADefinitions.CONAPI_DEVICE[piCount];
m_strSerialNumbers = null;
m_strSerialNumbers = new string[piCount];
m_strFriendlyNames = null;
m_strFriendlyNames = new string[piCount];
// Allocate memory for buffer
buffer = Marshal.AllocHGlobal(piCount * Marshal.SizeOf(typeof(CONADefinitions.CONAPI_DEVICE)));
// Get list of currently connected devices
ret = CONADeviceManagement.CONAGetDevices(m_hDMHandle, ref piCount, buffer);
if (ret != PCCSErrors.CONA_OK)
{
PCCAPIUtils.ShowErrorMessage("CONAGetDevices", ret);
}
else
{
ItemData = null;
ItemData = new string[piCount];
// Add each device to the phone list box
for (i = 0; i < piCount; i++)
{
// Calculate beginning of CONAPI_DEVICE structure of item 'i'
iPtr = buffer.ToInt64() + i * Marshal.SizeOf(typeof(CONADefinitions.CONAPI_DEVICE));
// Convert integer to pointer
ptr = new IntPtr(iPtr);
// Copy data from buffer
pDevices[i] = (CONADefinitions.CONAPI_DEVICE)Marshal.PtrToStructure(ptr, typeof(CONADefinitions.CONAPI_DEVICE));
// Add item to list box
strText = pDevices[i].pstrFriendlyName + " (";
strText += GetFreeMemoryString(pDevices[i]) + ")";
this.Items.Add(strText);
m_strSerialNumbers[i] = pDevices[i].pstrSerialNumber;
m_strFriendlyNames[i] = pDevices[i].pstrFriendlyName;
}
// CONAGetDevices allocates memory for the member variables in
// CONAPI_DEVICE and it is callers responsibility to free it...
ret = CONADeviceManagement.CONAFreeDeviceStructure(piCount, buffer);
if (ret != PCCSErrors.CONA_OK) PCCAPIUtils.ShowErrorMessage("CONAFreeDeviceStructure", ret);
}
Marshal.FreeHGlobal(buffer);
}
Common.MainForm.LBL_PhoneFiles.Text = "";
}
catch (Exception e)
{
MessageBox.Show(e.ToString(), "Exception In ListAllPhones");
}
Common.MainForm.bRefreshPhoneListBox = false;
Common.MainForm.Timer1.Enabled = true;
}
//===================================================================
// ResetContent
//
// Clear contents of list box
//
//===================================================================
public void ResetContent()
{
this.Items.Clear();
}
//===================================================================
// GetSelectedFolder
//
// Returns currently selected folder
//
//===================================================================
public string GetSelectedFolder()
{
string functionReturnValue = null;
functionReturnValue = m_strCurrentFolder;
// Let's check if there is phone folder selected
int index = SelectedIndex;
if (m_wState == Common.PHONELIST_STATE_PHONECONTENT & index != -1)
{
// there is a selected item
string strSelectedTxt;
strSelectedTxt = Items[SelectedIndex].ToString();
if (strSelectedTxt.Substring(0, 1) == "[" & strSelectedTxt != "[..]")
{
// folder [directoryname]
if (!functionReturnValue.EndsWith("\\"))
functionReturnValue += "\\";
functionReturnValue += ItemData[index];
}
}
return functionReturnValue;
}
//===================================================================
// GetCurrentFolder
//
// Returns folder, the content of which is currently shown
//
//===================================================================
public string GetCurrentFolder()
{
return m_strCurrentFolder;
}
//===================================================================
// GetCurrentFile
//
// Returns selected file. Return empty string if no file is selected.
//
//===================================================================
public string GetCurrentFile()
{
string functionReturnValue = null;
functionReturnValue = "";
int index = SelectedIndex;
if (m_wState == Common.PHONELIST_STATE_PHONECONTENT & index != -1)
{
// there is a selected item
string strSelectedTxt;
strSelectedTxt = Items[index].ToString();
if (strSelectedTxt.Substring(0, 1) != "[")
{
// selected item is file
functionReturnValue = ItemData[index];
}
}
return functionReturnValue;
}
//===================================================================
// GetItemData
//
// Return item data of list box item
//
//===================================================================
public string GetItemData(int index)
{
return ItemData[index];
}
//===================================================================
// GetDMHandle
//
// Return device management handle
//
//===================================================================
public int GetDMHandle()
{
return m_hDMHandle;
}
private void InitializeComponent()
{
this.SuspendLayout();
//
// PhoneListBox
//
this.Size = new System.Drawing.Size(120, 95);
this.ResumeLayout(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -