/// <summary>
        /// 通过ftp上传字节数据到服务器
        /// </summary>
        /// <param name="data">字节数据</param>
        /// <param name="fileName">存储到服务器的文件名,带后缀</param>
        /// <param name="callBack">完成回调函数</param>
        /// <param name="progress">进度改变回调函数</param>
        public void UploadData(byte[] data, string fileName, WillFtpUploadCallBack callBack, WillFtpUploadProgressChangedEvent proEvent = null)
        {
            if (string.IsNullOrEmpty(m_FTPHost) || string.IsNullOrEmpty(m_FTPUserName))
            {
                WDebuger.LogError("未进行初始化,请检查!");
                return;
            }
            if (string.IsNullOrEmpty(fileName))
            {
                WDebuger.LogError("存储文件名不能为空,请检查! 参数:" + fileName);
            }
            m_FTPUploadCallBack   = callBack;
            m_UploadProgressEvent = proEvent;
            m_UploadDataByteCount = data.Length;
            m_Progreess           = 0;
            m_WebClient           = new WebClient();
            m_WebClient.Encoding  = Encoding.UTF8;
            Uri uri = new Uri(m_FTPHost + fileName);

            m_WebClient.UploadDataCompleted   += new UploadDataCompletedEventHandler(OnDataUploadCompleted);
            m_WebClient.UploadProgressChanged += new UploadProgressChangedEventHandler(OnDataUploadProgressChanged);
            m_WebClient.Credentials            = new NetworkCredential(m_FTPUserName, m_FTPPasswork);

            m_WebClient.UploadDataAsync(uri, "STOR", data);
        }
 /// <summary>
 /// 单个文件上传完成回调
 /// </summary>
 /// <param name="over"></param>
 /// <param name="msg"></param>
 private static void UpVideoCallBack(bool over, string msg)
 {
     if (over == false)
     {
         m_ReturnoMsg = "failure";
         WDebuger.LogError("文件上传失败,请检查! 消息:" + msg);
         //EditorUtility.ClearProgressBar();
         //if (ChinarMessage.ShowRetryCancel("文件上传失败,请检查! 消息:" + msg, "警告"))
         UpToServer();
         return;
     }
     WDebuger.Log("文件上传成功!文件名:" + m_ResFileName[m_ItemResFilePath[0]]);
     m_ReturnoMsg = "over";
     m_ResServerPath.Add(m_ResFileName[m_ItemResFilePath[0]], msg);
     m_ItemResFilePath.RemoveAt(0);
     if (m_ItemResFilePath.Count <= 0)
     {
         m_UploadConfig = true;
         return;
     }
     try
     {
         string itemResPath      = m_ItemResFilePath[0];
         string itemResCloudName = m_ResFileName[m_ItemResFilePath[0]];
         WillAliyunUpload.Instance.UploadData(itemResPath, ConstData.companyname, ConstData.projectname + "/" + itemResCloudName, UpVideoCallBack, UploadProgressChangedEvent);
     }
     catch (Exception e)
     {
         WDebuger.LogError("文件上传失败,请检查! 消息:" + e.Message);
         //EditorUtility.ClearProgressBar();
         //if (ChinarMessage.ShowRetryCancel("文件上传失败,请检查! 消息:" + msg, "警告"))
         UpToServer();
         throw;
     }
 }
 protected virtual void Awake()
 {
     if (instance == null)
     {
         instance = (T)this;
     }
     else
     {
         WDebuger.LogError("Gat a second instance of this calss" + this.GetType());
     }
 }
 private void DownloadCallBack(bool downloadOver, string downloadMsg, object[] parameters)
 {
     if (downloadOver == true)
     {
         InitGameStart();
     }
     else
     {
         WDebuger.LogError("资源下载失败!");
     }
 }
 /// <summary>
 /// 初始化ftp上传
 /// </summary>
 /// <param name="ftpHost">ftp地址</param>
 /// <param name="ftpUserName">ftp密码,默认为匿名登录:anonymous</param>
 /// <param name="ftpPasswork">ftp密码,默认为匿名登录的空密码</param>
 public void Init(string ftpHost, string ftpUserName, string ftpPasswork)
 {
     if (string.IsNullOrEmpty(ftpHost))
     {
         WDebuger.LogError("ftp地址为空,请检查! 参数:" + ftpHost);
         return;
     }
     m_FTPHost     = ftpHost;
     m_FTPUserName = ftpUserName;
     m_FTPPasswork = ftpPasswork;
 }
 /// <summary>
 /// 错误消息处理
 /// </summary>
 /// <param name="errorMsg">错误消息</param>
 protected virtual void ErrorMessage(string errorMsg)
 {
     Progress    = 1;
     HttpMessage = errorMsg;
     HttpData    = null;
     if (m_CallBack != null)
     {
         m_CallBack(m_HttpUrl, false, errorMsg, HttpData, null, m_Parameters);
     }
     WDebuger.LogError(HttpMessage);
 }
        private IEnumerator GetToSave()
        {
            float waitTime   = 0;
            int   waitCount  = 0;
            bool  isContinue = true;

            while (true)
            {
                try
                {
                    m_WWW = new WWW(m_HttpUrl);
                }
                catch (Exception e)
                {
                    WDebuger.LogError(e.Message);
                }
                if (m_IsCanNext == true)
                {
                    while (m_WWW.isDone == false)
                    {
                        Progress = m_WWW.progress;
                        yield return(new WaitForEndOfFrame());

                        waitTime += Time.deltaTime;
                        if (m_WaitTime <= waitTime)
                        {
                            waitCount++;
                            if (waitCount >= m_WaitCount)
                            {
                                ErrorMessage("Error: 网络连接失败,请检查! 参数:" + m_HttpUrl);
                                isContinue = false;
                            }
                            waitTime = 0;
                            break;
                        }
                    }
                    if (isContinue == true && m_WWW.isDone == true)
                    {
                        SetMessage();
                        break;
                    }
                    else if (m_WWW.error != null)
                    {
                        ErrorMessage(m_WWW.error);
                        break;
                    }
                    else if (isContinue == false)
                    {
                        Progress = 1;
                        break;
                    }
                }
            }
        }
 /// <summary>
 /// 单个下载回调
 /// 会继续执行后面的下载
 /// 加载完成会调用回调
 /// </summary>
 /// <param name="ftpHost"></param>
 /// <param name="downloadSucceed"></param>
 /// <param name="callBackMessage"></param>
 /// <param name="downloadData"></param>
 /// <param name="e"></param>
 private void DownloadFileCallBack(string ftpHost, bool downloadSucceed, string callBackMessage, byte[] downloadData, DownloadDataCompletedEventArgs e)
 {
     if (downloadSucceed == false)
     {
         WDebuger.LogError("下载失败,请检查网络!");
         m_CallBack(false, "下载失败,请检查网络!", m_Parameters);
         m_CanChack = true;
         return;
     }
     WDebuger.Log("文件下载成功!:[" + ftpHost + "]");
     m_Coroutine = m_CoroutinesMono.StartCoroutine(SaveFile(downloadData));
 }
 /// <summary>
 /// 检查更新回调
 /// </summary>
 /// <param name="overOrFailed"></param>
 /// <param name="message"></param>
 /// <param name="parameters"></param>
 private void UpdataResCallBack(bool overOrFailed, string message, object[] parameters = null)
 {
     WDebuger.Log(message);
     if (overOrFailed == true)
     {
         m_CallBack(true, "下载完成", m_Parameters);
         Destroy(gameObject);
     }
     else
     {
         m_CallBack(false, message, m_Parameters);
         WDebuger.LogError("错误");
     }
 }
 /// <summary>
 /// 通过ftp上传文件到服务器
 /// </summary>
 /// <param name="filePath">文件路径</param>
 /// <param name="fileName">存储到服务器的文件名,带后缀</param>
 /// <param name="callBack">完成回调函数</param>
 /// <param name="progress">进度改变回调函数</param>
 public void UploadData(string filePath, string fileName, WillFtpUploadCallBack callBack, WillFtpUploadProgressChangedEvent proEvent = null)
 {
     if (string.IsNullOrEmpty(filePath))
     {
         WDebuger.LogError("文件地址为空,请检查! 参数:" + filePath);
         return;
     }
     if (!File.Exists(filePath))
     {
         WDebuger.LogError("找不到文件,请检查! 参数" + filePath);
         return;
     }
     byte[] data = File.ReadAllBytes(filePath);
     UploadData(data, fileName, callBack, proEvent);
 }
    public static void UpToServer()
    {
        m_ResFilePath.Clear();
        m_ItemResFilePath.Clear();
        m_ResFileName.Clear();
        m_ResServerPath.Clear();
        m_UploadConfig  = false;
        m_AllUploadOver = false;
        m_NowUpCount    = 0;
        //m_ResPath = Application.dataPath + ConstData.ABNEWPAT;
        m_ResPath = Application.persistentDataPath + "/" + ConstData.WorldMapUrl;
        GetWorldMap();
        DirectoryInfo dir = new DirectoryInfo(m_ResPath);

        FileInfo[] info = dir.GetFiles();
        print(info.Length);
        for (int i = 0; i < info.Length; i++)
        {
            print("This file : " + i);
            if (info[i].Name.Contains(".json"))
            {
                m_ConfigPath     = info[i].FullName;
                m_ConfigFileName = info[i].Name;
            }
            m_ResFilePath.Add(info[i].FullName);
            m_ItemResFilePath.Add(info[i].FullName);
            m_ResFileName.Add(info[i].FullName, info[i].Name);
        }
        WillAliyunUpload.Instance.InitAliyun(ConstData.OSSpath, ConstData.OSSkey, ConstData.OSSpassword);
        try
        {
            print("m_ItemResFilePath : " + m_ItemResFilePath.Count);
            print("m_ResFileName : " + m_ResFileName.Count);
            string itemResPath      = m_ItemResFilePath[0];
            string itemResCloudName = m_ResFileName[m_ItemResFilePath[0]];
            WillAliyunUpload.Instance.UploadData(itemResPath, ConstData.companyname, ConstData.projectname + "/" + itemResCloudName, UpVideoCallBack, UploadProgressChangedEvent);
        }
        catch (Exception e)
        {
            WDebuger.LogError(e.Message);
            throw;
        }
    }
        /// <summary>
        /// 检查资源更新
        /// </summary>
        /// <param name="mono"></param>
        /// <param name="callBack"></param>
        /// <param name="parameters"></param>
        public void UpdataRes(LoadCloudResCallBack callBack, object[] parameters)
        {
            //if (!ResourceManager.Instance.m_LoadFormAssetBundle)
            //{
            //    callBack(true, "Test", parameters);
            //    return;
            //}
            if (m_CanChack == true)
            {
                m_CanChack = false;
                m_CallBack = callBack;
                if (m_CoroutinesMono == null)
                {
                    m_CallBack(false, "", parameters);
                    m_CanChack = true;
                    WDebuger.LogError("未初始化管理器,请检查!");
                    return;
                }
                m_Parameters = parameters;
                m_DownLoadFileName.Clear();
                m_DownLoadFileNameItem.Clear();
                m_DownLoadFileList.Clear();
                string configPath = m_SavePath + ConstData.WLOCALCONFIG;
                if (!File.Exists(configPath))
                {
                    worldMapData.version = "1.0";
                    worldMapData.date    = System.DateTime.Now.ToString();
                    if (!Directory.Exists(m_SavePath))
                    {
                        Directory.CreateDirectory(m_SavePath);
                    }
                    m_DownLoadFileName.Add("WorldMap.json");
                    m_DownLoadFileNameItem.Add("WorldMap.json");
                    worldMapData.SaveJson(configPath);
                }
                worldMapData = WillData.LoadJson <WorldMapData>(configPath);

                WillFTPDownloadManager.Instance.Init(ConstData.FTPname, ConstData.FTPPassword);
                WillFTPDownloadManager.Instance.DownLoadData(ConstData.DownloadServerFtp + "WorldMap.json", DowlLoadConfigCallBack);
            }
        }
        /// <summary>
        /// 下载配置文件回调
        /// 处理下载后文件对比
        /// </summary>
        /// <param name="ftpHost"></param>
        /// <param name="downloadSucceed"></param>
        /// <param name="callBackMessage"></param>
        /// <param name="downloadData"></param>
        /// <param name="e"></param>
        private void DowlLoadConfigCallBack(string ftpHost, bool downloadSucceed, string callBackMessage, byte[] downloadData, DownloadDataCompletedEventArgs e)
        {
            Debug.Log(Application.persistentDataPath);
            if (downloadSucceed == false)
            {
                WDebuger.LogError("下载文件失败,请检查网络!");
                m_CallBack(true, "下载文件失败,请检查网络!", m_Parameters);
                m_CanChack = true;
                return;
            }
            if (downloadData == null)
            {
                WDebuger.LogError("下载文件失败,下载内容为空,请检查网络!");
                m_CallBack(true, "下载文件失败,下载内容为空,请检查网络!", m_Parameters);
                m_CanChack = true;
                return;
            }

            Debug.Log("Data : " + Encoding.Default.GetString(downloadData));
            s_worldMapData = JsonMapper.ToObject <WorldMapData>(Encoding.Default.GetString(downloadData));

            ContrastConfig();
            Debug.Log("配置表下载成功!");
        }
Esempio n. 14
0
 /// <summary>
 /// 预制体的加载
 /// </summary>
 public virtual void OnStartScene()
 {
     //这里编写需要加载的场景
     WDebuger.LogError("scene manger please override OnStartScene method!");
 }
Esempio n. 15
0
 public virtual void SetScenename()
 {
     SceneName = "";
     WDebuger.LogError("SceneName need Set!");
 }