using UnityEngine; using UnityEngine.UI; using System.Collections; using UnityEngine.Networking; using TMPro; [RequireComponent(typeof(Button))] public class Save_WEB : MonoBehaviour { //private static WaitForSeconds _waitForSeconds2 = new(2); // Prefix : "mt_" par defaut, "ai_" pour le bouton "send to ai jobs" (Send.SaveWEB). public static void SaveWEB(string Filename, string xmls, string Prefix = "mt_") { _G.FileName = Prefix+Filename; if(_G.FileName!="") { StaticCoroutine.Start(SendTextToFile(xmls)); } } public static IEnumerator SendTextToFile(string xmls) { WWWForm form = new(); //_G.PATH="baindepot"; //NEW VERSION string SendPath=_G.PATH; if(_G.PATH=="kitchensdepot")SendPath="free"; form.AddField("filename", SendPath+"/cloud/"+_G.FileName); //print("pathfile==="+_G.PATH+"/cloud/"+_G.FileName); form.AddField("filedata", xmls); //LIVE VERSION //form.AddField("filename", _G.FileName);//////////////////////////////////////////////////////////// //form.AddField("xmldata", xmls);//////////////////////////////////////////////////////////// //string path = ThisOnly.geturlSaveWeb(); string path = "https://ukitchenit.com/members/savecloud.php"; print("Save path====="+path); using UnityWebRequest webRequest = UnityWebRequest.Post(path, form); yield return webRequest.SendWebRequest(); // Seul ConnectionError etait traite : un refus du serveur (ProtocolError 4xx/5xx) tombait // dans le else et passait pour un succes. On trace le verdict dans tous les cas. print("Save result====" + webRequest.result + " code=" + webRequest.responseCode + " file=" + SendPath + "/cloud/" + _G.FileName); if (webRequest.result != UnityWebRequest.Result.Success) Debug.LogError("Save failed==== " + webRequest.error + "\n" + webRequest.downloadHandler?.text); else print("Save response====" + webRequest.downloadHandler?.text); if (webRequest.result == UnityWebRequest.Result.ConnectionError) { GameObject.Find("Canvas/SENDING/Message").GetComponent().text = "error!"; } else { //GameObject.Find("FN").GetComponent().text = _G.FileName; //_M.PH(2, 0, "ffffff", 1, 1); // Le rendu ne concerne que les jobs ai_ : l'envoi courriel sauvegarde en mt_ et n'a // rien a faire rendre. SendPath et non _G.PATH : c'est la que le fichier a ete ecrit. if (webRequest.result == UnityWebRequest.Result.Success && _G.FileName.StartsWith("ai_")) yield return CreateRenderJob(SendPath, _G.FileName); yield return new WaitForSeconds(1); //Get.o2("HIDER", "MESSAGE").SetActive(false); UnityWebRequest.ClearCookieCache(); //StaticCoroutine.Start(SendTextToFileBK(xmls)); } yield break; } // Demande au serveur de lancer le rendu du design qui vient d'etre sauvegarde. // fileName contient deja le prefixe ("ai_" pour les jobs) pose par SaveWEB(). public static IEnumerator CreateRenderJob(string path, string fileName) { // Doit viser exactement le fichier poste par SendTextToFile, avec l'extension ajoutee par savecloud.php. string file = "members/" + path + "/cloud/" + fileName + ".udt"; string url = "https://ukitchenit.com/aidesign/render/create-job.php?file=" + UnityWebRequest.EscapeURL(file); print("Render job path====" + url); using UnityWebRequest webRequest = UnityWebRequest.Get(url); yield return webRequest.SendWebRequest(); if (webRequest.result != UnityWebRequest.Result.Success) Debug.LogError("Render job failed==== " + webRequest.error); else print("Render job created====" + webRequest.downloadHandler.text); } // public static IEnumerator SendTextToFileBK(string xmls) // { // WWWForm form = new WWWForm(); // form.AddField("filename", _G.PATH+"/cloudbk/"+_G.FileName+_G.BKN); // form.AddField("filedata", xmls); // string path = ThisOnly.geturlSaveWeb();//_G.path+"members/savecloud.php" // using UnityWebRequest webRequest = UnityWebRequest.Post(path, form); // yield return webRequest.SendWebRequest(); // if (webRequest.result == UnityWebRequest.Result.ConnectionError) // { // GameObject.Find("FN").GetComponent().text = "error!"; // } // else // { // GameObject.Find("FN").GetComponent().text = _G.FileName; // //_M.PH(2, 0, "ffffff", 1, 1); // yield return _waitForSeconds2; // Get.o2("HIDER", "MESSAGE").SetActive(false); // _G.BKN += 1; // if (_G.BKN == 4) _G.BKN = 1; // UnityWebRequest.ClearCookieCache(); // } // yield break; // } }