using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; using UnityEngine.Networking; //[System.Serializable] //public class SheetInfo //{ // public string ToCsvString() // { // if (sheet_data == null) // return ""; // StringBuilder csvBuilder = new StringBuilder(); // foreach (List row in sheet_data) // { // for (int i = 0; i < row.Count; i++) // { // csvBuilder.Append(row[i]); // if (i < row.Count - 1) // { // csvBuilder.Append(","); // } // } // csvBuilder.Append("\n"); // } // return csvBuilder.ToString(); // } //} [System.Serializable] public class SheetInfoList { public Dictionary>> Data; public string ToCsvString(string key) { if (Data[key] == null) return ""; StringBuilder csvBuilder = new StringBuilder(); foreach (List row in Data[key]) { for (int i = 0; i < row.Count; i++) { csvBuilder.Append(row[i]); if (i < row.Count - 1) { csvBuilder.Append(","); } } csvBuilder.Append("\n"); } return csvBuilder.ToString(); } //} // public class CsvHeaderUpdater : MonoBehaviour // { // string _pathForHeaderTemplates = "../template/"; // contains a headers for each files // [SerializeField] List _pathsToDownload = new List(); // Decide which members need updating // [SerializeField] bool _allPaths = false; // [SerializeField] List _fileToLoad = new List(); // [SerializeField] bool _allFiles = false; // [SerializeField] SheetInfoList _allInfo = new(); // [SerializeField] int _numberOfFileReady = 0; // [SerializeField] int _numberOfFiles; // [ContextMenu("Load Files")] // public void StartProcess() // { // _numberOfFileReady = 0; // if (_allInfo.Data == null) _allInfo.Data = new(); // DownloadFilesForSelectedPaths(); // } // public void DownloadFilesForSelectedPaths() // { // StringBuilder sb = new StringBuilder(_P.PathServer + "members/"); // List paths = _pathsToDownload; // //if (_allPaths) { paths = new List(_G._Paths.Keys); paths.Remove(Paths.Universal); } // List files = _fileToLoad; // if (_allFiles) { files = new List(Enum.GetValues(typeof(Files)).Cast()); } // _numberOfFiles = files.Count * _pathsToDownload.Count; // foreach (Paths path in paths) // { // string member = _G._Paths[path]; // string serverPath = sb.ToString() + member + "/library/"; // foreach (Files file in files) // { // DownloadCsvList(serverPath, file.ToString(), member); // } // } // StaticCoroutine.Start(WaitForComplete()); // } // IEnumerator WaitForComplete() // { // yield return new WaitUntil(() => _numberOfFileReady >= _numberOfFiles); // Debug.Log("Completed"); // } // void DownloadCsvList(string serverPath, string csvFileName, string member) // { // StaticCoroutine.Start(DownloadFile(serverPath, csvFileName, member)); // } // public static string BinaryToText(byte[] data) // { // return Encoding.UTF8.GetString(data); // } // IEnumerator DownloadFile(string url, string fileName, string member) // { // string csvFileName = fileName.ToString() + ".csv?v=" + System.DateTime.Now; // url += csvFileName; // using (UnityWebRequest www = UnityWebRequest.Get(url)) // { // UnityWebRequest.ClearCookieCache(); // yield return www.SendWebRequest(); // _numberOfFileReady += 1; // if (www.result != UnityWebRequest.Result.Success) // { // Debug.Log("Problem encountered for " + fileName + " at " + url + " " + www.error); // } // else // { // if (www.downloadHandler.data == null) yield break; // string load = BinaryToText(www.downloadHandler.data); // string[] loads = load.Split(new char[] { '\n' }); // //List> data = new(); // //foreach (string line in loads) { string l = line.Replace("/", "|"); data.Add(line.Split(',').ToList()); } // List data = new(); // foreach (string line in loads) { string l = line.Replace("/", "|"); data.Add(l); } // _G.LibraryLoads = data; // } // } // } // private void ExtractCounter(string fileName, string member) // { // throw new NotImplementedException(); // } // IEnumerator SaveToTemplateCoroutine(string fileName, string csvdata) // { // string guidString = System.Guid.NewGuid().ToString(); // string urlForTemplate = "https://software.ciemetric.com/members/savecsv.php?a=" + guidString; // WWWForm form = new WWWForm(); // //string allInfo = JsonUtility.ToJson(_allInfo); // form.AddField("filename", fileName); // form.AddField("csvdata", csvdata); // form.AddField("path", _pathForHeaderTemplates); // using (UnityWebRequest www = UnityWebRequest.Post(urlForTemplate, form)) // { // yield return www.SendWebRequest(); // string response = www.downloadHandler.text; // Debug.Log("response == " + response); // if (www.result != UnityWebRequest.Result.Success) // { // // Debug.Log(www.error); // } // else // { // Debug.Log("Saved Template Successfuly"); // } // } // } }