/// <summary> /// /// </summary> /// <param name="_url">Target URL</param> /// <param name="_localPath">Path to Local File</param> /// <param name="_resultAct">First int is Local File Size; Second int tells Remote File Size</param> /// <returns></returns> public IEnumerator DownloadBehaviourCheck(FileURL _fileUrl, Action <UnityWebRequestHelper.DownloadProcess, int, int> _resultAct) { int localFileSize = myFileIOHelper.CheckFileSize(_fileUrl.localPath); bool processed = false; bool supportPartialDL = false; int remoteFileSize = -1; StartCoroutine(myUnityWebRequestHelper.CheckFileSize(_fileUrl.fullURL, (int _val, bool _supportPartialDL) => { remoteFileSize = _val; supportPartialDL = _supportPartialDL; processed = true; } )); while (!processed) { yield return(null); } //check remote server support if (!supportPartialDL) { //not support partial download Debug.Log("Remote Server Not Support Partial Download"); _resultAct(UnityWebRequestHelper.DownloadProcess.RedownloadFromBeginning, localFileSize, remoteFileSize); yield break; } _resultAct(DownloadBehaviourCheck(localFileSize, remoteFileSize), localFileSize, remoteFileSize); }
public void TestMethodAppendTo() { FileIOHelper fileIOHelper = new FileIOHelper(); byte[] bytess = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; string filepath = @"d:\123.546"; int fileSize = fileIOHelper.CheckFileSize(filepath); fileIOHelper.AppendTo(filepath, bytess); Console.WriteLine("Append to d:\\123.546 from " + fileSize); Assert.AreEqual <int>(fileSize + 7, fileIOHelper.CheckFileSize(filepath)); System.IO.Stream st = new System.IO.MemoryStream(new byte[] { 5, 4, 3, 2, 1 }); fileSize = fileIOHelper.CheckFileSize(filepath); fileIOHelper.AppendTo(filepath, st); Console.WriteLine("Append to d:\\123.546"); Assert.AreEqual <int>(fileSize + 5, fileIOHelper.CheckFileSize(filepath)); }
public void TestMethodCheckLocalFileSize() { FileIOHelper fileIOHelper = new FileIOHelper(); string path = "d:\\.testfile"; int afile = fileIOHelper.CheckFileSize(path); Console.WriteLine(afile);//not exist Assert.AreEqual <int>(-1, afile); fileIOHelper.Touch(path); afile = fileIOHelper.CheckFileSize(path); Console.WriteLine();//exist Assert.AreEqual <int>(0, afile); fileIOHelper.Remove(path); path = @"d:\123.546"; int nonExistFile = fileIOHelper.CheckFileSize(path); Console.WriteLine(nonExistFile);//File not exist Assert.AreEqual <int>(-1, nonExistFile); }