private void monitorPdaExportProgress() { int errorCount = 0; int tileCount = 0; int toExport = TerraserverCache.TileNamesCollection.Count; int percentComplete = 0; int percentCompletePrev = 0; foreach (string tileName in TerraserverCache.TileNamesCollection.Keys) { string srcPath = TerraserverCache.tileImagePath(tileName); if (File.Exists(srcPath)) { try { PdaHelper.exportSingleFile(tileName, srcPath, true); if ((tileCount % 10) == 0) { labelInfo.Text = "" + tileCount + " of " + toExport + " " + tileName; } tileCount++; percentComplete = toExport == 0 ? 0 : (tileCount * 100 / toExport); if (percentComplete != percentCompletePrev) { percentCompletePrev = percentComplete; progressBar.Value = percentComplete; } } catch (Exception exc) { errorCount++; LibSys.StatusBar.Error("exporting PDA file: " + srcPath + " -- " + exc.Message); } } else { errorCount++; LibSys.StatusBar.Error("exporting PDA file: " + srcPath + " -- file does not exist"); } } TerraserverCache.TileNamesCollection.Clear(); TerraserverCache.TileNamesCollection = null; labelHeader.Text = headerText2; labelInfo.Text = String.Format(infoText, tileCount, errorCount); progressBar.Visible = false; m_pdaCopyThread = null; // and exit, terminating the thread. }
private bool verifyPdaExportSet() { int tileCount = 0; int toFixCount = 0; int fixedCount = 0; int toExport = TerraserverCache.TileNamesCollection.Count; int percentToFix = 0; ArrayList ToFix = new ArrayList(); if (toExport == 0) { return(false); } /* * // for debugging - delete some tiles to test fixing logic: * int delCnt = 100; * foreach(string tileName in TerraserverCache.TileNamesCollection.Keys) * { * string srcPath = TerraserverCache.tileImagePath(tileName); * * if(File.Exists(srcPath)) * { * try * { * File.Delete(srcPath); * } * catch {} * } * if(delCnt-- <= 0) * { * break; * } * } * // end for debugging */ foreach (string tileName in TerraserverCache.TileNamesCollection.Keys) { string srcPath = TerraserverCache.tileImagePath(tileName); if (File.Exists(srcPath)) { tileCount++; } else { toFixCount++; LibSys.StatusBar.Error("file: " + srcPath + " -- was not downloaded correctly, fixing..."); ToFix.Add(srcPath); tryFixTile(tileName); } } percentToFix = toExport == 0 ? 0 : (toFixCount * 100 / toExport); labelInfo.Text = String.Format(verifyText, tileCount, toFixCount, percentToFix, fixedCount); fixagain: DateTime startedFixing = DateTime.Now; while (ToFix.Count > 0 && DateTime.Now < startedFixing.AddSeconds(20)) { again: foreach (string srcPath in ToFix) { if (File.Exists(srcPath)) { LibSys.StatusBar.Trace("OK: file " + srcPath + " -- was fixed."); ToFix.Remove(srcPath); fixedCount++; goto again; } } Application.DoEvents(); labelInfo.Text = String.Format(verifyText, tileCount, toFixCount, percentToFix, fixedCount); Thread.Sleep(1000); } if (ToFix.Count > 0) { if (Project.YesNoBox(m_parent, fixedCount == 0 ? String.Format(verifyErrorText0, ToFix.Count) : String.Format(verifyErrorText, fixedCount, toFixCount, ToFix.Count)) ) { goto fixagain; } } labelInfo.Text = String.Format(verifyText, tileCount, toFixCount, percentToFix, fixedCount); return((toExport - ToFix.Count + fixedCount) > 0); }