private void LoadDeckPaddDecks(string DeckFile) { //this.Decks = new List<Deck>(); Deck item = new Deck(); DownloadFileHandler fh = GameObject.Find("FileHandler").GetComponent <DownloadFileHandler>(); item.GUID = System.Guid.NewGuid().ToString(); string deckType; System.IO.StreamReader sr = new System.IO.StreamReader(DeckFile); while (!sr.EndOfStream) { string line = sr.ReadLine(); string[] data = line.Split('\t'); List <string[]> cardData = CardBase.GetDataByField(CardBase.CardCollection, "Name", data[1], false); deckType = CardBase.FieldValue(cardData[0], "Type"); int cardIndex = CardBase.GetIndex(data[1]); Card card = new Card(); card.ParentGUID = item.GUID; card.Active = true; card.CardIndex = cardIndex; fh.GetFileFromURL(cardIndex); card.PlayerIndex = Global.CurrentPlayer; switch (deckType) { case "Mission": GetDeck(DeckEnum.Mission).Cards.Add(card); break; case "Dilemma": GetDeck(DeckEnum.Dilemma).Cards.Add(card); break; default: GetDeck(DeckEnum.Draw).Cards.Add(card); break; } } }
/// <summary> /// 执行文件下载 /// </summary> /// <param name="url"></param> /// <param name="savePath"></param> /// <param name="downloadFileHandler"></param> public void downloadFile(string url, string savePath, DownloadFileHandler downloadFileHandler) { this.downloadFileHandler = downloadFileHandler; this.url = url; this.savePath = savePath; try { // 创建目录 System.IO.Directory.CreateDirectory(Path.GetDirectoryName(savePath)); if (File.Exists(savePath)) { File.Delete(savePath); } wc = new WebClient(); wc.DownloadProgressChanged += WebClientDownloadProgressChanged; wc.DownloadDataCompleted += WebClientDownloadCompleted; wc.DownloadDataAsync(new Uri(url)); // Sync //byte[] bf = wc.DownloadData(new System.Uri(url)); //ByteArrayToFile(savePath, bf); // DownloadFileAsync存在文件不释放问题 // wc.DownloadFileAsync(new System.Uri(url), savePath); } catch (Exception ex) { downloadCro.IsSuccess = false; downloadCro.Message = ex.Message; downloadFileHandler?.Invoke(downloadCro); } }
public bool GetStationsLite() { if (File.Exists(commoditiesTempFileName)) { File.Delete(commoditiesTempFileName); // migration - remove obsolete file } return(DownloadFileHandler.DownloadFile("http://robert.astronet.se/Elite/eddb/v4/stations.json", stationFileName)); }
public bool GetCommodities() { if (File.Exists(systemTempFileName)) { File.Delete(systemTempFileName); // migration - remove obsolete file } return(DownloadFileHandler.DownloadFile("http://robert.astronet.se/Elite/eddb/v4/commodities.json", commoditiesFileName)); }
public bool GetSystems() { if (File.Exists(stationTempFileName)) { File.Delete(stationTempFileName); // migration - remove obsolete file } return(DownloadFileHandler.DownloadFile("http://robert.astronet.se/Elite/eddb/v4/systems_populated.json", systemFileName)); }
private void LoadLackeyDecks(string DeckFile) { //this.Decks = new List<Deck>(); DownloadFileHandler fh = GameObject.Find("FileHandler").GetComponent <DownloadFileHandler>(); Deck item = GetDeck(DeckEnum.Draw); item.GUID = System.Guid.NewGuid().ToString(); item.Cards.Clear(); string deckType = ""; System.IO.StreamReader sr = new System.IO.StreamReader(DeckFile); while (!sr.EndOfStream) { string line = sr.ReadLine(); if (line != "") { string[] data = line.Split('\t'); if (data.Length == 1) { deckType = data[0]; } else { if (data[1].Trim() != "") { int qty = System.Int32.Parse(data[0]); int cardIndex = CardBase.GetIndex(data[1]); fh.GetFileFromURL(cardIndex); Card card = new Card(); card.ParentGUID = item.GUID; card.Active = true; card.CardIndex = cardIndex; card.PlayerIndex = Global.CurrentPlayer; for (int i = 0; i < qty; i++) { switch (deckType) { case "Missions:": GetDeck(DeckEnum.Mission).Cards.Add(card); break; case "Dilemmas:": GetDeck(DeckEnum.Dilemma).Cards.Add(card); break; default: GetDeck(DeckEnum.Draw).Cards.Add(card); break; } } } else { deckType = data[0]; } } } } }
private void Btn_download_Click(object sender, RoutedEventArgs e) { TransferFileDetails = (TransferFileDetails)dataGrid.SelectedItem; if (TransferFileDetails != null) { downloadFiles.Add(new FileStatus(TransferFileDetails.FileName, TransferFileDetails.FileSize, "Downloading..")); UpdateDataGrid(); DownloadFileHandler downloadFile = new DownloadFileHandler(TransferFileDetails, download_DataGrid); dataGrid.SelectedItem = null; dataGrid_LostFocus(null, null); } }
internal string GetHiddenSystems() { try { string edsmhiddensystems = Path.Combine(Tools.GetAppDataDirectory(), "edsmhiddensystems.json"); bool newfile = false; DownloadFileHandler.DownloadFile(_serverAddress + "api-v1/hidden-systems?showId=1", edsmhiddensystems, out newfile); string json = Tools.TryReadAllTextFromFile(edsmhiddensystems); return(json); } catch (Exception ex) { Trace.WriteLine($"Exception: {ex.Message}"); Trace.WriteLine($"ETrace: {ex.StackTrace}"); return(null); } }
public string GetEDSMDistances() // download a file of distances.. { if (File.Exists(EDSMDistancesFileName)) { File.Delete(EDSMDistancesFileName); } if (File.Exists(EDSMDistancesFileName + ".etag")) { File.Delete(EDSMDistancesFileName + ".etag"); } if (DownloadFileHandler.DownloadFile(_serverAddress + "dump/distances.json", EDSMDistancesFileName)) { return(EDSMDistancesFileName); } else { return(null); } }