public void startDownload() { FileWrap file = EditorBase.mDownloadManager.getCurDownloadingFile(); mCurDownloadingLabel.Content = "_" + file.getFileName(); mCurFileProgress.Value = mCurFileProgress.Minimum; }
public void updateState() { DownloadManager manager = EditorBase.mDownloadManager; FileWrap file = manager.getCurDownloadingFile(); if (file != null && file.getFileName() != CommonDefine.VERSION && file.getFileName() != CommonDefine.FILELIST) { // 当前进度 float percent = file.getTotalSize() > 0 ? (float)file.getCurSize() / (float)file.getTotalSize() : 0.0f; mCurFileProgress.Value = percent * mCurFileProgress.Maximum; mCurFilePercent.Content = StringUtility.floatToString((float)mCurFileProgress.Value, 2) + "%"; float curSize = file.getCurSize() / 1024.0f; float totalSize = file.getTotalSize() / 1024.0f; mCurSizeLabel.Content = StringUtility.floatToString(MathUtility.KBToMBOrG(curSize), 3) + StringUtility.unitConversion(curSize) + "/" + StringUtility.floatToString(MathUtility.KBToMBOrG(totalSize), 3) + StringUtility.unitConversion(totalSize); // 总文件体积 float downLoadTotalSize = manager.getTotalSize() / 1024.0f; mTotalSizeLabel.Content = StringUtility.floatToString(MathUtility.KBToMBOrG(downLoadTotalSize), 3) + StringUtility.unitConversion(downLoadTotalSize); // 当前下载速度 float curDownLoadSpeed = manager.getCurSpeed() / 1024.0f; mCurSpeedLabel.Content = StringUtility.floatToString(MathUtility.KBToMBOrG(curDownLoadSpeed), 3) + StringUtility.unitConversion(curDownLoadSpeed) + "/S"; // 总进度 float totalPercent = (float)manager.getDownloadedSize() / manager.getTotalSize(); mTotalProgress.Value = totalPercent * mTotalProgress.Maximum; mTotalFileCountText.Content = StringUtility.intToString(manager.getDownloadedCount()) + "/" + StringUtility.intToString(manager.getTotalCount()); mTotalPercent.Content = StringUtility.floatToString((float)mTotalProgress.Value, 2) + "%"; // 预计剩余时间 int hours = 0, minutes = 0, seconds = 0; MathUtility.secondsToHoursMinutesSeconds((int)manager.getRemainTime(), ref hours, ref minutes, ref seconds); string timeString = StringUtility.intToString(hours, 2) + "小时" + StringUtility.intToString(minutes, 2) + "分" + StringUtility.intToString(seconds, 2) + "秒"; mTotalTimeLabel.Content = timeString; } }
private void SetPdfXParameters(IList <string> parameters) { var shortenedTempPath = PathHelper.GetShortPathName(Job.JobTempFolder); parameters.Add("-dPDFX"); Logger.Debug("Shortened Temppath from\r\n\"" + Job.JobTempFolder + "\"\r\nto\r\n\"" + shortenedTempPath + "\""); //Add ICC profile var iccFile = PathSafe.Combine(shortenedTempPath, "profile.icc"); switch (Job.Profile.PdfSettings.ColorModel) { case ColorModel.Cmyk: FileWrap.WriteAllBytes(iccFile, GhostscriptResources.WebCoatedFOGRA28); break; case ColorModel.Gray: FileWrap.WriteAllBytes(iccFile, GhostscriptResources.ISOcoated_v2_grey1c_bas); break; } parameters.Add("-sOutputICCProfile=\"" + iccFile + "\""); //Set in pdf-X example, but is not documented in the distiller parameters var defFile = PathSafe.Combine(shortenedTempPath, "pdfx_def.ps"); var sb = new StringBuilder(GhostscriptResources.PdfxDefinition); sb.Replace("%/ICCProfile (ISO Coated sb.icc)", "/ICCProfile (" + EncodeGhostscriptParametersOctal(iccFile.Replace('\\', '/')) + ")"); FileWrap.WriteAllText(defFile, sb.ToString()); parameters.Add(defFile); }
protected void onStart(string fileName, long totalSize) { if (!mDownloadingFileList.ContainsKey(fileName)) { return; } mCurDownloading = mDownloadingFileList[fileName]; mCurDownloading.setTotalSize(totalSize); // 其他文件在接收到数据时就写入文件,并且先存放到临时目录中 if (fileName != CommonDefine.VERSION && fileName != CommonDefine.FILELIST) { mCurDownloading.startWrite(fileName, CommonDefine.TEMP_PATH + fileName); mCurDownloading.setWriteMode(WRITE_MODE.WM_AUTO_WRITE); mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_START_DOWNLOAD, fileName); } else { mCurDownloading.startWrite(fileName); // 版本文件只在完成下载时才写入文件,标记着当前资源版本 if (fileName == CommonDefine.VERSION) { mCurDownloading.setWriteMode(WRITE_MODE.WM_WRITE_FINISH); } // 列表文件不写入文件 else if (fileName == CommonDefine.FILELIST) { mCurDownloading.setWriteMode(WRITE_MODE.WM_DONT_WRITE); } } }
protected void notifyVersionDownloaded(FileWrap versionFile) { // 版本文件下载完毕后,提示是否有新版本可以更新 string versionString = FileUtility.openTxtFile(CommonDefine.VERSION); bool hasNewVersion = false; if (versionString == "") { hasNewVersion = true; } else { string remoteVersion = BinaryUtility.bytesToString(versionFile.getFileData()); hasNewVersion = remoteVersion != versionString; } if (hasNewVersion) { setState(UPGRADE_STATE.US_WAIT_FOR_UPGRADE); } else { done(); } mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_NEW_VERSION, StringUtility.boolToString(hasNewVersion)); }
/// <summary> /// Method to delete a file given its full path /// </summary> /// <param name="filePath">Full path to the file that will be deleted</param> public void DeleteFileIfExists(string filePath) { FileWrap fileHelper = new FileWrap(); if (fileHelper.Exists(filePath)) { fileHelper.Delete(filePath); } }
public void update(float elapsedTime) { DownloadManager manager = EditorBase.mDownloadManager; FileWrap file = manager.getCurDownloadingFile(); if (manager.getDownloading() && file != null && file.getTotalSize() > 0 && manager.getTotalCount() > 0) { updateState(); } }
public static void Bind(IntPtr L) { AnimationWrap.Register(L); AnimatorWrap.Register(L); ApplicationWrap.Register(L); AssetBundleWrap.Register(L); BaseLuaWrap.Register(L); BehaviourWrap.Register(L); ColorWrap.Register(L); ComponentWrap.Register(L); CoreWrap.Register(L); DebugWrap.Register(L); DeviceInfoWrap.Register(L); DownLoadFromWebWrap.Register(L); EventListenerWrap.Register(L); EventSenderWrap.Register(L); GameObjectWrap.Register(L); JumperWrap.Register(L); LuaLinkerWrap.Register(L); LuaManagerWrap.Register(L); LuaScriptMgrWrap.Register(L); LuaToolsWrap.Register(L); MathWrap.Register(L); MonoBehaviourWrap.Register(L); NGUIDebugWrap.Register(L); ObjectWrap.Register(L); ResourcesWrap.Register(L); TimeWrap.Register(L); TransformWrap.Register(L); TweenAlphaWrap.Register(L); TweenPositionWrap.Register(L); TweenScaleWrap.Register(L); TypeWrap.Register(L); UIBasicSpriteWrap.Register(L); UIButtonColorWrap.Register(L); UIButtonWrap.Register(L); UICameraWrap.Register(L); UIEventManagerWrap.Register(L); UILabelWrap.Register(L); UIPanelWrap.Register(L); UIProgressBarWrap.Register(L); UIRectWrap.Register(L); UISliderWrap.Register(L); UISpriteWrap.Register(L); UITextureWrap.Register(L); UITweenerWrap.Register(L); UIWidgetContainerWrap.Register(L); Vector2Wrap.Register(L); Vector3Wrap.Register(L); UIWidgetWrap.Register(L); DirectoryWrap.Register(L); FileWrap.Register(L); yieldWrap.Register(L); }
private void SetPdfAParameters(IList <string> parameters) { var shortenedTempPath = PathHelper.GetShortPathName(Job.JobTempFolder); switch (Job.Profile.OutputFormat) { case OutputFormat.PdfA1B: parameters.Add("-dPDFA=1"); break; case OutputFormat.PdfA2B: parameters.Add("-dPDFA=2"); break; case OutputFormat.PdfA3B: parameters.Add("-dPDFA=3"); break; } //parameters.Add("-dNOOUTERSAVE"); //Set in pdf-A example, but is not documented in the distiller parameters Logger.Debug("Shortened Temppath from\r\n\"" + Job.JobTempFolder + "\"\r\nto\r\n\"" + shortenedTempPath + "\""); //Add ICC profile var iccFile = PathSafe.Combine(shortenedTempPath, "profile.icc"); //Set ICC Profile according to the color model switch (Job.Profile.PdfSettings.ColorModel) { case ColorModel.Cmyk: FileWrap.WriteAllBytes(iccFile, Resources.WebCoatedFOGRA28); break; case ColorModel.Gray: FileWrap.WriteAllBytes(iccFile, Resources.ISOcoated_v2_grey1c_bas); break; default: case ColorModel.Rgb: FileWrap.WriteAllBytes(iccFile, Resources.eciRGB_v2); break; } parameters.Add("-sPDFACompatibilityPolicy=1"); parameters.Add("-sOutputICCProfile=\"" + iccFile + "\""); var defFile = PathSafe.Combine(Job.JobTempFolder, "pdfa_def.ps"); var sb = new StringBuilder(Resources.PdfaDefinition); sb.Replace("[ICC_PROFILE]", "(" + EncodeGhostscriptParametersOctal(iccFile.Replace('\\', '/')) + ")"); FileWrap.WriteAllText(defFile, sb.ToString()); parameters.Add(defFile); }
protected void notifyFileListDownloaded(FileWrap listFile) { // 列表文件下载完毕,解析列表 setState(UPGRADE_STATE.US_PARSING_REMOTE_FILE_LIST); string listContent = BinaryUtility.bytesToString(listFile.getFileData()); parseRemoteFileList(listContent); setState(UPGRADE_STATE.US_GENERATE_LOCAL_FILE); // 检查本地文件 getLocalFileList(); // 如果在检查本地文件过程中取消了,则直接返回 if (mCancel) { setState(UPGRADE_STATE.US_NONE); return; } // 判断出需要更新的文件 setState(UPGRADE_STATE.US_GENERATE_MODIFIED_FILE); // 然后下载修改过和新增的文件 mModifiedList = generateModifiedFile(mRemoteFileList, mLocalFileList, mIgnorePathList); setState(UPGRADE_STATE.US_DOWNLOADING_REMOTE_FILE); if (mModifiedList.Count() == 0) { // 如果有临时目录,则将临时目录中的所有文件替换到游戏目录 notifyAllDownloaded(); mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_NOTHING_UPDATE); done(); } else { // 计算所有需要下载的文件的大小 mTotalSize = 0.0f; foreach (var item in mModifiedList) { mTotalSize = mTotalSize + item.Value.mFileSize; } // 开始下载所有文件,并且开始计时 mCurTimeCount = 0.0f; foreach (var item in mModifiedList) { // 如果临时文件存在,表示之前没下载成功,暂时删除临时文件 // 如果实现断点续传时需要获取临时文件的大小 long offset = 0; if (FileUtility.isFileExist(CommonDefine.TEMP_PATH + item.Key + CommonDefine.TEMP_FILE_EXTENSION)) { offset = FileUtility.getFileSize(CommonDefine.TEMP_PATH + item.Key + CommonDefine.TEMP_FILE_EXTENSION); } repuestDownload(item.Key, offset); } } }
void watcher_Created(object sender, FileSystemEventArgs e) { FileInfo fi = new FileInfo(e.FullPath); FileWrap fw = new FileWrap(fi); lock (imgFiles) { imgFiles.Add(fw); imgFiles.Sort(); } fw.WaitLoaded(); if (config.UpdateFrequency == 0) { LoadLastImageAnddeleteUnused(); } }
void watcher_Deleted(object sender, FileSystemEventArgs e) { FileWrap fw = null; lock (imgFiles) { foreach (var f in imgFiles) { if (f.FileInfo.FullName.Equals(e.FullPath)) { fw = f; break; } } imgFiles.Remove(fw); } }
private void SetPdfXParameters(IList <string> parameters) { var shortenedTempPath = PathHelper.GetShortPathName(Job.JobTempFolder); parameters.Add("-dPDFX"); Logger.Debug("Shortened Temppath from\r\n\"" + Job.JobTempFolder + "\"\r\nto\r\n\"" + shortenedTempPath + "\""); //Add ICC profile string iccFile = PathSafe.Combine(shortenedTempPath, "profile.icc"); FileWrap.WriteAllBytes(iccFile, CoreResources.ISOcoated_v2_300_eci); parameters.Add("-sOutputICCProfile=\"" + iccFile + "\""); //parameters.Add("-dNOOUTERSAVE"); //Set in pdf-X example, but is not documented in the distiller parameters string defFile = PathSafe.Combine(shortenedTempPath, "pdfx_def.ps"); var sb = new StringBuilder(CoreResources.PdfxDefinition); sb.Replace("%/ICCProfile (ISO Coated sb.icc)", "/ICCProfile (" + EncodeGhostscriptParametersOctal(iccFile.Replace('\\', '/')) + ")"); FileWrap.WriteAllText(defFile, sb.ToString()); parameters.Add(defFile); }
public DownloadManager(string name) : base(name) { mDownloadingFileList = new Dictionary <string, FileWrap>(); mDownloadedList = new Dictionary <string, FileWrap>(); mRemoteFileList = new Dictionary <string, DownloadFileInfo>(); mLocalFileList = new Dictionary <string, DownloadFileInfo>(); mModifiedList = new Dictionary <string, DownloadFileInfo>(); mIgnorePathList = new List <string>(); mCurDownloading = null; mCancel = false; mState = UPGRADE_STATE.US_NONE; mIgnorePathList.Add("dndl_Data/StreamingAssets/CustomSound/RaceSound"); mCurTimeCount = -1.0f; mCurSpeed = 0.0f; mSpeedInSecond = 0.0f; mTotalSize = 0.0f; mDownloadedSize = 0; mRemainTime = 0.0f; mDownloadTimeOut = 120.0f; mLastDownloadingTime = -1.0f; }
protected void notifyVersionDownloaded(FileWrap versionFile) { // 版本文件下载完毕后,提示是否有新版本可以更新 string localUpdateInfo = ""; string localVersion = getVersionFromFile(FileUtility.openTxtFile(CommonDefine.VERSION), ref localUpdateInfo); string remoteUpdateInfo = ""; string remoteVersion = getVersionFromFile(BinaryUtility.bytesToString(versionFile.getFileData()), ref remoteUpdateInfo); bool hasNewVersion = remoteVersion != localVersion; if (hasNewVersion) { setState(UPGRADE_STATE.US_WAIT_FOR_UPGRADE); } else { done(); } List <string> paramList = new List <string>(); paramList.Add(StringUtility.boolToString(hasNewVersion)); paramList.Add(remoteUpdateInfo); mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_NEW_VERSION, paramList); }
void LoadLastImageAnddeleteUnused() { FileWrap fw = GetLastLoaded(); if (fw != null && fw != currentImageFile) { currentImageFile = fw; lock (imgFiles) { try { LoadImage(fw.FileInfo); } catch (Exception e) { MessageBox.Show("Cannot load file: " + e.ToString()); } } try { GC.Collect(); } catch { MessageBox.Show("GC Error"); } } try { DeleteUnusedImages(); } catch { MessageBox.Show("delete Images Error"); } }
/// <summary> /// Checks for the existence of the given file. /// </summary> /// <param name="filePath">The path to check</param> public bool FileExists(string filePath) { FileWrap file = new FileWrap(); return(file.Exists(filePath)); }
protected void onFinish(string fileName, bool downloadSuccess) { if (!mDownloadingFileList.ContainsKey(fileName)) { return; } // 如果没有下载成功,则不再继续执行后续更新逻辑 if (!downloadSuccess) { setState(UPGRADE_STATE.US_NONE); return; } mLastDownloadingTime = -1.0f; FileWrap file = mDownloadingFileList[fileName]; if (fileName == CommonDefine.VERSION) { notifyVersionDownloaded(file); } else if (fileName == CommonDefine.FILELIST) { notifyFileListDownloaded(file); } else { string md5 = ""; if (mRemoteFileList.ContainsKey(file.getFileName())) { md5 = mRemoteFileList[file.getFileName()].mMD5; } // 如果失败,则不再继续更新 int ret = file.finishWrite(md5); if (ret != 0) { if (ret == 1) { logError("文件下载失败," + fileName + "文件校验失败, 可能是上次未更新完成且长时间没有更新,请重新更新", true); } else if (ret == 2) { logError("文件下载失败,文件可能被占用 : " + fileName, true); } setState(UPGRADE_STATE.US_NONE); pushDelayCommand <CommandDownloadManagerCancel>(mDownloadManager); } else { mDownloadedSize += file.getTotalSize(); // 加入下载完成的列表 mDownloadedList.Add(fileName, file); mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_FINISH_DOWNLOAD, file.getFileName()); // 全部文件都下载完毕,则版本更新完毕 if (mDownloadedList.Count() == mModifiedList.Count()) { notifyAllDownloaded(); // 更新完成 mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_UPDATE_DONE); // 更新版本号 done(); } } } }