private IEnumerator _updateTable(string name, string URL, string ver) { State = CSVWranglerState.Downloading; Debug.Log(name + ".csv is downloading"); WWW www = new WWW(URL); activeDownloads.Add(www); yield return(www); if (string.IsNullOrEmpty(www.error)) { UTIL.WriteAllText(Application.persistentDataPath + "/" + name + ".csv", www.text); //we know the order its name, url, ver //get the row string[] targetRow = indexTable.GetRowWithData("name", name); //doesn't exist create it if (targetRow == null) { targetRow = new string[3]; targetRow[0] = name; indexTable.AddRow(targetRow); } targetRow[1] = URL; targetRow[2] = ver; } activeDownloads.Remove(www); }
//load local tables from persist storage as described in the curtable, which is loaded from the csvwrangler.csv // currently synchronous, in the future may become async public void LoadTables() { State = CSVWranglerState.Loading; //reset so we could reload tables = new Dictionary <string, DeadSimpleCSV>(); //grab the row and load each file of name into the tables dict string[] tableNames = indexTable.GetColumn("name"); foreach (string name in tableNames) { string tableFullLoc = Application.persistentDataPath + "/" + name + ".csv"; //TODO could change this logic so the file contents is returned by the util function so we don't double load? //make sure it exists UTIL.EnsureTextResourceIsHere(tableFullLoc, "csvs/" + name); //attempt to load string fileContents = UTIL.ReadAllText(tableFullLoc); //notify of failure if (string.IsNullOrEmpty(fileContents)) { Debug.LogWarning("Tried to load the " + name + " csv but something went wrong"); } else//success, maybe { DeadSimpleCSV table = new DeadSimpleCSV(fileContents, true); tables.Add(name, table); } } State = CSVWranglerState.Ready; }
//this checks the local index against the live url index given, downloads new or updated or all if forced csvs // and stores in Application persist data path any newer versions that are listed in the index public void UpdateFromIndex(string indexURL) { ForceInitIndex(); State = CSVWranglerState.CheckingIndex; StartCoroutine(_updateFromIndex(indexURL)); }
private void ProcessIndex(DeadSimpleCSV newTable) { State = CSVWranglerState.ProcessingIndex; //make a list of all name col names string[] curNames = indexTable.GetColumn("name"), newNames = newTable.GetColumn("name"); List <string> colnames = new List <string>(); colnames.AddRange(curNames.ToList()); colnames.AddRange(newNames.ToList()); colnames = colnames.Distinct().ToList(); //this is all a bit too table-ey and memory trashy but it is a table and it is a one off init process //handles all new rows from the given index, updates, creates and destroys as required _processAllNewRows(colnames, newTable); //flush the index file back to storage StartCoroutine(_flushUpdatedTable(true)); }
public void ForceInitIndex() { string csvIndexLoc = Application.persistentDataPath + "/csvWrangler.csv"; //ForceCacheLocalFiles(); if (!ForceCacheIndex()) { Debug.LogError("CSV Wrangler is trying to be used without a local cached csvWrangler.csv in the Resources. Did you remember to cache your csvs?"); State = CSVWranglerState.ErrorNoIndex; return; } //load previous csvwrangler index csv file indexTable = new DeadSimpleCSV(UTIL.ReadAllText(csvIndexLoc), true); //something terrible happened fake an empty one if (indexTable.headers == null || indexTable.headers.Length == 0) { indexTable.headers = new string[] { "name", "url", "ver" }; } State = CSVWranglerState.IndexOnly; }