IEnumerator DownLoadCoroutine() { int lastDownloadBytes = 0; while (true) { if (_DownloadList.Count >= 1 && NetworkInterface.IsClient) { string isoName = _DownloadList[0]._isoName; if (0 == _CurDownload) { _CurDownload = _DownloadList[0].UGCHandle; DownloadUGC(); lastDownloadBytes = 0; } else { int downloadedBytes = 0; int totalBytes = 0; if (SteamRemoteStorage.GetUGCDownloadProgress(new UGCHandle_t(_CurDownload), out downloadedBytes, out totalBytes)) { if (0 != totalBytes && downloadedBytes != lastDownloadBytes) { int speed = downloadedBytes - lastDownloadBytes; lastDownloadBytes = downloadedBytes; speed /= 1024; RoomGui_N.UpdateDownLoadInfo(_DownloadList.Count, speed); RoomGui_N.SetMapInfo("Downloading " + isoName + "...[" + downloadedBytes * 100 / totalBytes + "%]"); } } else { // string skey = ""; foreach (KeyValuePair <string, FileSender> iter in _FileSenderMgr) { if (iter.Value.m_FileHandle == _CurDownload && iter.Value.m_FileSize > 0) { int speed = iter.Value.m_Sended - lastDownloadBytes; lastDownloadBytes = iter.Value.m_Sended; speed /= 1024; totalBytes = iter.Value.m_FileSize; RoomGui_N.UpdateDownLoadInfo(_DownloadList.Count, speed); RoomGui_N.SetMapInfo("Downloading " + isoName + "...[" + downloadedBytes * 100 / totalBytes + "%]"); break; } } } } } yield return(new WaitForSeconds(0.02f)); } }
public static void RPC_S2C_SendFile(uLink.BitStream stream, uLink.NetworkMessageInfo info) { byte [] data = stream.Read <byte[]> (); int count = stream.Read <int> (); string skey = stream.Read <string> (); if (data != null && count != 0) { if (_FileSenderMgr.ContainsKey(skey) && _FileSenderMgr[skey] != null) { bool bFinish = false; _FileSenderMgr[skey].WriteData(data, count, ref bFinish); if (bFinish) { RegisteredISO iso = _DownloadList.Find(iter => iter.UGCHandle == _FileSenderMgr[skey].m_FileHandle); if (iso != null) { string fielName = VCConfig.s_CreationNetCachePath + _FileSenderMgr[skey].m_FileName + VCConfig.s_CreationNetCacheFileExt; using (FileStream fs = new FileStream(fielName, FileMode.Create, FileAccess.Write, FileShare.Read)) { fs.Write(_FileSenderMgr[skey].m_Data, 0, (int)_FileSenderMgr[skey].m_FileSize); } _DownloadList.RemoveAll(iter => iter.UGCHandle == _FileSenderMgr[skey].m_FileHandle); Debug.Log(_DownloadList.Count().ToString() + "===========" + _FileSenderMgr[skey].m_FileName); _SteamItems[iso._hashCode] = _FileSenderMgr[skey].m_FileName; } NetworkManager.SyncServer(EPacketType.PT_Common_UGCDownloaded, _FileSenderMgr[skey].m_FileHandle); _CurDownload = 0; _FileSenderMgr.Remove(skey); if (_DownloadList.Count <= 0) { RoomGui_N.SetMapInfo("Download complete"); if (null != RoomGui_N.Instance && RoomGui_N.Instance.isShow) { RoomGui_N.Instance.ActiveStartBtn(); } } else { RoomGui_N.SetMapInfo("Downloading " + _FileSenderMgr[skey].m_FileName + "...[100%]"); } RoomGui_N.UpdateDownLoadInfo(_DownloadList.Count, 0); } else { NetworkManager.SyncServer(EPacketType.PT_Common_UGCUpload, skey, count, true); } } } }
internal static void DownloadUGC() { try { RegisteredISO iso = _DownloadList.Find(iter => iter.UGCHandle == _CurDownload); if (null == iso) { _DownloadList.RemoveAll(iter => iter.UGCHandle == _CurDownload); _CurDownload = 0; return; } if (!_SteamItems.ContainsKey(iso._hashCode)) { //if (_CurDownloadList.Contains(_CurDownload)) // return; UGCHandle_t handler; handler.m_UGCHandle = _CurDownload; SteamAPICall_t caller = SteamRemoteStorage.UGCDownload(handler, 0); //new CallResult<RemoteStorageDownloadUGCResult_t>(OnSteamUGCDownloadResult, caller); RemoteStorageDownloadPreUGCResult = CallResult <RemoteStorageDownloadUGCResult_t> .Create(OnSteamUGCDownloadResult); RemoteStorageDownloadPreUGCResult.Set(caller); RoomGui_N.SetMapInfo("Downloading " + iso._isoName + "...[0%]"); } else { _DownloadList.RemoveAll(iter => iter.UGCHandle == _CurDownload); NetworkManager.SyncServer(EPacketType.PT_Common_UGCDownloaded, _CurDownload); _CurDownload = 0; if (_DownloadList.Count <= 0) { RoomGui_N.SetMapInfo("Download complete"); if (null != RoomGui_N.Instance && RoomGui_N.Instance.isShow) { RoomGui_N.Instance.ActiveStartBtn(); } } else { RoomGui_N.SetMapInfo("Downloading " + iso._isoName + "...[100%]"); } } RoomGui_N.UpdateDownLoadInfo(_DownloadList.Count, 0); } catch (Exception e) { LogManager.Warning(e.Message); } }
public static void RPC_S2C_FileDontExists(uLink.BitStream stream, uLink.NetworkMessageInfo info) { ulong fileHandle = stream.Read <ulong> (); _DownloadList.RemoveAll(iter => iter.UGCHandle == fileHandle); _CurDownload = 0; if (_DownloadList.Count <= 0) { RoomGui_N.SetMapInfo("Download complete"); if (null != RoomGui_N.Instance && RoomGui_N.Instance.isShow) { RoomGui_N.Instance.ActiveStartBtn(); } } RoomGui_N.UpdateDownLoadInfo(_DownloadList.Count, 0); }
public static void RPC_S2C_DownTimeOut(uLink.BitStream stream, uLink.NetworkMessageInfo info) { /*ulong fileHandle = */ stream.Read <ulong> (); RoomGui_N.SetMapInfo("Download failed"); MessageBox_N.ShowYNBox(PELocalization.GetString(8000116), OnYesEvent, OnNoEvent); }
static void OnSteamUGCDownloadResult(RemoteStorageDownloadUGCResult_t pCallback, bool bIOFailure) { Debug.Log("[SteamUGCDownloadResult] -- " + pCallback.m_eResult + " -- Name:" + pCallback.m_pchFileName + " -- Size:" + pCallback.m_nSizeInBytes); if (pCallback.m_eResult == EResult.k_EResultOK) { RegisteredISO iso = _DownloadList.Find(iter => iter.UGCHandle == pCallback.m_hFile.m_UGCHandle); if (iso != null) { string fielName = VCConfig.s_CreationNetCachePath + iso._hashCode.ToString("X").PadLeft(16, '0') + VCConfig.s_CreationNetCacheFileExt; byte[] fileData = new byte[pCallback.m_nSizeInBytes]; int length = SteamRemoteStorage.UGCRead(pCallback.m_hFile, fileData, pCallback.m_nSizeInBytes, 0, EUGCReadAction.k_EUGCRead_Close); using (FileStream fs = new FileStream(fielName, FileMode.Create, FileAccess.Write, FileShare.Read)) { fs.Write(fileData, 0, length); } _DownloadList.RemoveAll(iter => iter.UGCHandle == pCallback.m_hFile.m_UGCHandle); _SteamItems[iso._hashCode] = pCallback.m_pchFileName; } if (BaseNetwork.MainPlayer.NetworkState == ENetworkState.Null) { NetworkManager.SyncServer(EPacketType.PT_Common_UGCDownloaded, pCallback.m_hFile.m_UGCHandle); } else { for (int i = 0; i < _CurDownloadList.Count; i++) { if (_CurDownloadList[i] == pCallback.m_hFile.m_UGCHandle) { NetworkManager.SyncServer(EPacketType.PT_Common_UGCDownloaded, pCallback.m_hFile.m_UGCHandle); _CurDownloadList[i] = 0; } } } _CurDownload = 0; if (_DownloadList.Count <= 0) { RoomGui_N.SetMapInfo("Download complete"); if (null != RoomGui_N.Instance && RoomGui_N.Instance.isShow) { RoomGui_N.Instance.ActiveStartBtn(); } } else { RoomGui_N.SetMapInfo("Downloading " + pCallback.m_pchFileName + "...[100%]"); } RoomGui_N.UpdateDownLoadInfo(_DownloadList.Count, 0); } else if (pCallback.m_eResult == EResult.k_EResultFileNotFound) { Debug.LogWarning(pCallback.m_hFile.m_UGCHandle + " does not exits."); //_DownloadList.RemoveAll(iter => iter.UGCHandle == pCallback.m_hFile.m_UGCHandle); //_CurDownload = 0; //if (_DownloadList.Count <= 0) //{ // RoomGui_N.SetMapInfo("Download complete"); // if (null != RoomGui_N.Instance && RoomGui_N.Instance.isShow) // RoomGui_N.Instance.ActiveStartBtn(); //} //RoomGui_N.UpdateDownLoadInfo(_DownloadList.Count, 0); NetworkManager.SyncServer(EPacketType.PT_Common_InvalidUGC, _DownloadList[0]._hashCode, pCallback.m_hFile.m_UGCHandle); } else if (pCallback.m_eResult == EResult.k_EResultTimeout) { NetworkManager.SyncServer(EPacketType.PT_Common_DownTimeOut, _DownloadList[0]._hashCode, pCallback.m_hFile.m_UGCHandle); } else { RoomGui_N.SetMapInfo("Download failed"); MessageBox_N.ShowYNBox(PELocalization.GetString(8000116), OnYesEvent, OnNoEvent); } }