private void _onAdded(String content) { JsonObject json2 = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(content); string name = (string)json2 [NAME_KEY]; int minIndex = (int)json2 [MIN_INDEX_KEY]; int maxIndex = (int)json2 [MAX_INDEX_KEY]; string comicName = (string)json2 [COMIC_NAME_KEY]; for (int i = minIndex; i < (maxIndex + 1); i++) { JsonObject json = new JsonObject(); json [NAME_KEY] = name; json [INDEX_KEY] = i; json [COMIC_NAME_KEY] = comicName; _jsonArr.Add(json); DownLoadInfo info = new DownLoadInfo(); info.name = name; info.index = i; info.comicName = comicName; info.json = json; json [IS_JPG_KEY] = info.isJpg; _downloadInfos.Add(info); _log("add " + name + " " + i); } save(); }
private void _removeDownload(String content) { // _log ("_removeDownload " + content); string[] info = content.Split(new char[] { '|' }); string name = info [0]; int index = Int32.Parse(info [1]); DownLoadInfo dInfo = null; for (int i = 0; i < _downloadInfos.Count; i++) { DownLoadInfo curInfo = _downloadInfos [i]; // _log (curInfo.name); // _log (name); // _log (curInfo.index + ""); // _log (index + ""); if (curInfo.name == name && curInfo.index == index) { _log("find " + content); dInfo = curInfo; break; } } if (dInfo == null) { _log("not find " + content); return; } _log("_removeDownload " + content); _jsonArr.Remove(dInfo.json); _downloadInfos.Remove(dInfo); save(); }
private void load() { ArrayList stringList = SolaFile.LoadAppFile(SAVE_FILE_NAME); if (stringList == null) { _log("No data."); _jsonArr = new JsonArray(); _json [LIST_KEY] = _jsonArr; } else { string data = (string)stringList [0]; _json = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(data); _jsonArr = (JsonArray)_json [LIST_KEY]; JsonArray ja = _jsonArr; for (int i = 0; i < ja.Count; i++) { JsonObject json = (JsonObject)ja [i]; DownLoadInfo info = new DownLoadInfo(); info.name = (string)json [NAME_KEY]; info.index = (int)json [INDEX_KEY]; info.isJpg = (bool)json [IS_JPG_KEY]; info.comicName = (string)json [COMIC_NAME_KEY]; info.json = json; _downloadInfos.Add(info); _javaObj.Call("addDownLoad", json.ToString()); } _log("Loaded."); } }
/// <summary> /// Main函数 /// </summary> /// <param name="args"></param> static void Main(string[] args) { Console.WriteLine("Hello World!"); DownLoadInfo dli = new DownLoadInfo(); for (int i = 0; i < args.Length; i += 2) { switch (args[i]) { case "-h": case "-help": UserHelperPage(); break; case "-u": case "-url": dli.DownLoadUrl.Add(args[i + 1]); break; case "-p": case "-path": dli.DownLoadPath = args[i + 1]; break; default: break; } } //执行下载动作 DownLoad.DownLoadFile(dli); }
IEnumerator LoadImg() { if (_downloadInfos.Count == 0) { yield return(new WaitForSeconds(1f)); StartCoroutine(LoadImg()); yield break; } DownLoadInfo info = _downloadInfos [_downloadInfos.Count - 1]; int index = info.index; string suffix = ".jpg"; if (!info.isJpg) { suffix = ".png"; } string url = "http://i.nhentai.net/galleries/" + info.name + "/" + index + suffix; _log("开始下载" + url); _www = new WWW(url); yield return(_www); if (_www.error != null) { if (info.isJpg == false) { _log("download failure " + url); _jsonArr.Remove(info.json); _downloadInfos.Remove(info); save(); } else { info.json [IS_JPG_KEY] = false; info.isJpg = false; save(); } } else { writeFile(info, index); } StartCoroutine(LoadImg()); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; Cultural.BLL.Department departBll = new Cultural.BLL.Department(); context.Response.ContentType = "text/plain"; string paraFID = context.Request["FID"]; //读取参数PageSize if (paraFID != null && paraFID.Trim() == "DL") //列表界面 { int paraIndex = context.Request["Index"] == null ? 1 : int.Parse(context.Request["Index"]); //读取参数PageSize int paraSize = context.Request["PageSize"] == null ? 10 : int.Parse(context.Request["PageSize"]); //读取参数PageSize string paraBoardID = context.Request["BoardID"] == null ? "0" : context.Request["BoardID"].ToString(); //读取参数 DepartInfo departInfo = new DepartInfo(); departInfo.DepartList = departBll.DataTableToList(departBll.GetListByPage(string.Format(" BoardID={0} and Status!='0' ", paraBoardID), " Weight desc,DepartID asc ", (paraIndex - 1) * paraSize, paraIndex * paraSize).Tables[0]); departInfo.TotalNum = departBll.GetRecordCount(string.Format(" BoardID={0} and Status!='0' ", paraBoardID)); context.Response.Write(JsonHelper.Serialize(departInfo)); } if (paraFID != null && paraFID.Trim() == "DownL") //列表界面 { int paraIndex = context.Request["Index"] == null ? 1 : int.Parse(context.Request["Index"]); //读取参数PageSize int paraSize = context.Request["PageSize"] == null ? 10 : int.Parse(context.Request["PageSize"]); //读取参数PageSize string paraBoardID = context.Request["BoardID"] == null ? "0" : context.Request["BoardID"].ToString(); //读取参数 DownLoadInfo downLoadInfo = new DownLoadInfo(); Cultural.BLL.DownCenter dcBll = new Cultural.BLL.DownCenter(); downLoadInfo.DownCenterList = dcBll.DataTableToList(dcBll.GetListByPage(string.Format(" BoardID={0} and Status!='0' ", paraBoardID), " PubTime desc ", (paraIndex - 1) * paraSize, paraIndex * paraSize).Tables[0]); foreach (Cultural.Model.DownCenter dc in downLoadInfo.DownCenterList) { dc.PubTime = dc.PubTime.Substring(0, 10); } downLoadInfo.TotalNum = dcBll.GetRecordCount(string.Format(" BoardID={0} and Status!='0' ", paraBoardID)); context.Response.Write(JsonHelper.Serialize(downLoadInfo)); } if (paraFID != null && paraFID.Trim() == "DownD") //详细界面 { int paraIndex = context.Request["InfoID"] == null ? 0 : int.Parse(context.Request["InfoID"]); //读取参数InfoID Cultural.Model.DownCenter downLoad = new Cultural.Model.DownCenter(); Cultural.BLL.DownCenter dcBll = new Cultural.BLL.DownCenter(); downLoad = dcBll.GetModel(paraIndex); DownLoadInfo downLoadInfo = new DownLoadInfo(); downLoadInfo.DownCenterList = new List <Cultural.Model.DownCenter>(); downLoadInfo.DownCenterList.Add(downLoad); Cultural.BLL.Board boardBll = new Cultural.BLL.Board(); Cultural.Model.Board board = new Cultural.Model.Board(); board = boardBll.GetModel(int.Parse(downLoad.BoardID.ToString())); downLoadInfo.BName = board.BoardName; context.Response.Write(JsonHelper.Serialize(downLoadInfo)); } }
private readonly Queue <DownLoadInfo> m_needDownLoadRes = new Queue <DownLoadInfo>(); // 需要下载的资源 // 下载文件 public async void DownLoadResFile(DownLoadInfo downLoadInfo) { if (null != downLoadInfo) { if (m_workingDownLoadQue.Count < MaxDownLoadNum) { UnityWebRequest webRequest = m_stopDownLoadQue.Dequeue(); if (null == webRequest) { webRequest = new UnityWebRequest(downLoadInfo.Url) { timeout = 5 // 网络超时设置 }; } else { webRequest.url = downLoadInfo.Url; } using (webRequest.downloadHandler = new DownloadHandlerFile(downLoadInfo.SavePath) { removeFileOnAbort = true }) // 想缓存DownloadHandlerFile,但是缓存后没找到修改保存路径的方法 { await webRequest.SendWebRequest(); // 等待文件下载完成 if (webRequest.isDone && webRequest.isNetworkError) { DebugUtility.Instance.Error($"请求下载 {downLoadInfo.Url} 失败,失败原因为:{webRequest.error}"); } m_workingDownLoadQue.Remove(downLoadInfo.Url); m_stopDownLoadQue.Enqueue(webRequest); // 闲置下来的请求放入容器中重复使用 downLoadInfo.FinishAction?.Invoke(); if (m_needDownLoadRes.Count > 0) // 每次下载完检测一下是否有需要下载 { using (DownLoadInfo Info = m_needDownLoadRes.Dequeue()) { DownLoadResFile(Info); } } } } else { m_needDownLoadRes.Enqueue(downLoadInfo); } } }
public int DownLoad(string url, System.Action <byte[]> hdlOnSuccess, System.Action <string> hdlOnError, System.Action <ulong> hdlProcess = null) { Logger.LogInfo("DownLoad " + url); DownLoadInfo downloadInfo = CreateDownloadInfo(url, hdlOnSuccess, hdlOnError, hdlProcess); if (mCurDownLoadTaskList.Count > ConstConfig.MaxHttpTask) { mWaitTaskList.Add(downloadInfo); } else { HttpLoaderTask downloader = CreateDownloadTask(); mCurDownLoadTaskList.Add(downloader); downloader.BeginDownLoad(downloadInfo); } return(downloadInfo.taskId); }
// 修改本地资源文件 private async void ModifyLocalResFile(List <SingleResInfo> updateList, Action finishAction = null) { int count = updateList.Count; int finishCount = 0; for (int i = 0; i < count; i++) { stringBuilder.Clear(); if (updateList[i].Status == (byte)ResFileStatus.DELETE) // 删除的话只删除persistentDataPath目录下 { stringBuilder.Append(PathUtility.Instance.GetPersistentDataPath()); stringBuilder.Append(updateList[i].Path); if (File.Exists(stringBuilder.ToString())) { File.Delete(stringBuilder.ToString()); } } else // 新增、修改都是需要从服务器中下载文件 { stringBuilder.Append(PathUtility.Instance.GetResListFileUrl()); stringBuilder.Append(updateList[i].Path); } using (DownLoadInfo downLoadInfo = new DownLoadInfo { Url = stringBuilder.ToString(), SavePath = stringBuilder.ToString(), // TODO 下载后 保存文件的路径 FinishAction = () => { finishCount++; }, }) { DownLoadFileUtility.Instance.DownLoadResFile(downLoadInfo); } } while (finishCount != count) { await Task.Yield(); } finishAction?.Invoke(); string path = PathUtility.Instance.GetResVerFilePath(); // 资源文件全部更新完毕 更新一下标志位 File.WriteAllText(path, onlineVerStr + "|1"); DownLoadFileUtility.Instance.Clear(); // 资源文件全部下载完毕 清除一下相关的缓存 }
DownLoadInfo CreateDownloadInfo(string url, System.Action <byte[]> hdlOnSuccess, System.Action <string> hdlOnError, System.Action <ulong> hdlProcess) { DownLoadInfo ret = null; if (mCachedTaskInfoQueue.Count > 0) { ret = mCachedTaskInfoQueue.Dequeue(); } else { ret = new DownLoadInfo(); } ret.url = url; ret.hdlOnSuccess = hdlOnSuccess; ret.hdlOnError = hdlOnError; ret.hdlProcess = hdlProcess; ret.taskId = ++mCurMaxId; return(ret); }
void ReturnDownloadInfo(DownLoadInfo task) { mCachedTaskInfoQueue.Enqueue(task); }
private void writeFile(DownLoadInfo info, int index) { // _log ("写文件"); _texture2D = _www.texture; byte[] bytes; string fix; if (info.isJpg) { fix = ".jpg"; bytes = _texture2D.EncodeToJPG(); } else { fix = ".png"; bytes = _texture2D.EncodeToPNG(); } string dir = "c:\\comic\\" + info.comicName; if (Application.platform == RuntimePlatform.Android) { dir = SDCARD_PATH + info.comicName; } string indexStr = ""; if (index < 10) { indexStr = "00" + index; } else if (index < 100) { indexStr = "0" + index; } else { indexStr = "" + index; } string path = dir + Path.DirectorySeparatorChar + indexStr + fix; // _log ("路径" + path); if (Application.platform == RuntimePlatform.Android) { Directory.CreateDirectory(dir); } else { DirectoryInfo dirInfo = new DirectoryInfo(dir); dirInfo.Create(); } File.WriteAllBytes(path, bytes); _log(path + "完成下载"); _jsonArr.Remove(info.json); _downloadInfos.Remove(info); save(); Destroy(_texture2D); }
public void BeginDownLoad(DownLoadInfo taskInfo) { this.taskInfo = taskInfo; StartCoroutine(DownLoad()); }
public static void DownLoadFile(DownLoadInfo downLoadInfo) { var taskCount = 100; }