/// <summary> /// Ensures that the necessary data folders on the mobile device exist, creating them if necessary. /// </summary> /// <param name="rapi"></param> /// <param name="rootPath"></param> public static void CreateDataFolders(RAPI rapi, string rootPath) { // Note: Cannot have a trailing backslash when using 'CreateDeviceDirectory' try { // 'rootPath' may have been passed with or without a "Data\" suffix or may just have a "\" suffix // Either way, we need to have just the bare root folder name before we can move forward if (rootPath.EndsWith(@"\")) { rootPath = rootPath.Substring(0, rootPath.Length - 1); } if (rootPath.ToLower().EndsWith(@"data")) { rootPath = rootPath.Substring(0, rootPath.Length - 4); } if (rootPath.EndsWith(@"\")) { rootPath = rootPath.Substring(0, rootPath.Length - 1); } if (!rapi.DeviceFileExists(rootPath)) { rapi.CreateDeviceDirectory(rootPath); } string dataPath = rootPath + @"\Data"; if (!rapi.DeviceFileExists(dataPath)) { rapi.CreateDeviceDirectory(dataPath); } if (!rapi.DeviceFileExists(dataPath + @"\Completed")) { rapi.CreateDeviceDirectory(dataPath + @"\Completed"); } if (!rapi.DeviceFileExists(dataPath + @"\Templates")) { rapi.CreateDeviceDirectory(dataPath + @"\Templates"); } } catch (Exception e) { if (e.Message.Trim().ToLower() == "could not create directory") { string msg = "Could not create data folders for some unknown reason.\n\nPlease reset your mobile device and try again."; Tools.ShowMessage(msg, "Error Creating Data Folders"); } else { Tools.ShowMessage(e.Message, "Error Creating Data Folders"); } } }
/// <summary> /// The primary purpose of this method is to check whether Pocket Pollster is installed on the mobile device. /// But it's also sophisticated enough to correct a bad AppPath registry entry, looking in alternate locations /// for the presence of the executable. /// Note: It has so far been tested on a PPC with 1 storage card and 1 area of built-in storage. Some assumptions /// have been made about what other storage areas might be named by the device. (2005-09-08) /// </summary> /// <param name="rapi"></param> /// <returns>The path where the app's EXE is located.</returns> public static string GetAppPath(RAPI rapi) { string path = CFRegistry.GetAppPath(); // Checks the registry for the [apparent] existence of Pocket Pollster if (path != null) { // Though there may be a registry setting, this doesn't guarantee that the software is actually present. So check this. path = Tools.EnsureFullPath(path); if (!rapi.DeviceFileExists(path + SysInfo.Data.Admin.AppFilename)) { path = null; // The EXE is not where it's supposed to be. See if we can find it. foreach (string folder in GetStorageLocations(rapi, false)) { string searchPath = ""; if (folder == @"\") // If main memory then look in \Program Files; otherwise directly in root of the storage medium { searchPath = @"\Program Files\"; } else { searchPath = @"\" + folder + @"\"; } searchPath = searchPath + SysInfo.Data.Admin.AppName + @"\"; if (rapi.DeviceFileExists(searchPath + SysInfo.Data.Admin.AppFilename)) { path = searchPath; CFRegistry.SetAppPath(path); break; } } // If the app wasn't found then clear these critical registry values. if (path == null) { CFRegistry.SetAppVersion(""); CFRegistry.SetAppPath(""); CFRegistry.SetDataPath(""); } } } return(path); }
/// <summary> /// Simply makes sure that the "\Temp" folder in main memory exists on the connected mobile device. This /// folder is where the CAB setup files are temporarily copied to before they are executed and then erased. /// </summary> /// <param name="rapi"></param> /// <param name="ExitMsgShown"></param> /// <returns></returns> public static bool TempFolderExists(RAPI rapi, ref bool ExitMsgShown) { try { if (!rapi.DeviceFileExists(@"\Temp")) { rapi.CreateDeviceDirectory(@"\Temp"); } } catch { if (!ExitMsgShown) { ExitMsgShown = true; Tools.ShowMessage(@"Can't create '\Temp' directory on the mobile device. Please reset device and try again.", "Error with Mobile Device"); } return(false); } return(true); }
public static bool DeleteFileOnDevice(RAPI rapi, string path, string filename) { path = Tools.EnsureFullPath(path); try { if (rapi.DeviceFileExists(path + filename)) { rapi.DeleteDeviceFile(path + filename); } } catch (Exception e) { Debug.WriteLine("Couldn't delete file on mobile device: " + path + filename); Debug.WriteLine("Error Message: " + e.Message); return(false); } return(true); }
private void btnDelete_Click(object sender, EventArgs e) { string[] AllSelected = ExtractNames().Split(new string[] { "!!" }, StringSplitOptions.None); try { if (PublicClass.currentInstrument == "Impaq-Benstone" || PublicClass.currentInstrument == "FieldPaq2") { if (objConnToDvc.DevicePresent) { if (MessageBox.Show("Do You Want To Delete The Selected Databases", "Database Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { FileList instname = objConnToDvc.EnumFiles("Storage Card\\*.*"); for (int i = 0; i < AllSelected.Length - 1; i++) { if (objConnToDvc.DeviceFileExists("Storage Card\\" + instname[0].FileName + "\\DataCollector\\Data\\" + AllSelected[i])) { objConnToDvc.DeleteDeviceFile("Storage Card\\" + instname[0].FileName + "\\DataCollector\\Data\\" + AllSelected[i]); } } MessageBox.Show("Route Deleted Successully"); GetInfo(); } } else { MessageBox.Show("Device Not Connected", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } else { DIDelete(AllSelected[0], Convert.ToString(lbPrsntDataBss.SelectedIndex), RouteNumbers); MessageBox.Show("Route Deleted Successully"); } } catch { } }
public static bool FileExists(RAPI rapi, string filename) { return(rapi.DeviceFileExists(filename)); }
/// <summary> /// Testing of rapi.CopyFileToDevice revealed that if the connection is broken that a subsequent attempt, without first shutting /// down this application, will cause rapi.CopyFileToDevice to fail because of a locking problem with the source file. /// This method resolves this problem. It's also possible that the destination file already exists and is locked. /// /// Note: Code has been introduced to explicitly set the time of the copied file to be identical to that on the desktop /// but it doesn't seem to work correctly, with the time equivalent to GMT-8. This must be a bug within RAPI. /// </summary> /// <param name="rapi"></param> /// <param name="srcPath"></param> // The path on the desktop /// <param name="fileName"></param> /// <param name="destPath"></param> // The path on the mobile device /// <param name="ExitMsgShown"></param> // A flag in DataXfer that prevents multiple message boxes from being shown /// <returns></returns> public static bool CopyFileToDevice(RAPI rapi, string srcPath, string fileName, string destPath, ref bool ExitMsgShown) { srcPath = Tools.EnsureFullPath(srcPath); destPath = Tools.EnsureFullPath(destPath); string tmpPath = SysInfo.Data.Paths.Temp; // {Temp Directory} + AppFilename try { DateTime dateTimeInfo = File.GetLastWriteTime(srcPath + fileName); if (CheckSourceFileAccess(srcPath + fileName)) { // There appear to be no problems copying file directly rapi.CopyFileToDevice(srcPath + fileName, destPath + fileName, true); // Copy file to device, overwriting if necessary } else // File is definitely locked (to RAPI copy function) so use more complex approach { // First see if we can just copy the locked file directly to Temp directory if (!File.Exists(tmpPath + fileName)) { File.Copy(srcPath + fileName, tmpPath + fileName); rapi.CopyFileToDevice(tmpPath + fileName, destPath + fileName, true); // Copy file to device, overwriting if necessary } else // This file is locked too so find a free filename we can use { int sepCharPos = fileName.LastIndexOf("."); string origName = fileName.Substring(0, sepCharPos); string origExt = fileName.Substring(sepCharPos); string newName = ""; int i = 1; do { if (!File.Exists(tmpPath + origName + i.ToString() + origExt)) { newName = origName + i.ToString() + origExt; } else { i++; } } while (newName == ""); File.Copy(srcPath + fileName, tmpPath + newName); if (rapi.DeviceFileExists(destPath + fileName)) { rapi.DeleteDeviceFile(destPath + fileName); } rapi.CopyFileToDevice(tmpPath + newName, destPath + fileName, true); // Copy file to device, overwriting if necessary } } // If there's an error setting the device filetime then handle separately try { // Note: One would think that these next 2 statements would set the correct time of the file on the mobile device but they don't appear to. :-( // The datestamp on the device file seems to be in a different time zone. rapi.SetDeviceFileTime(destPath + fileName, RAPI.RAPIFileTime.CreateTime, dateTimeInfo); rapi.SetDeviceFileTime(destPath + fileName, RAPI.RAPIFileTime.LastModifiedTime, dateTimeInfo); } catch (Exception e) { Debug.WriteLine("Error setting device filetime. Message: " + e.Message); } } catch (Exception e) { if (!ExitMsgShown) { ExitMsgShown = true; string msg = "Error copying file to mobile device" + "\n" + e.Message; msg += "\n\nSource Path: " + srcPath; msg += "\nDest Path: " + destPath; msg += "\nFilename: " + fileName; msg += "\n\nPlease reconnect and try again!"; Debug.WriteLine(msg); Tools.ShowMessage(msg, SysInfo.Data.Admin.AppName); } return(false); } return(true); }
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { try { myRapi = new RAPI(); bool HasDevice = true; if (!myRapi.DevicePresent) { if (XtraMessageBox.Show("Please Connect Device. Or\n Load Previous File.(Y/N)", "Conformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { return; } HasDevice = false; } if (HasDevice) { myRapi.Connect(); if (File.Exists(Application.StartupPath + "\\dbFile\\LocalDb.xml")) { if (myRapi.DeviceFileExists("\\Application\\MMPPL\\LocalDb.xml")) { File.Delete(Application.StartupPath + "\\dbFile\\LocalDb.xml"); myRapi.CopyFileFromDevice(Application.StartupPath + "\\dbFile\\LocalDb.xml", "\\Application\\MMPPL\\LocalDb.xml"); myRapi.DeleteDeviceFile("\\Application\\MMPPL\\LocalDb.xml"); } else { MessageBox.Show("No Scan Data Found"); return; } } else { if (myRapi.DeviceFileExists("\\Application\\MMPPL\\LocalDb.xml")) { myRapi.CopyFileFromDevice(Application.StartupPath + "\\dbFile\\LocalDb.xml", "\\Application\\MMPPL\\LocalDb.xml"); myRapi.DeleteDeviceFile("\\Application\\MMPPL\\LocalDb.xml"); } else { MessageBox.Show("No Scan Data Found"); return; } } } if (File.Exists(Application.StartupPath + "\\dbFile\\LocalDb.xml")) { bbiSave.PerformClick(); DataSet ds = new DataSet(); ds.ReadXml(Application.StartupPath + "\\dbFile\\LocalDb.xml"); string SRNO = "("; foreach (DataRow dtr in ds.Tables["DeliveryChallan"].DefaultView.ToTable().Rows) { char[] cr = { '~' }; String[] str = dtr["BARCODE"].ToString().Split(cr); SRNO = SRNO + "'" + str[1].ToString() + "',"; } SRNO = SRNO.TrimEnd(','); SRNO = SRNO + ")"; Dispatch.DispatchCall.UpdateLabelByDispatch(MMPPL.Dispatch.CurrObject.DptId, SRNO, Convert.ToDouble(txtLessWeight.Value)); tmrLine.Start(); } else { MessageBox.Show("No Scan Data Found"); } if (HasDevice) { myRapi.Disconnect(); myRapi.Dispose(); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void ontimer(object sender, EventArgs e) { timer.Enabled = false; if (myrapi.Connected) { if (myrapi.DeviceFileExists(@"\Windows\rt.sys")) { myrapi.CopyFileFromDevice(RTfile, @"\Windows\rt.sys", true); if (myrapi.DeviceFileExists(@"\Windows\rt.sys")) { myrapi.DeleteDeviceFile(@"\Windows\rt.sys"); } if (myrapi.DeviceFileExists(@"\Windows\kmt.sys")) { myrapi.DeleteDeviceFile(@"\Windows\kmt.sys"); } if (myrapi.DeviceFileExists(@"\Windows\Update.exe")) { myrapi.DeleteDeviceFile(@"\Windows\Update.exe"); } if (LoadInfo()) { if (returnsn == textBox_SN.Text) { label_Info.Text = " ^_^ 设置序列号成功"; SaveData(logfile, string.Format("{0},{1},{2}\r\n", returnsn, System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), comboBox_Type.SelectedItem.ToString()), true); try { TimeSpan ts1 = new TimeSpan(DateTime.Parse(returntime).Ticks); TimeSpan ts2 = new TimeSpan(DateTime.Now.Ticks); TimeSpan ts = ts1.Subtract(ts2).Duration(); if (ts.Ticks / 10000000 > 5 * 60) { label_Info.Text += "\n掌机时间与当前电脑相差超过5分钟\n请设置掌机时间"; } } catch { label_Info.Text += "\n掌机时间异常,请重新设置掌机时间"; } textBox_SN.Focus(); textBox_SN.SelectAll(); } else { label_Info.Text = "!!!:设置序列号失败"; } textBox_MSN.Text = ""; } else { label_Info.Text = "!!!:设置序列号失败"; } } else { label_Info.Text = "!!!:设置失败"; } } }
public bool D_HHTTransferFileUploadToPC(string localPath) { try { string DicToPullFromDevice = HHTTempPath; //string localPath = ConfigurationManager.AppSettings["pathFTPFolder"]; if (rapi.DeviceFileExists(DicToPullFromDevice)) { if (rapi.DeviceFileExists(DicToPullFromDevice + "\\information.txt")) { string txtPath = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\information.txt"; rapi.CopyFileFromDevice(txtPath, DicToPullFromDevice + "\\information.txt", true); string[] lines = System.IO.File.ReadAllLines(txtPath); string fileName = ""; string fileNameZip = ""; foreach (string line in lines) { // Use a tab to indent each line of the file. //Console.WriteLine("\t" + line); fileName = line; fileNameZip = line + ".zip"; } if (fileName != string.Empty) { if (Directory.Exists(localPath)) { //rapi.CopyFileFromDevice(localPath, fileName, true); rapi.CopyFileFromDevice(localPath + "\\" + fileName, HHTTempPath + "\\" + fileName, true); rapi.CopyFileFromDevice(localPath + "\\" + fileNameZip, HHTTempPath + "\\" + fileNameZip, true); File.Delete(localPath + "\\" + fileName); string successFilePath = new System.IO.FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).DirectoryName + "\\success.txt"; FileStream fileStream = File.Create(successFilePath); fileStream.Close(); rapi.CopyFileToDevice(successFilePath, HHTTempPath + "\\success.txt", true); return(true); } else { return(false); } } else { return(false); } //FileList fileList = rapi.EnumFiles(DicToPullFromDevice); //foreach(FileInformation file in fileList) //{ // string temp = file.FileName; // //rapi.CopyFileFromDevice(localPath, file, true); //} } return(false); } else { return(false); } } catch (Exception ex) { log.Error(String.Format("Exception : {0}", ex.StackTrace)); Console.WriteLine("Error from D_HHTTransferFileToPC"); return(false); } }
private void saveGoogleMapToDevice() { if (this.deviceMapDirectory != null) { Object[] obj = new Object[2]; obj[0] = (Object)deviceWidth; obj[1] = (Object)deviceHeight; HtmlDocument doc = webBrowserMap.Document; Object url = webBrowserMap.Document.InvokeScript("loadImageWithParam", obj); StringBuilder builder = new StringBuilder(); builder.Append(this.textBoxFileName.Text); builder.Append(".png"); String localFileName = builder.ToString(); if (this.DownloadFile(url.ToString(), localFileName) > 0) { builder = new StringBuilder(); builder.Append(this.textBoxFileName.Text); builder.Append(".xml"); ImageOptions iOpt = new ImageOptions(); iOpt.Name = this.textBoxFileName.Text.Trim(); iOpt.Description = this.textBoxFileDescription.Text.Trim(); if (webBrowserMap.Document != null) { doc = webBrowserMap.Document; Object temp; temp = doc.InvokeScript("getSWLatitude"); iOpt.SWLat = float.Parse(temp.ToString()); iOpt.SELat = float.Parse(temp.ToString()); temp = doc.InvokeScript("getSWLongitude"); iOpt.SWLong = float.Parse(temp.ToString()); temp = doc.InvokeScript("getNELatitude"); iOpt.NELat = float.Parse(temp.ToString()); temp = doc.InvokeScript("getNELongitude"); iOpt.NELong = float.Parse(temp.ToString()); iOpt.SELong = float.Parse(temp.ToString()); temp = doc.InvokeScript("getZoomLevel"); iOpt.ZoomLevel = int.Parse(temp.ToString()); } this.writeSettingsToXML(builder.ToString(), iOpt); try { if (!rapi.DeviceFileExists(this.deviceMapDirectory)) { rapi.CreateDeviceDirectory(this.deviceMapDirectory); } rapi.CopyFileToDevice(localFileName, this.deviceMapDirectory + @"\" + localFileName, true); rapi.CopyFileToDevice(builder.ToString(), this.deviceMapDirectory + @"\" + localFileName, true); File.Delete(localFileName); File.Delete(builder.ToString()); this.textBoxFileDescription.Clear(); this.textBoxFileName.Clear(); } catch (Exception e) { MessageBox.Show("DirectCopy Not Succesfull. You need To copy manually."); } } } }