📄 common.cs
字号:
//Filename : Common.cs
//Part of : Application installer C# example
//Description : Main module of CSInstaller.NET example application
//Version : 3.2
//
//This example is only to be used with PC Connectivity API version 3.2.
//Compability ("as is") with future versions is not quaranteed.
//
//Copyright (c) 2007 Nokia Corporation.
//
//This material, including but not limited to documentation and any related
//computer programs, is protected by intellectual property rights of Nokia
//Corporation and/or its licensors.
//All rights are reserved. Reproducing, modifying, translating, or
//distributing any or all of this material requires the prior written consent
//of Nokia Corporation. Nokia Corporation retains the right to make changes
//to this material at any time without notice. A copyright license is hereby
//granted to download and print a copy of this material for personal use only.
//No other license to any other intellectual property rights is granted. The
//material is provided "as is" without warranty of any kind, either express or
//implied, including without limitation, any warranty of non-infringement,
//merchantability and fitness for a particular purpose. In no event shall
//Nokia Corporation be liable for any direct, indirect, special, incidental,
//or consequential loss or damages, including but not limited to, lost profits
//or revenue,loss of use, cost of substitute program, or loss of data or
//equipment arising out of the use or inability to use the material, even if
//Nokia Corporation has been advised of the likelihood of such damages occurring.
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace CSInstaller
{
using CONADefinitions;
using CONAFileSystem;
using PCCAPIUtils;
using PCCSErrors;
class Common
{
// Device manager handle
public static int hDMHandle = 0;
// File System handle
public static int hFSHandle = 0;
// Main form of application
public static InstallerDialog MainForm;
// Phone supports appication uninstallation
public static bool bAppUninstallSupported;
//===================================================================
// DeviceNotifyCallback
//
// Callback function for device connection notifications
//
//===================================================================
public static int DeviceNotifyCallback(
int iStatus,
[MarshalAs(UnmanagedType.LPWStr)] string pstrSerialNumber)
{
try
{
MainForm.bRefreshPhonecombo = true;
return PCCSErrors.CONA_OK;
}
catch
{
return -1;
}
}
//===================================================================
// FSNotifyCallback
//
// Callback function for file operation notifications
//
//===================================================================
public static int FSNotifyCallback(int iOperation, int iStatus, int iTransferredBytes, int iAllBytes)
{
int functionReturnValue = 0;
functionReturnValue = PCCSErrors.CONA_OK;
if (iOperation == CONADefinitions.CONAInstallApplicationNtf)
{
if (iStatus == PCCSErrors.CONA_OK_BUT_USER_ACTION_NEEDED)
{
// Show text stating wait status
MainForm.labelWait.Visible = true;
MainForm.ProgressBar1.Visible = false;
}
else
{
MainForm.SetProgress(iStatus);
}
}
else
{
MainForm.SetProgress(iStatus);
}
if (MainForm.IsCancelled())
{
functionReturnValue = PCCSErrors.ECONA_CANCELLED;
}
return functionReturnValue;
}
//===================================================================
// InstallJavaApplication
//
// Install Java application to phone
//
//===================================================================
public static int InstallJavaApplication(string strJarFile, string strJadFile)
{
int functionReturnValue = 0;
string jarFile;
string jadFile;
string path;
CONAApplicationInstallation.CONAPI_APPLICATION_JAVA javaFiles;
int dwOptions = CONADefinitions.CONA_DEFAULT_FOLDER | CONADefinitions.CONA_OVERWRITE | CONADefinitions.CONA_WAIT_THAT_USER_ACTION_IS_DONE;
jarFile = System.IO.Path.GetFileName(strJarFile);
jadFile = System.IO.Path.GetFileName(strJadFile);
javaFiles.pstrFileNameJar = jarFile;
if (jadFile.Length == 0)
{
javaFiles.pstrFileNameJad = null;
}
else
{
javaFiles.pstrFileNameJad = jadFile;
}
path = System.IO.Path.GetDirectoryName(strJarFile);
functionReturnValue = CONAApplicationInstallation.CONAInstallJavaApplication(hFSHandle, CONAApplicationInstallation.CONA_APPLICATION_TYPE_JAVA, ref javaFiles, dwOptions, path, null);
switch (functionReturnValue) {
case PCCSErrors.CONA_OK:
MessageBox.Show("Application installation succeeded");
break;
case PCCSErrors.CONA_OK_BUT_USER_ACTION_NEEDED:
// Either device does not support waiting or the maximum waiting time exceeded
MessageBox.Show("User action needed on the device side");
break;
default:
PCCAPIUtils.ShowErrorMessage("CONAInstallApplication", functionReturnValue);
break;
}
return functionReturnValue;
}
//===================================================================
// InstallSymbianApplication
//
// Install Symbian application to phone
//
//===================================================================
public static int InstallSymbianApplication(string strFile)
{
int functionReturnValue = 0;
string sisFile;
string path;
CONAApplicationInstallation.CONAPI_APPLICATION_SIS sisFiles;
int dwOptions = CONADefinitions.CONA_DEFAULT_FOLDER | CONADefinitions.CONA_OVERWRITE | CONADefinitions.CONA_WAIT_THAT_USER_ACTION_IS_DONE;
sisFile = System.IO.Path.GetFileName(strFile);
sisFiles.pstrFileNameSis = sisFile;
path = System.IO.Path.GetDirectoryName(strFile);
functionReturnValue = CONAApplicationInstallation.CONAInstallSymbianApplication(hFSHandle, CONAApplicationInstallation.CONA_APPLICATION_TYPE_SIS, ref sisFiles, dwOptions, path, null);
switch (functionReturnValue) {
case PCCSErrors.CONA_OK:
MessageBox.Show("Application installation succeeded");
break;
case PCCSErrors.CONA_OK_BUT_USER_ACTION_NEEDED:
// Either device does not support waiting or the maximum waiting time exceeded
MessageBox.Show("User action needed on the device side");
break;
default:
PCCAPIUtils.ShowErrorMessage("CONAInstallApplication", functionReturnValue);
break;
}
return functionReturnValue;
}
//===================================================================
// InstallTheme
//
// Install theme to phone
//
//===================================================================
public static int InstallTheme(string strFile)
{
int functionReturnValue = 0;
string strNthFile = "";
string path = "";
CONAApplicationInstallation.CONAPI_APPLICATION_FILE nthFile = new CONAApplicationInstallation.CONAPI_APPLICATION_FILE();
int dwOptions = CONADefinitions.CONA_DEFAULT_FOLDER | CONADefinitions.CONA_OVERWRITE | CONADefinitions.CONA_WAIT_THAT_USER_ACTION_IS_DONE;
strNthFile = System.IO.Path.GetFileName(strFile);
nthFile.pstrFileName = strNthFile;
path = System.IO.Path.GetDirectoryName(strFile);
functionReturnValue = CONAApplicationInstallation.CONAInstallTheme(hFSHandle, CONAApplicationInstallation.CONA_APPLICATION_TYPE_THEMES, ref nthFile, dwOptions, path, null);
switch (functionReturnValue) {
case PCCSErrors.CONA_OK:
MessageBox.Show("Application installation succeeded");
break;
case PCCSErrors.CONA_OK_BUT_USER_ACTION_NEEDED:
// Either device does not support waiting or the maximum waiting time exceeded
MessageBox.Show("User action needed on the device side");
break;
default:
PCCAPIUtils.ShowErrorMessage("CONAInstallApplication", functionReturnValue);
break;
}
return functionReturnValue;
}
//===================================================================
// InstallNGageApplication
//
// Install NGage application to phone
//
//===================================================================
public static int InstallNGageApplication(string strFile)
{
int functionReturnValue = 0;
string nGageFile;
string sourcePath;
string targetPath = "\\\\C:\\Data\\";
//Phone memory is used
string nGageFolder = "N-Gage";
int iOptions = CONADefinitions.CONA_DIRECT_PC_TO_PHONE | CONADefinitions.CONA_OVERWRITE;
int iResult;
// Split source file name in path and file name
nGageFile = System.IO.Path.GetFileName(strFile);
sourcePath = System.IO.Path.GetDirectoryName(strFile);
// Create n-gage folder on Phone
iResult = CONAFileSystem.CONACreateFolder(hFSHandle, nGageFolder, targetPath);
if (iResult != PCCSErrors.CONA_OK & iResult != PCCSErrors.ECONA_FOLDER_ALREADY_EXIST)
{
PCCAPIUtils.ShowErrorMessage("CONACreateFolder", iResult);
}
// Append n-gage foldr to target path
targetPath = targetPath + nGageFolder;
// N-Gage application is installed by copying file to predefined folder,
functionReturnValue = CONAFileSystem.CONACopyFile(hFSHandle, iOptions, nGageFile, sourcePath, targetPath);
if (functionReturnValue == PCCSErrors.CONA_OK)
{
MessageBox.Show("Application installation succeeded");
}
else
{
PCCAPIUtils.ShowErrorMessage("CONACopyFile", functionReturnValue);
}
return functionReturnValue;
}
//===================================================================
// UnInstallApplication
//
// UnInstalls application from phone
//
//===================================================================
public static int UnInstallApplication(string strAppName, string strAppUID)
{
int functionReturnValue = 0;
int iOptions;
iOptions = CONAApplicationInstallation.CONA_SILENT_UNINSTALLATION;
functionReturnValue = CONAApplicationInstallation.CONAUninstallApplication(hFSHandle, iOptions, strAppName, strAppUID);
if (functionReturnValue != PCCSErrors.CONA_OK)
{
PCCAPIUtils.ShowErrorMessage("CONAUninstallApplication", functionReturnValue);
}
return functionReturnValue;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -