upgrade
This commit is contained in:
91
Assets/trCRM/Scripts/call/RecordManager.cs
Normal file
91
Assets/trCRM/Scripts/call/RecordManager.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
using UnityEngine;
|
||||
using System.Collections;
|
||||
using Coolape;
|
||||
using System.Net;
|
||||
using System.IO;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
public class RecordManager : CLBehaviour4Lua
|
||||
{
|
||||
public static RecordManager self;
|
||||
//public static string currentRecord;
|
||||
//public string host = "";
|
||||
//public string user = "";
|
||||
//public string password = "";
|
||||
//public string remotePath = "";
|
||||
public string url = "";
|
||||
public static Hashtable ftpMap = new Hashtable();
|
||||
|
||||
public RecordManager()
|
||||
{
|
||||
self = this;
|
||||
}
|
||||
|
||||
public void upload(string soundPath, string sectionName, object finishCallback)
|
||||
{
|
||||
//this.finishCallback = finishCallback;
|
||||
object[] paras = new object[] { soundPath, finishCallback };
|
||||
//ThreadEx.exec(doUpload, paras);
|
||||
string fileName = Path.GetFileName(soundPath);
|
||||
byte[] bytes = FileEx.ReadAllBytes(soundPath);
|
||||
UnityWebRequest www = WWWEx.uploadFile(url, sectionName, fileName, bytes, CLAssetType.text, (Callback)onUploadFile, (Callback)onUploadFile, paras, false);
|
||||
ftpMap[soundPath] = www;
|
||||
}
|
||||
|
||||
//public void doUpload(object paras)
|
||||
//{
|
||||
// object[] objs = (object[])paras;
|
||||
// string soundFile = objs[0].ToString();
|
||||
// object callback = objs[1];
|
||||
// //FTP ftp = new FTP (host, user, password);
|
||||
// Debug.LogError(host+"===="+ user+"===="+ password);
|
||||
// RenciSFTPHelper ftp = new RenciSFTPHelper(host, user, password);
|
||||
// Debug.LogError("1111111");
|
||||
// if(! ftp.connect())
|
||||
// {
|
||||
// Debug.LogError("connect failed!!!" + host + "====" + user + "====" + password);
|
||||
// onUploadFile(false, 0, soundFile);
|
||||
// return;
|
||||
// }
|
||||
// Debug.LogError("222222222");
|
||||
// ftpMap[Path.GetFileName(soundFile)] = ftp;
|
||||
// //bool ret = ftp.Upload (soundPath, remotePath);
|
||||
// string remoteFile = Path.Combine(remotePath, Path.GetFileName(soundFile));
|
||||
// bool ret = ftp.put(soundFile, remoteFile, (Callback)onUploadFile);
|
||||
//}
|
||||
|
||||
public void onUploadFile(params object[] objs)
|
||||
{
|
||||
string content = objs[0] as string;
|
||||
object[] orgs = objs[1] as object[];
|
||||
string soundPath = orgs[0] as string;
|
||||
object callback = orgs[1];
|
||||
Utl.doCallback(callback, content, soundPath);
|
||||
ftpMap.Remove(soundPath);
|
||||
}
|
||||
|
||||
public float progress(string soudPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(soudPath))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
UnityWebRequest request = ftpMap[soudPath] as UnityWebRequest;
|
||||
if (request != null)
|
||||
{
|
||||
return request.uploadProgress; //ftp;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public void abort(string soundPath)
|
||||
{
|
||||
UnityWebRequest request = ftpMap[soundPath] as UnityWebRequest;
|
||||
if (request != null)
|
||||
{
|
||||
request.Dispose();
|
||||
request = null;
|
||||
ftpMap.Remove(soundPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user