diff --git a/Assets/EvaluluScript_SendTracesFromHMSceneStart.cs b/Assets/EvaluluScript_SendTracesFromHMSceneStart.cs new file mode 100644 index 0000000000000000000000000000000000000000..f334256fd8de33b0d63151ccf45bbc249b6d569b --- /dev/null +++ b/Assets/EvaluluScript_SendTracesFromHMSceneStart.cs @@ -0,0 +1,312 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using UnityEngine; + +public class EvaluluScript_SendTracesFromHMSceneStart : MonoBehaviour +{ + // Start is called before the first frame update + public void CallbackSynchroEnd(List<string> allAccount, List<string> successSynchroAccount, List<string> errorSynchroAccount) + { + sendTraces(successSynchroAccount); + } + + private bool currentlySending = false; + private int nbOfFilesToUpload = 0; + private int nbOfFilesUploaded = 0; + private List<path_andteacherid_and_userid> savedFilesWaitingToBeUploaded; + private string pathDirectory; + private string pathDirectoryArchive; + private string PathDirectoryTemporary; + private string pathDirectoryArchiveAncien; + private string currentlySentFilePath = ""; + private string currentlySentTemporaryFilePath = ""; + public HM_PluginController hmPluginController; + + public class path_andteacherid_and_userid + { + public string path; + public string teachercode; + public string usercode; + public string usericonID; + } + + [System.Serializable] + public class NewSystemeDeTracesJSONRoot + { + public string deviceUniqueID; + public string fluenceId; + public string teacherCode; + public string loginCode; + public string userID; + public string userIconID; + } + + public void sendTraces(List<string> successSynchroAccount) + { + //Debug.LogError("sendTraces thisTeacherCode="+ thisTeacherCode+ " loginCode = "+ loginCode); + pathDirectory = Application.persistentDataPath + "/newSystemeTraces/"; + pathDirectoryArchive = Application.persistentDataPath + "/newSystemeTraces/ArchiveReal"; + pathDirectoryArchiveAncien = Application.persistentDataPath + "/newSystemeTraces/Archive"; + PathDirectoryTemporary = Application.persistentDataPath + "/newSystemeTraces/Temporary"; + + + + if (!currentlySending) + { + + + currentlySending = true; + nbOfFilesToUpload = 0; + nbOfFilesUploaded = 0; + savedFilesWaitingToBeUploaded = new List<path_andteacherid_and_userid>(); + savedFilesWaitingToBeUploaded.Clear(); + string[] savedFilesWaitingToBeUploaded_temp1 = Directory.GetFiles(pathDirectory, "*.json"); // attention, ici on prend TOUT les fichiers sans distinction alors qu'il faudrait à minima check le enseignant ID + string[] savedFilesWaitingToBeUploaded_inOldArciveFolder_temp = Directory.GetFiles(pathDirectoryArchiveAncien, "*.json"); // attention, ici on prend TOUT les fichiers sans distinction alors qu'il faudrait à minima check le enseignant ID + string[] savedFilesWaitingToBeUploaded_temp = savedFilesWaitingToBeUploaded_temp1.Concat(savedFilesWaitingToBeUploaded_inOldArciveFolder_temp).ToArray(); + + foreach (string teacheraccount in successSynchroAccount) + { + //Debug.LogError("account in successSynchroAccount = " + account); + List<HM_ChildUser> childUsers = HM_PluginController.GetAllActiveChildsOfTeacher(teacheraccount); + if (childUsers != null) + { + foreach (HM_ChildUser child in childUsers) + { + //Debug.Log("userIconID="+child.userIconID+ " loginCode="+ child.loginCode+ " userID="+ child.userID); + //si besoin ça c'est l'UUID qui est aussi renvoyé par la fonction "GetMainUserID" (au où tu l'utilisais pour identifier les élèves, permettra du coup de faire le lien) + foreach (string filePath in savedFilesWaitingToBeUploaded_temp) + { + // Lire le contenu du fichier JSON + string jsonContent = System.IO.File.ReadAllText(filePath); + + // Désérialiser le JSON en une instance de la classe + NewSystemeDeTracesJSONRoot data = JsonUtility.FromJson<NewSystemeDeTracesJSONRoot>(jsonContent); + + // Accéder aux propriétés nécessaires + string teacherCode = data.teacherCode; + string usericonID = data.userIconID; + string logincodeuser = data.loginCode; + // Faire quelque chose avec les valeurs, par exemple, les imprimer dans la console + + if (teacherCode == teacheraccount && logincodeuser == child.loginCode && usericonID == child.userIconID.ToString()) + { + path_andteacherid_and_userid aaa = new path_andteacherid_and_userid(); + aaa.path = filePath; + aaa.teachercode = teacherCode; + aaa.usericonID = usericonID; + aaa.usercode = logincodeuser; + Debug.LogError("bingo"); + Debug.Log($"Fichier : {filePath}, teacherCode : {teacherCode}, userIconID : {usericonID}"); + savedFilesWaitingToBeUploaded.Add(aaa); + } + } + } + } + } + + + + Debug.Log("au final on a à uploader " + savedFilesWaitingToBeUploaded.Count + " fichiers"); + + + if (!Directory.Exists(pathDirectoryArchive)) + { + Directory.CreateDirectory(pathDirectoryArchive); + } + if (!Directory.Exists(PathDirectoryTemporary)) + { + Directory.CreateDirectory(PathDirectoryTemporary); + } + else + { + deleteTemporaryFiles(); + } + nbOfFilesToUpload = savedFilesWaitingToBeUploaded.Count; + + if (nbOfFilesToUpload > 0) + { + uploadOnefichierTraceToHM(); + } + + + } + currentlySending = false; + } + + private void deleteTemporaryFiles() + { + // Obtenez la liste de tous les fichiers dans le dossier spécifié. + string[] files = Directory.GetFiles(PathDirectoryTemporary); + + foreach (string filePath in files) + { + if (Path.GetExtension(filePath) == ".json") + { + try + { + // Supprimez le fichier s'il a l'extension .json. + File.Delete(filePath); + ////Debug.Log("Fichier supprimé : " + filePath); + } + catch (Exception e) + { + ////Debug.LogError("Erreur lors de la suppression du fichier : " + e.Message); + } + } + } + } + + private void uploadOnefichierTraceToHM() + { + if (nbOfFilesUploaded > savedFilesWaitingToBeUploaded.Count - 1) + { + endAllUploads(); + } + else + { + currentlySentFilePath = savedFilesWaitingToBeUploaded[nbOfFilesUploaded].path; + // Le fichier JSON existe, donc nous le lisons + string dateEnvoi = DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"); + + string nouveauNomAvecDate = Path.GetFileNameWithoutExtension(currentlySentFilePath) + "-" + dateEnvoi + ".json"; + Debug.Log("on etudie " + currentlySentFilePath); + if (currentlySentFilePath.Contains("Archive")) + { + Debug.LogError("on traite une archive là"); + nouveauNomAvecDate = Path.GetFileNameWithoutExtension(currentlySentFilePath) + ".json"; + } + + currentlySentTemporaryFilePath = Path.Combine(PathDirectoryTemporary, nouveauNomAvecDate); + Debug.Log("nouveauNomAvecDate = " + nouveauNomAvecDate + " currentlySentTemporaryFilePath=" + currentlySentTemporaryFilePath); + // Copiez le fichier source vers le dossier de destination en le renommant si nécessaire. + File.Copy(currentlySentFilePath, currentlySentTemporaryFilePath, true); + if (File.Exists(currentlySentTemporaryFilePath)) + { + try + { + string teachercode = savedFilesWaitingToBeUploaded[nbOfFilesUploaded].teachercode; + string userIconID = savedFilesWaitingToBeUploaded[nbOfFilesUploaded].usericonID; + string userloginCode = savedFilesWaitingToBeUploaded[nbOfFilesUploaded].usercode; + HM_PluginController.UploadTrace(currentlySentTemporaryFilePath, uploadOneFileAsynchroneFinished, teachercode, userIconID, userloginCode); + } + catch (Exception ex) + { + // Gérez toute exception survenue lors de l'appel à CheckTraceExist ici. + Debug.LogError("Erreur lors de l'appel à UploadTrace : " + ex.Message); + deletecurrentFileFromTemporaryFolder(false); + endAllUploads(); + } + } + else + { + Debug.LogError("Traces 2 - ne devrait jamais arriver"); + deletecurrentFileFromTemporaryFolder(false); + endAllUploads(); + /* sauf si : + * Fichier source inexistant : Si le fichier source spécifié n'existe pas, la copie échouera. + Permissions insuffisantes : Si l'application n'a pas les permissions nécessaires pour lire le fichier source ou écrire dans le répertoire de destination, la copie échouera. + Espace disque insuffisant : Si le disque de destination est plein ou manque d'espace, la copie échouera. + Fichier de destination verrouillé : Si le fichier de destination est déjà ouvert ou verrouillé par une autre application, la copie échouera. + Problèmes matériels : Des problèmes matériels, tels que des secteurs défectueux sur le disque, peuvent entraîner des erreurs lors de la copie + */ + } + } + + } + + private void deletecurrentFileFromTemporaryFolder(bool SuccesSomoveitToTheArchiveFolder) + { + if (SuccesSomoveitToTheArchiveFolder) + { + // Obtenez le nom du fichier sans le chemin + string fileName = Path.GetFileName(currentlySentTemporaryFilePath); + // Créez le chemin complet du fichier de destination dans le nouveau dossier + string destinationARCHIVEFilePath = Path.Combine(pathDirectoryArchive, fileName); + // Déplacez le fichier source vers le dossier de destination + ////Debug.Log("fichierTemporary moved in archive" + fichierTemporary); + if (File.Exists(currentlySentTemporaryFilePath)) + { + if (!File.Exists(destinationARCHIVEFilePath)) + { + File.Move(currentlySentTemporaryFilePath, destinationARCHIVEFilePath); + } + else + { + File.Delete(currentlySentTemporaryFilePath); + } + } + + + ////Debug.Log("ToDeleteOriginalFilePath = " + fichierOriginal); + // et on supprime le fichier original vu qu'il a été mis dans l'archive + if (File.Exists(currentlySentFilePath)) + { + File.Delete(currentlySentFilePath); + ////Debug.Log("fichier original deleted " + fichierOriginal); + } + else + { + ////Debug.Log("le fichier original n'existe pas "); + } + } + else + { + // on supprime le fichier de temporary + if (File.Exists(currentlySentTemporaryFilePath)) + { + File.Delete(currentlySentTemporaryFilePath); + ////Debug.Log("fichier original deleted " + fichierOriginal); + } + } + } + + + private void uploadOneFileAsynchroneFinished(int resultCode, string resultMessage) + { + Debug.LogError("resultCode=" + resultCode + " resultMessage=" + resultMessage + " nombreDeFichiersTraites=" + nbOfFilesUploaded + " nombreDeFichiersATransferer=" + nbOfFilesToUpload); + ////Debug.Log("transfertAsynchroneFinished resultCode = " + resultCode.ToString() + " resultMessage=" + resultMessage + " nombreDeFichiersTraites = " + nombreDeFichiersTraites); + + if (resultCode == 1 || resultCode == 0) + { + deletecurrentFileFromTemporaryFolder(true); + if (nbOfFilesUploaded == nbOfFilesToUpload - 1) + { + + nbOfFilesToUpload = 0; + nbOfFilesUploaded = 0; + currentlySending = false; + endAllUploads(); + + } + else + { + // le transfeet précédent c'est bien passé (retour == 0) on lance le fichier suivant + nbOfFilesUploaded++; + uploadOnefichierTraceToHM(); + } + + + // Bien passé + } + else + { + Debug.LogError("erreur lors de l'envoi on stop tout"); + deletecurrentFileFromTemporaryFolder(false); + endAllUploads(); + } + } + + + private void endAllUploads() + { + Debug.LogError("endTransferts"); + nbOfFilesUploaded = 0; + nbOfFilesToUpload = 0; + currentlySending = false; + + } + +} diff --git a/Assets/EvaluluScript_SendTracesFromHMSceneStart.cs.meta b/Assets/EvaluluScript_SendTracesFromHMSceneStart.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..6c0d645b233cdf3775169a57e8b90a2c6b13ae70 --- /dev/null +++ b/Assets/EvaluluScript_SendTracesFromHMSceneStart.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b3fe735a286924845b27fd76072b5089 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Prefabs/uploadTracesEvalulu_adeposerdansHM_sceneStart.prefab b/Assets/Prefabs/uploadTracesEvalulu_adeposerdansHM_sceneStart.prefab new file mode 100644 index 0000000000000000000000000000000000000000..e471ac85f258794b62f768835b150248b873d0a2 --- /dev/null +++ b/Assets/Prefabs/uploadTracesEvalulu_adeposerdansHM_sceneStart.prefab @@ -0,0 +1,50 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &3444795586396849137 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 3797655205488179624} + - component: {fileID: 279471507686351197} + m_Layer: 5 + m_Name: uploadTracesEvalulu_adeposerdansHM_sceneStart + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &3797655205488179624 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3444795586396849137} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 100, y: 100} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &279471507686351197 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 3444795586396849137} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b3fe735a286924845b27fd76072b5089, type: 3} + m_Name: + m_EditorClassIdentifier: diff --git a/Assets/Prefabs/uploadTracesEvalulu_adeposerdansHM_sceneStart.prefab.meta b/Assets/Prefabs/uploadTracesEvalulu_adeposerdansHM_sceneStart.prefab.meta new file mode 100644 index 0000000000000000000000000000000000000000..4056abfeeee6d77f39050adea32728634d099e85 --- /dev/null +++ b/Assets/Prefabs/uploadTracesEvalulu_adeposerdansHM_sceneStart.prefab.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 06a9d1a944c66694db163b78f9e08fb5 +PrefabImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/TRANS3_PluginHM/Scenes/HM_SceneStart.unity b/Assets/TRANS3_PluginHM/Scenes/HM_SceneStart.unity index 2df10a23b4321617daa8f402672bf30fa2670cce..e876499f85d59013a3d26282749995931705dd8f 100644 --- a/Assets/TRANS3_PluginHM/Scenes/HM_SceneStart.unity +++ b/Assets/TRANS3_PluginHM/Scenes/HM_SceneStart.unity @@ -36228,6 +36228,7 @@ RectTransform: m_ConstrainProportionsScale: 0 m_Children: - {fileID: 2880375242900932910} + - {fileID: 1706337277} m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} @@ -44262,6 +44263,119 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 1696368029} m_CullTransparentMesh: 1 +--- !u!1001 &1706337276 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + serializedVersion: 3 + m_TransformParent: {fileID: 1399988443} + m_Modifications: + - target: {fileID: 3444795586396849137, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_Name + value: uploadTracesEvalulu_adeposerdansHM_sceneStart + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_Pivot.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_Pivot.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_AnchorMax.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_AnchorMax.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_AnchorMin.x + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_AnchorMin.y + value: 0.5 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_SizeDelta.x + value: 100 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_SizeDelta.y + value: 100 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_AnchoredPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_AnchoredPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_RemovedGameObjects: [] + m_AddedGameObjects: [] + m_AddedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} +--- !u!224 &1706337277 stripped +RectTransform: + m_CorrespondingSourceObject: {fileID: 3797655205488179624, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + m_PrefabInstance: {fileID: 1706337276} + m_PrefabAsset: {fileID: 0} +--- !u!114 &1706337278 stripped +MonoBehaviour: + m_CorrespondingSourceObject: {fileID: 279471507686351197, guid: 06a9d1a944c66694db163b78f9e08fb5, type: 3} + m_PrefabInstance: {fileID: 1706337276} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b3fe735a286924845b27fd76072b5089, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &1714360956 GameObject: m_ObjectHideFlags: 0 @@ -63097,7 +63211,19 @@ MonoBehaviour: m_Calls: [] onSynchroEnd: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 1706337278} + m_TargetAssemblyTypeName: EvaluluScript_SendTracesFromHMSceneStart, Assembly-CSharp + m_MethodName: CallbackSynchroEnd + m_Mode: 0 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 childAvatars: - {fileID: 21300000, guid: d37b2a0103a7d3a4dbe5515de7901bb1, type: 3} - {fileID: 21300000, guid: 5b81b6917f2275344ae44b9c802fcfd6, type: 3} diff --git a/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs b/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs index 24355da914ba17083e302bf0ab8699269846dbcd..e95436a024e80330fd4fea9d8e1b3016eb76a526 100644 --- a/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs +++ b/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs @@ -402,11 +402,11 @@ public class HM_PluginController : MonoBehaviour void Start() { if (HM_NetworkController.currentENV == HM_NetworkController.ENV.DEVELOP) - GameObject.Find("HM_TextVersion").GetComponent<TextMeshProUGUI>().text = "v1.6.5 - DEVELOP"; + GameObject.Find("HM_TextVersion").GetComponent<TextMeshProUGUI>().text = "v1.6.6 - DEVELOP"; else if (HM_NetworkController.currentENV == HM_NetworkController.ENV.PREPROD) - GameObject.Find("HM_TextVersion").GetComponent<TextMeshProUGUI>().text = "v1.6.5 - PREPROD"; + GameObject.Find("HM_TextVersion").GetComponent<TextMeshProUGUI>().text = "v1.6.6 - PREPROD"; else - GameObject.Find("HM_TextVersion").GetComponent<TextMeshProUGUI>().text = "v1.6.5 - PROD"; + GameObject.Find("HM_TextVersion").GetComponent<TextMeshProUGUI>().text = "v1.6.6 - PROD"; HM_Scripts.optionPanel.HideButton(true); @@ -1189,13 +1189,13 @@ public class HM_PluginController : MonoBehaviour Debug.Log(GetSettingsSession()); } - public static void CheckTraceExist(string fileURL, System.Action<int,string> callback, int userIconId = -1, int userLoginCode = -1) + public static void CheckTraceExist(string fileURL, System.Action<int,string> callback, string teacherCode = null, int userIconId = -1, string userLoginCode = null) { HM_Scripts.pluginController.StartPlugin(); HM_ReturnInfo returnInfo = new HM_ReturnInfo(); - if (userIconId == -1 && userLoginCode == -1 && HM_DataController.currentChildUser == null) + if (teacherCode == null && userIconId == -1 && userLoginCode == null && HM_DataController.currentChildUser == null) { returnInfo.code = -1; returnInfo.message = "Le plugin HM ne retrouve pas l'enfant actuellement connecté"; @@ -1211,21 +1211,31 @@ public class HM_PluginController : MonoBehaviour return; } - if (HM_DataController.currentTeacherAccount.dataAWS._idToken == null - || HM_DataController.currentTeacherAccount.dataAWS._idToken.Length == 0 - || HM_DataController.currentTeacherAccount.dataAWS.identityId == null - || HM_DataController.currentTeacherAccount.dataAWS.identityId.Length == 0) + HM_TeacherAccount teacherAccount = null; + + if(teacherCode != null) { - returnInfo.code = -3; - returnInfo.message = "Compte professeur non authentifié"; - HM_Scripts.pluginController.StartCoroutine(OnCheckTraceExistResponse(returnInfo, callback)); - return; + foreach(HM_TeacherAccount t in HM_DataController.model.teacherAccounts) + { + if(t.teacherCode.ToUpper().Equals(teacherCode.ToUpper())) + { + teacherAccount = t; + break; + } + } + } + else + { + teacherAccount = HM_DataController.currentTeacherAccount; } - if ((userIconId == -1 && userLoginCode != -1) || (userIconId != -1 && userLoginCode == -1)) + if (teacherAccount.dataAWS._idToken == null + || teacherAccount.dataAWS._idToken.Length == 0 + || teacherAccount.dataAWS.identityId == null + || teacherAccount.dataAWS.identityId.Length == 0) { - returnInfo.code = -4; - returnInfo.message = "Une des deux données userIconId ou userLoginCode n'est pas renseigné"; + returnInfo.code = -3; + returnInfo.message = "Compte professeur non authentifié"; HM_Scripts.pluginController.StartCoroutine(OnCheckTraceExistResponse(returnInfo, callback)); return; } @@ -1254,9 +1264,9 @@ public class HM_PluginController : MonoBehaviour break; } - string serverPath = "private/" + HM_DataController.currentTeacherAccount.dataAWS.identityId + "/traces/" + appName + "/"; + string serverPath = "private/" + teacherAccount.dataAWS.identityId + "/traces/" + appName + "/"; - if (userIconId != -1 && userLoginCode != -1) + if (userIconId != -1 && userLoginCode != null) { serverPath += userIconId + "/" + userLoginCode + "/" + filename; } @@ -1297,13 +1307,14 @@ public class HM_PluginController : MonoBehaviour yield return null; } - public static void UploadTrace(string fileURL, System.Action<int, string> callback, int userIconId = -1, int userLoginCode = -1) + public static void UploadTrace(string fileURL, System.Action<int, string> callback, string teacherCode = null, string userIconId = null, string userLoginCode = null) { + Debug.Log("UploadTrace"); HM_Scripts.pluginController.StartPlugin(); HM_ReturnInfo returnInfo = new HM_ReturnInfo(); - if (userIconId == -1 && userLoginCode == -1 && HM_DataController.currentChildUser == null) + if (teacherCode == null && userIconId == null && userLoginCode == null && HM_DataController.currentChildUser == null) { returnInfo.code = -1; returnInfo.message = "Le plugin HM ne retrouve pas l'enfant actuellement connecté"; @@ -1319,21 +1330,31 @@ public class HM_PluginController : MonoBehaviour return; } - if (HM_DataController.currentTeacherAccount.dataAWS._idToken == null - || HM_DataController.currentTeacherAccount.dataAWS._idToken.Length == 0 - || HM_DataController.currentTeacherAccount.dataAWS.identityId == null - || HM_DataController.currentTeacherAccount.dataAWS.identityId.Length == 0) + HM_TeacherAccount teacherAccount = null; + + if (teacherCode != null) { - returnInfo.code = -3; - returnInfo.message = "Compte professeur non authentifié"; - HM_Scripts.pluginController.StartCoroutine(OnUploadTraceResponse(returnInfo, callback)); - return; + foreach (HM_TeacherAccount t in HM_DataController.model.teacherAccounts) + { + if (t.teacherCode.ToUpper().Equals(teacherCode.ToUpper())) + { + teacherAccount = t; + break; + } + } + } + else + { + teacherAccount = HM_DataController.currentTeacherAccount; } - if ((userIconId == -1 && userLoginCode != -1) || (userIconId != -1 && userLoginCode == -1)) + if (teacherAccount.dataAWS._idToken == null + || teacherAccount.dataAWS._idToken.Length == 0 + || teacherAccount.dataAWS.identityId == null + || teacherAccount.dataAWS.identityId.Length == 0) { - returnInfo.code = -4; - returnInfo.message = "Une des deux données userIconId ou userLoginCode n'est pas renseigné"; + returnInfo.code = -3; + returnInfo.message = "Compte professeur non authentifié"; HM_Scripts.pluginController.StartCoroutine(OnUploadTraceResponse(returnInfo, callback)); return; } @@ -1362,9 +1383,9 @@ public class HM_PluginController : MonoBehaviour break; } - string serverPath = "private/" + HM_DataController.currentTeacherAccount.dataAWS.identityId + "/traces/" + appName + "/"; + string serverPath = "private/" + teacherAccount.dataAWS.identityId + "/traces/" + appName + "/"; - if (userIconId != -1 && userLoginCode != -1) + if (userIconId != null && userLoginCode != null) { serverPath += userIconId + "/" + userLoginCode + "/" + filename; } diff --git a/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs.bak b/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs.bak new file mode 100644 index 0000000000000000000000000000000000000000..43a82199f727b594088006570cc531e4c6a4717b --- /dev/null +++ b/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs.bak @@ -0,0 +1,1411 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using TMPro; +using System; +using UnityEngine.Events; +using Newtonsoft.Json; +using System.Text; +using UnityEngine.UI; +using Shatalmic; +using UnityEngine.Android; +using Newtonsoft.Json.Linq; +using System.Threading.Tasks; + +public enum APP_ID +{ + NONE, + LUCIOLE, + ELARGIR, + EVASION, + EVALULU, +} + +public class HM_PluginController : MonoBehaviour +{ + public enum NAV_CONTEXT + { + NONE, + LOT, + LETTRE, + NEW_TEACHER, + SYNCHRO, + } + + + //pour lancer automatiquement le plugin sur l'écran de choix profil (lancement d'une application TRANS3). Laissez à false pour le prefab ! + public bool sceneStart = false; + + public APP_ID appID = APP_ID.NONE;//choix de l'app concernée, à modifier via Inspector + + [HideInInspector] + public static NAV_CONTEXT navContext = NAV_CONTEXT.NONE; + [HideInInspector] + public int navMaxID = 0; + + public string sceneNameAfterLogin = ""; + public UnityEvent callbackSecondChildLogin; + public UnityEvent onAppSettingCancel; + public UnityEvent onAppSettingEnd; + public UnityEvent<List<string>, List<string>, List<string>> onSynchroEnd; + + public List<Sprite> childAvatars = new List<Sprite>(); + + public TextMeshProUGUI appName; + public Image appImage; + public TextMeshProUGUI appVersion; + + public List<Sprite> appsImages = new List<Sprite>(); + + public bool isActive = false; + private int isActiveCpt = 0; + + [HideInInspector] + public Image colorDeviceInfo = null; + +#if UNITY_ANDROID && !UNITY_EDITOR + private AndroidJavaObject androidVersion = null; +#endif + + public void CheckAndroidPermissions(bool force = false) + { + int alreadyAsked = PlayerPrefs.GetInt("HM_BluetoothPermissions", -1); + + var callbacks = new PermissionCallbacks(); + callbacks.PermissionDenied += PermissionCallbacks_PermissionDenied; + callbacks.PermissionGranted += PermissionCallbacks_PermissionGranted; + callbacks.PermissionDeniedAndDontAskAgain += PermissionCallbacks_PermissionDeniedAndDontAskAgain; + + if (force || alreadyAsked <= 0)//demande de permission + { +#if UNITY_ANDROID && !UNITY_EDITOR + int sdkVersion = androidVersion.GetStatic<int>("SDK_INT"); +#else + int sdkVersion = 31; +#endif + + if (sdkVersion >= 31) + { + if (!Permission.HasUserAuthorizedPermission("android.permission.BLUETOOTH_SCAN")) + { + Permission.RequestUserPermission("android.permission.BLUETOOTH_SCAN", callbacks); + } + else + { + if (!Permission.HasUserAuthorizedPermission("android.permission.BLUETOOTH_ADVERTISE")) + { + Permission.RequestUserPermission("android.permission.BLUETOOTH_ADVERTISE", callbacks); + } + else + { + if (!Permission.HasUserAuthorizedPermission("android.permission.BLUETOOTH_CONNECT")) + { + Permission.RequestUserPermission("android.permission.BLUETOOTH_CONNECT", callbacks); + } + else + { + PlayerPrefs.SetInt("HM_BluetoothPermissions", 2); + } + } + } + } + else + { + if (!Permission.HasUserAuthorizedPermission("android.permission.ACCESS_FINE_LOCATION")) + { + Permission.RequestUserPermission("android.permission.ACCESS_FINE_LOCATION", callbacks); + } + else + { + if (!Permission.HasUserAuthorizedPermission("android.permission.BLUETOOTH")) + { + Permission.RequestUserPermission("android.permission.BLUETOOTH", callbacks); + } + else + { + PlayerPrefs.SetInt("HM_BluetoothPermissions", 2); + } + } + } + + } + } + + public bool HasAndroidBluetoothPermissions() + { +#if UNITY_ANDROID && !UNITY_EDITOR + int sdkVersion = androidVersion.GetStatic<int>("SDK_INT"); +#else + int sdkVersion = 31; +#endif + + if (sdkVersion >= 31) + { + if (Permission.HasUserAuthorizedPermission("android.permission.BLUETOOTH_SCAN") + && Permission.HasUserAuthorizedPermission("android.permission.BLUETOOTH_ADVERTISE") + && Permission.HasUserAuthorizedPermission("android.permission.BLUETOOTH_CONNECT")) + { + return true; + } + } + else + { + if (Permission.HasUserAuthorizedPermission("android.permission.ACCESS_FINE_LOCATION") + && Permission.HasUserAuthorizedPermission("android.permission.BLUETOOTH")) + { + return true; + } + } + + return false; + } + + + private void PermissionCallbacks_PermissionDenied(string permissionName) + { + PlayerPrefs.SetInt("HM_BluetoothPermissions", 1); + } + + private void PermissionCallbacks_PermissionGranted(string permissionName) + { + CheckAndroidPermissions(true); + } + + private void PermissionCallbacks_PermissionDeniedAndDontAskAgain(string permissionName) + { + PlayerPrefs.SetInt("HM_BluetoothPermissions", 0); + } + + void Awake() + { + HM_Scripts.Initialize(); + + //HM_Model.Initialize(); + +#if UNITY_ANDROID && !UNITY_EDITOR + androidVersion = new AndroidJavaObject("android.os.Build$VERSION"); + CheckAndroidPermissions(); +#endif + + if (sceneStart) + { + HM_Log.ReplaceTextFile("HM_Log.txt", ""); + HM_Log.ReplaceTextFile("HM_LogResult.txt", ""); + + //Debug.Log("Load"); + HM_Model.Load(); + HM_Scripts.optionPanel.UpdateData(); + HM_Scripts.debugPanel.buttonSwitchPanel.gameObject.SetActive(true); + + } + else + { + HM_Scripts.debugPanel.buttonSwitchPanel.gameObject.SetActive(false); + } + + isActive = false; + isActiveCpt = 0; + + //l'appID est sensé exister dans un contexte normal. Il doit étre renseigner sur chaque instance de HM_PluginController existant dans le projet + //(dans la scéne HM_SceneStart et sur toutes les instances prefabs utilisés dans les scénes de l'application) + if (appID == APP_ID.NONE) + { + Debug.LogWarning("Un script HM_PluginController n'a pas été configuré pour une app en particulier. Merci de renseigner l'app !"); + } + + colorDeviceInfo = GameObject.Find("HM_ColorDeviceInfo").GetComponent<Image>(); + + switch (HM_DataController.model.currentColorID) + { + case 1: + colorDeviceInfo.color = new Color32(246, 115, 172, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "A"; + break; + case 2: + colorDeviceInfo.color = new Color32(155, 47, 174, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "B"; + break; + case 3: + colorDeviceInfo.color = new Color32(64, 84, 178, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "C"; + break; + case 4: + colorDeviceInfo.color = new Color32(29, 170, 241, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "D"; + break; + case 5: + colorDeviceInfo.color = new Color32(31, 188, 210, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "E"; + break; + case 6: + colorDeviceInfo.color = new Color32(80, 174, 85, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "F"; + break; + case 7: + colorDeviceInfo.color = new Color32(205, 218, 73, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "G"; + break; + case 8: + colorDeviceInfo.color = new Color32(253, 192, 47, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "H"; + break; + case 9: + colorDeviceInfo.color = new Color32(164, 125, 112, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "I"; + break; + case 10: + colorDeviceInfo.color = new Color32(97, 125, 138, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "J"; + break; + case 11: + colorDeviceInfo.color = new Color32(255, 140, 120, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "K"; + break; + case 12: + colorDeviceInfo.color = new Color32(0, 121, 135, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "L"; + break; + case 13: + colorDeviceInfo.color = new Color32(30, 223, 145, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "M"; + break; + case 14: + colorDeviceInfo.color = new Color32(201, 130, 255, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "N"; + break; + case 15: + colorDeviceInfo.color = new Color32(255, 49, 49, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "O"; + break; + case 16: + colorDeviceInfo.color = new Color32(68, 74, 255, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "P"; + break; + case 17: + colorDeviceInfo.color = new Color32(255, 110, 13, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Q"; + break; + case 18: + colorDeviceInfo.color = new Color32(84, 67, 59, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "R"; + break; + case 19: + colorDeviceInfo.color = new Color32(37, 96, 58, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "S"; + break; + case 20: + colorDeviceInfo.color = new Color32(36, 28, 110, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "T"; + break; + case 21: + colorDeviceInfo.color = new Color32(168, 94, 94, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "U"; + break; + case 22: + colorDeviceInfo.color = new Color32(128, 94, 168, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "V"; + break; + case 23: + colorDeviceInfo.color = new Color32(126, 74, 74, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "W"; + break; + case 24: + colorDeviceInfo.color = new Color32(131, 183, 151, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "X"; + break; + case 25: + colorDeviceInfo.color = new Color32(226, 132, 74, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Y"; + break; + case 26: + colorDeviceInfo.color = new Color32(255, 68, 212, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Z"; + break; + case 27: + colorDeviceInfo.color = new Color32(127, 47, 235, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Δ"; + break; + case 28: + colorDeviceInfo.color = new Color32(95, 95, 95, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Θ"; + break; + case 29: + colorDeviceInfo.color = new Color32(97, 158, 196, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Ξ"; + break; + case 30: + colorDeviceInfo.color = new Color32(214, 167, 113, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Φ"; + break; + case 31: + colorDeviceInfo.color = new Color32(123, 53, 110, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Ψ"; + break; + case 32: + colorDeviceInfo.color = new Color32(89, 96, 1, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "Ω"; + break; + case -1: + colorDeviceInfo.color = new Color32(200, 200, 200, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "-"; + break; + default: + colorDeviceInfo.color = new Color32(200, 200, 200, 255); + colorDeviceInfo.transform.GetChild(0).GetComponent<TextMeshProUGUI>().text = "-"; + break; + } + + HM_Content.contentBackgroundCG = GameObject.FindGameObjectsWithTag("HM_ContentBackground")[0].GetComponent<CanvasGroup>(); + HM_Content.contentBackgroundCG.alpha = 0; + HM_Content.contentBackgroundCG.interactable = false; + HM_Content.contentBackgroundCG.blocksRaycasts = false; + + HM_Content.popupBackgroundCG = GameObject.FindGameObjectsWithTag("HM_PopupBackground")[0].GetComponent<CanvasGroup>(); + HM_Content.popupBackgroundCG.alpha = 0; + HM_Content.popupBackgroundCG.interactable = false; + HM_Content.popupBackgroundCG.blocksRaycasts = false; + + switch(appID) + { + case APP_ID.ELARGIR: + appName.text = "Elargir"; + appImage.sprite = appsImages[0]; + break; + case APP_ID.EVASION: + appName.text = "Evasion"; + appImage.sprite = appsImages[1]; + break; + case APP_ID.LUCIOLE: + appName.text = "Luciole"; + appImage.sprite = appsImages[2]; + break; + case APP_ID.EVALULU: + appName.text = "EvaLulu"; + appImage.sprite = appsImages[3]; + break; + default: + appName.text = "APP NAME"; + appImage.sprite = null; + break; + } + + appVersion.text = "v" + Application.version; + + HM_Scripts.pluginController = this; + + if (!sceneStart) + { + StopPlugin(); + } + } + + void Start() + { + if (HM_NetworkController.currentENV == HM_NetworkController.ENV.DEVELOP) + GameObject.Find("HM_TextVersion").GetComponent<TextMeshProUGUI>().text = "v1.6.5 - DEVELOP"; + else if (HM_NetworkController.currentENV == HM_NetworkController.ENV.PREPROD) + GameObject.Find("HM_TextVersion").GetComponent<TextMeshProUGUI>().text = "v1.6.5 - PREPROD"; + else + GameObject.Find("HM_TextVersion").GetComponent<TextMeshProUGUI>().text = "v1.6.5 - PROD"; + + HM_Scripts.optionPanel.HideButton(true); + + //si démarrage auto, on lance le contenu de choix du profil enfant + if (sceneStart) + { + switch (appID) + { + case APP_ID.ELARGIR: + //tente d'envoyer les données Audio Elargir en attente (si il y en a) + HM_NetworkController.instance.SendAudioData(); + break; + } + + if (HM_DataController.model.teacherAccounts.Count == 0) + { + navContext = NAV_CONTEXT.NEW_TEACHER; + HM_Scripts.contentCodeTeacher.OpenContent(); + } + else + { + HM_DataController.currentChildUser = null; + HM_DataController.currentTeacherAccount = null; + + bool synchroNeeded = false; + + foreach(HM_TeacherAccount t in HM_DataController.model.teacherAccounts) + { + if(t.dataAWS._idToken != null && t.dataAWS._idToken.Length > 0) + { + synchroNeeded = true; + break; + } + } + + if(synchroNeeded && Application.internetReachability != NetworkReachability.NotReachable) + { + HM_Scripts.contentRefreshAWS.OpenContent(); + } + else + { + HM_Scripts.contentProfil.OpenContent(); + } + + } + + } + } + + //Active le Plugin sur un contenu en particulier (ne devrait étre appelé que par le plugin lui méme) + public void StartPlugin(HM_Content content = null) + { + //this.gameObject.SetActive(true); + isActive = true; + isActiveCpt++; + + if(content != null) + { + content.OpenContent(); + } + } + + //Met en pause le Plugin (ne devrait étre appelé que par le plugin lui méme) + public void StopPlugin() + { + //this.gameObject.SetActive(false); + isActiveCpt--; + + if(isActiveCpt <= 0) + { + isActiveCpt = 0; + isActive = false; + + HM_Content.contentBackgroundCG.alpha = 0; + HM_Content.contentBackgroundCG.interactable = false; + HM_Content.contentBackgroundCG.blocksRaycasts = false; + + HM_Content.popupBackgroundCG.alpha = 0; + HM_Content.popupBackgroundCG.interactable = false; + HM_Content.popupBackgroundCG.blocksRaycasts = false; + } + } + + + public bool CheckTeacherCodeValid(string code) + { + //calcul checksum + int checksum = ChecksumTeacherCode(code); + + //vérification si 6ème lettre OK + if (code[5] == (char)('A' + checksum)) + { + return true; + } + + return false; + } + + private int ChecksumTeacherCode(string code) + { + int checksum = 0; + + //checkum via calcul "(1 * lettre1 + 2 * lettre2 + 3 * lettre3 + 4 * lettre4 + 5 * lettre5) modulo 26" + //lettre1~5 étant la position du caractère dans l'alphabet : A=1, B=2, ... + + for (int j = 0; j < 5; j++) + { + checksum += (j + 1) * (int)(code[j] - 64); //-64 pour retrouver la bonne position en partant de A=1 + } + + checksum = checksum % 26;// 0 to 25 + + return checksum; + } + + + + /// <summary> + /// Les fonctions suivantes sont les points d'entrée pour utilisation de ce plugin HM + /// </summary> + + //Démarre le Plugin sur le contenu pour identifier un profil enfant de type "évaluateur", différent du profil actuellement connecté + //Utilisation type : Application Elargir si demande d'évaluation par un pair pour un texte + public static void OpenLoginSecondaryChild() + { + //le profilID est sensé exister dans un contexte normal, car il aura été renseigné via la scéne de démarrage HM_SceneStart + + //on lance la page de choix du profil + HM_Scripts.pluginController.StartPlugin(HM_Scripts.contentProfil); + } + + //Démarre le Plugin sur le contenu pour identifier un professeur afin de configurer l'enfant actuellement connecté + public static void OpenTeacherAdmin(int contextID = -1) + { + //l'appID est sensé exister dans un contexte normal. Il doit étre renseigner sur chaque instance de HM_PluginController existant dans le projet + //(dans la scéne HM_SceneStart et sur toutes les instances prefabs utilisés dans les scénes de l'application) + + if(HM_Scripts.pluginController.appID == APP_ID.NONE) + { + Debug.LogError("Pas de paramétrage possible sans avoir indiqué l'app concernée sur le script HM_PluginController via l'Inspector"); + HM_Log.AppendTextToFile("HM_Log.txt", "OpenTeacherAdmin error : Pas de paramétrage possible sans avoir indiqué l'app concernée sur le script HM_PluginController via l'Inspector"); + return; + } + else if(HM_Scripts.pluginController.appID == APP_ID.EVASION || HM_Scripts.pluginController.appID == APP_ID.EVALULU) + { + Debug.LogError("Pas de paramétrage possible pour cette application"); + HM_Log.AppendTextToFile("HM_Log.txt", "OpenTeacherAdmin error : Pas de paramétrage possible pour cette application"); + return; + } + + switch(HM_Scripts.pluginController.appID) + { + case APP_ID.ELARGIR: + HM_ContentSettingApp_Elargir.contextID = contextID; + break; + case APP_ID.LUCIOLE: + HM_ContentSettingApp_Luciole.contextID = contextID; + break; + } + + //le currentChildUser est sensé exister dans un contexte normal, car il aura été renseigné via la scéne de démarrage HM_SceneStart + if (HM_DataController.currentChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "OpenTeacherAdmin error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return; + } + + //on lance la page de demande du code enseignant + HM_Scripts.pluginController.StartPlugin(HM_Scripts.contentCodeTeacher); + } + + public static void DisconnectUser() + { + HM_Scripts.pluginController.StartPlugin(HM_Scripts.popupAlertDisconnect); + } + + public void DeleteSaveData() + { + HM_DataController.model.DeleteSaveData(); + } + + public static string GetMainUserID() + { + if (HM_DataController.currentChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetMainUserID error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return ""; + } + + return HM_DataController.currentChildUser.userID; + } + + public static string GetSecondUserID() + { + if (HM_DataController.secondaryChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant secondaire actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetSecondUserID error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return ""; + } + + return HM_DataController.secondaryChildUser.userID; + } + + public static string GetProgression() + { + if (HM_DataController.currentChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetProgression error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return ""; + } + + if (HM_Scripts.pluginController.appID == APP_ID.NONE) + { + Debug.LogWarning("Un script HM_PluginController n'a pas été configuré pour une app en particulier. Merci de renseigner l'app !"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetProgression error : Un script HM_PluginController n'a pas été configuré pour une app en particulier."); + return ""; + } + else if (HM_Scripts.pluginController.appID == APP_ID.EVALULU) + { + Debug.LogError("Cette application n'a pas été configuré pour utiliser cette fonction"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetProgression error : Cette application n'a pas été configuré pour utiliser cette fonction"); + return ""; + } + + switch (HM_Scripts.pluginController.appID) + { + case APP_ID.ELARGIR: + return JsonConvert.SerializeObject(HM_DataController.currentChildUser.appElargirUserData.progression); + case APP_ID.LUCIOLE: + return JsonConvert.SerializeObject(HM_DataController.currentChildUser.appLucioleUserData.progression); + case APP_ID.EVASION: + return JsonConvert.SerializeObject(HM_DataController.currentChildUser.appEvasionUserData.progression); + } + + return ""; + } + + public static void SetProgression(string jsonProgression) + { + if(HM_DataController.currentChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "SetProgression error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return; + } + + if (HM_Scripts.pluginController.appID == APP_ID.NONE) + { + Debug.LogWarning("Un script HM_PluginController n'a pas été configuré pour une app en particulier. Merci de renseigner l'app !"); + HM_Log.AppendTextToFile("HM_Log.txt", "SetProgression error : Un script HM_PluginController n'a pas été configuré pour une app en particulier."); + return; + } + else if (HM_Scripts.pluginController.appID == APP_ID.EVALULU) + { + Debug.LogError("Cette application n'a pas été configuré pour utiliser cette fonction"); + HM_Log.AppendTextToFile("HM_Log.txt", "SetProgression error : Cette application n'a pas été configuré pour utiliser cette fonction"); + return; + } + + try + { + switch (HM_Scripts.pluginController.appID) + { + case APP_ID.ELARGIR: + //cas particulier : on remet settings.difficultyMode à 0 + HM_DataController.currentChildUser.appElargirUserData.settings.difficultyMode = 0; + HM_DataController.currentChildUser.appElargirUserData.settings.revisionDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + + HM_DataController.currentChildUser.appElargirUserData.progression = JsonConvert.DeserializeObject<HM_AppElargirUserProgression>(jsonProgression); + HM_DataController.currentChildUser.appElargirUserData.progression.dateUpdate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + break; + case APP_ID.LUCIOLE: + HM_DataController.currentChildUser.appLucioleUserData.progression = JsonConvert.DeserializeObject<HM_AppLucioleUserProgression>(jsonProgression); + HM_DataController.currentChildUser.appLucioleUserData.progression.dateUpdate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + break; + case APP_ID.EVASION: + HM_DataController.currentChildUser.appEvasionUserData.progression = JsonConvert.DeserializeObject<HM_AppEvasionUserProgression>(jsonProgression); + HM_DataController.currentChildUser.appEvasionUserData.progression.dateUpdate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + break; + } + } + catch (Exception e) + { + Debug.LogError("SetProgression jsonProgression Deserialize ERROR : " + e.Message); + HM_Log.AppendTextToFile("HM_Log.txt", "SetProgression jsonProgression Deserialize ERROR : " + e.Message); + } + + HM_DataController.model.Save(); + } + + public static string GetSettingsSession() + { + if (HM_DataController.currentChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetSettingsSession error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return ""; + } + + if (HM_Scripts.pluginController.appID == APP_ID.NONE) + { + Debug.LogWarning("Un script HM_PluginController n'a pas été configuré pour une app en particulier. Merci de renseigner l'app !"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetSettingsSession error : Un script HM_PluginController n'a pas été configuré pour une app en particulier."); + return ""; + } + else if (HM_Scripts.pluginController.appID == APP_ID.EVALULU) + { + Debug.LogError("Cette application n'a pas été configuré pour utiliser cette fonction"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetSettingsSession error : Cette application n'a pas été configuré pour utiliser cette fonction"); + return ""; + } + + switch (HM_Scripts.pluginController.appID) + { + case APP_ID.ELARGIR: + return JsonConvert.SerializeObject(HM_DataController.currentChildUser.appElargirUserData.settings); + case APP_ID.LUCIOLE: + return JsonConvert.SerializeObject(HM_DataController.currentChildUser.appLucioleUserData.settings); + case APP_ID.EVASION: + return JsonConvert.SerializeObject(HM_DataController.currentChildUser.appEvasionUserData.settings); + } + + return ""; + } + + public static void SetSettingsSession(string jsonSettings) + { + if (HM_DataController.currentChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "SetSettingsSession error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return; + } + + if (HM_Scripts.pluginController.appID == APP_ID.NONE) + { + Debug.LogWarning("Un script HM_PluginController n'a pas été configuré pour une app en particulier. Merci de renseigner l'app !"); + HM_Log.AppendTextToFile("HM_Log.txt", "SetSettingsSession error : Un script HM_PluginController n'a pas été configuré pour une app en particulier."); + return; + } + else if (HM_Scripts.pluginController.appID == APP_ID.EVALULU) + { + Debug.LogError("Cette application n'a pas été configuré pour utiliser cette fonction"); + HM_Log.AppendTextToFile("HM_Log.txt", "SetSettingsSession error : Cette application n'a pas été configuré pour utiliser cette fonction"); + return; + } + + try + { + switch (HM_Scripts.pluginController.appID) + { + case APP_ID.ELARGIR: + HM_DataController.currentChildUser.appElargirUserData.settings = JsonConvert.DeserializeObject<HM_AppElargirUserSettings>(jsonSettings); + HM_DataController.currentChildUser.appElargirUserData.settings.revisionDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + break; + case APP_ID.LUCIOLE: + HM_DataController.currentChildUser.appLucioleUserData.settings = JsonConvert.DeserializeObject<HM_AppLucioleUserSettings>(jsonSettings); + HM_DataController.currentChildUser.appLucioleUserData.settings.revisionDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + break; + case APP_ID.EVASION: + HM_DataController.currentChildUser.appEvasionUserData.settings = JsonConvert.DeserializeObject<HM_AppEvasionUserSettings>(jsonSettings); + HM_DataController.currentChildUser.appEvasionUserData.settings.revisionDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + break; + } + } + catch (Exception e) + { + Debug.LogError("SetSettingsSession jsonSettings Deserialize ERROR : " + e.Message); + HM_Log.AppendTextToFile("HM_Log.txt", "SetSettingsSession jsonSettings Deserialize ERROR : " + e.Message); + } + + HM_DataController.model.Save(); + } + + + public static void AddResultData(string jsonProgression, float playDuration, string jsonResult) + { + if (HM_DataController.currentChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return; + } + + if (HM_Scripts.pluginController.appID == APP_ID.NONE) + { + Debug.LogWarning("Un script HM_PluginController n'a pas été configuré pour une app en particulier. Merci de renseigner l'app !"); + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData error : Un script HM_PluginController n'a pas été configuré pour une app en particulier."); + return; + } + else if (HM_Scripts.pluginController.appID == APP_ID.EVALULU) + { + Debug.LogError("Cette application n'a pas été configuré pour utiliser cette fonction"); + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData error : Cette application n'a pas été configuré pour utiliser cette fonction"); + return; + } + + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData playDuration reçu : " + playDuration); + SetProgression(jsonProgression); + + switch (HM_Scripts.pluginController.appID) + { + case APP_ID.EVASION: + HM_AppEvasionUserResult resultEvasion = new HM_AppEvasionUserResult(); + resultEvasion.activityId = 834; + resultEvasion.resultId = System.Guid.NewGuid().ToString(); + resultEvasion.userId = HM_DataController.currentChildUser.userID; + resultEvasion.globalDuration = Time.realtimeSinceStartup; + resultEvasion.playDuration = playDuration; + resultEvasion.playDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + resultEvasion.taskId = HM_AppEvasionUserResult.taskId_session; + resultEvasion.revisionDate = resultEvasion.playDate; + try + { + JObject o = JObject.Parse(jsonResult); + + //si à tout hasard contient une valeur "appData", cela veut dire qu'on doit désérialiser dans HM_AppEvasionUserResult + if (o.ContainsKey("appData")) + { + HM_AppEvasionUserResult resultEvasionTemp = JsonConvert.DeserializeObject<HM_AppEvasionUserResult>(jsonResult); + resultEvasion.appData = resultEvasionTemp.appData; + } + else//sinon on désérialise dans HM_AppEvasionUserResult_SessionData + { + HM_AppEvasionUserResult_SessionData appDataEvasionTemp = JsonConvert.DeserializeObject<HM_AppEvasionUserResult_SessionData>(jsonResult); + resultEvasion.appData = appDataEvasionTemp; + } + HM_DataController.currentChildUser.appEvasionUserData.results.Add(resultEvasion); + HM_Log.AppendTextToFile("HM_LogResult.txt", JsonConvert.SerializeObject(resultEvasion)); + } + catch(Exception e) + { + Debug.LogError("AddResultData jsonResult Deserialize ERROR : "+e.Message); + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData jsonResult Deserialize ERROR : " + e.Message); + } + break; + case APP_ID.ELARGIR: + //cas particulier : on remet settings.difficultyMode à 0 + HM_DataController.currentChildUser.appElargirUserData.settings.difficultyMode = 0; + HM_DataController.currentChildUser.appElargirUserData.settings.revisionDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + + HM_AppElargirUserResult resultElargir = new HM_AppElargirUserResult(); + resultElargir.activityId = 835; + resultElargir.resultId = System.Guid.NewGuid().ToString(); + resultElargir.userId = HM_DataController.currentChildUser.userID; + resultElargir.globalDuration = Time.realtimeSinceStartup; + resultElargir.playDuration = playDuration; + resultElargir.playDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + resultElargir.taskId = HM_AppElargirUserResult.taskId_session; + resultElargir.revisionDate = resultElargir.playDate; + try + { + + JObject o = JObject.Parse(jsonResult); + + //si à tout hasard contient une valeur "appData", cela veut dire qu'on doit désérialiser dans HM_AppElargirUserResult + if (o.ContainsKey("appData")) + { + HM_AppElargirUserResult resultElargirTemp = JsonConvert.DeserializeObject<HM_AppElargirUserResult>(jsonResult); + resultElargir.appData = resultElargirTemp.appData; + } + else//sinon on désérialise dans HM_AppElargirUserResult_SessionData + { + HM_AppElargirUserResult_SessionData appDataElargirTemp = JsonConvert.DeserializeObject<HM_AppElargirUserResult_SessionData>(jsonResult); + resultElargir.appData = appDataElargirTemp; + + } + + //audio présent + if (resultElargir.appData.audio != null && resultElargir.appData.audio.Length > 0 && resultElargir.appData.audio.Split('/').Length > 0) + { + List<HM_DataAudio> audioPending = new List<HM_DataAudio>(); + string audioData = PlayerPrefs.GetString("HM_DataAudio", ""); + + if (audioData != null && audioData.Length > 0) + { + audioPending = JsonConvert.DeserializeObject<List<HM_DataAudio>>(audioData); + } + + string filename = resultElargir.appData.audio.Split('/')[resultElargir.appData.audio.Split('/').Length - 1]; + + HM_DataAudio da = new HM_DataAudio(); + da.localPath = resultElargir.appData.audio; + da.filename = filename; + da.resultID = resultElargir.resultId; + da.childIconID = HM_DataController.currentChildUser.userIconID; + da.childCode = HM_DataController.currentChildUser.loginCode; + da.teacherCode = HM_DataController.currentTeacherAccount.teacherCode; + + resultElargir.appData.audioLink = "audios/" + da.childIconID + "/" + da.childCode + "/" + da.resultID + "/" + da.filename; + + audioPending.Add(da); + + PlayerPrefs.SetString("HM_DataAudio", JsonConvert.SerializeObject(audioPending)); + } + + + HM_DataController.currentChildUser.appElargirUserData.results.Add(resultElargir); + HM_Log.AppendTextToFile("HM_LogResult.txt", JsonConvert.SerializeObject(resultElargir)); + } + catch (Exception e) + { + Debug.LogError("AddResultData jsonResult Deserialize ERROR : " + e.Message); + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData jsonResult Deserialize ERROR : " + e.Message); + } + break; + case APP_ID.LUCIOLE: + HM_AppLucioleUserResult resultLuciole = new HM_AppLucioleUserResult(); + resultLuciole.activityId = 836; + resultLuciole.resultId = System.Guid.NewGuid().ToString(); + resultLuciole.userId = HM_DataController.currentChildUser.userID; + resultLuciole.globalDuration = Time.realtimeSinceStartup; + resultLuciole.playDuration = playDuration; + resultLuciole.playDate = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssK"); + resultLuciole.taskId = HM_AppLucioleUserResult.taskId_session; + resultLuciole.revisionDate = resultLuciole.playDate; + resultLuciole.appData.parcours = HM_DataController.currentChildUser.appLucioleUserData.settings.parcours; + resultLuciole.appData.avancementGlobal = HM_DataController.currentChildUser.appLucioleUserData.progression.lucioleParameters.avancementGlobal; + resultLuciole.appData.avancementCurrentMission = HM_DataController.currentChildUser.appLucioleUserData.progression.lucioleParameters.avancementCurrentMission; + resultLuciole.appData.nbrEtoilesGain = HM_DataController.currentChildUser.appLucioleUserData.progression.lucioleParameters.nbrEtoilesGain; + resultLuciole.appData.nbrEtoilesTotal = HM_DataController.currentChildUser.appLucioleUserData.progression.lucioleParameters.nbrEtoilesTotal; + resultLuciole.appData.currentGrade = HM_DataController.currentChildUser.appLucioleUserData.progression.lucioleParameters.currentGrade; + try + { + JObject o = JObject.Parse(jsonResult); + + //si à tout hasard contient une valeur "appData", cela veut dire qu'on doit désérialiser dans HM_AppLucioleUserResult + if (o.ContainsKey("appData")) + { + HM_AppLucioleUserResult resultLucioleTemp = JsonConvert.DeserializeObject<HM_AppLucioleUserResult>(jsonResult); + resultLuciole.appData = resultLucioleTemp.appData; + } + else//sinon on désérialise dans HM_AppLucioleUserResult_SessionData + { + HM_AppLucioleUserResult_SessionData appDataLuciolerTemp = JsonConvert.DeserializeObject<HM_AppLucioleUserResult_SessionData>(jsonResult); + resultLuciole.appData = appDataLuciolerTemp; + + } + HM_DataController.currentChildUser.appLucioleUserData.results.Add(resultLuciole); + HM_Log.AppendTextToFile("HM_LogResult.txt", JsonConvert.SerializeObject(resultLuciole)); + } + catch (Exception e) + { + Debug.LogError("AddResultData jsonResult Deserialize ERROR : " + e.Message); + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData jsonResult Deserialize ERROR : " + e.Message); + } + break; + } + + HM_DataController.model.Save(); + + } + + public static void AddResultDataAdmin(string jsonProgression, float playDuration, string jsonResult, int addJours = 0, int addMinutes = 0) + { + SetProgression(jsonProgression); + + switch (HM_Scripts.pluginController.appID) + { + case APP_ID.EVASION: + HM_AppEvasionUserResult resultEvasion = new HM_AppEvasionUserResult(); + resultEvasion.activityId = 834; + resultEvasion.resultId = System.Guid.NewGuid().ToString(); + resultEvasion.userId = HM_DataController.currentChildUser.userID; + resultEvasion.globalDuration = Time.realtimeSinceStartup; + resultEvasion.playDuration = playDuration; + resultEvasion.playDate = DateTime.UtcNow.AddDays(-addJours).AddMinutes(addMinutes).ToString("yyyy-MM-ddTHH:mm:ssK"); + resultEvasion.revisionDate = resultEvasion.playDate; + try + { + HM_AppEvasionUserResult resultEvasionTemp = JsonConvert.DeserializeObject<HM_AppEvasionUserResult>(jsonResult); + resultEvasion.appData = resultEvasionTemp.appData; + resultEvasion.taskId = resultEvasionTemp.taskId; + Debug.Log(resultEvasion.taskId); + + HM_DataController.currentChildUser.appEvasionUserData.results.Add(resultEvasion); + HM_Log.AppendTextToFile("HM_LogResult.txt", JsonConvert.SerializeObject(resultEvasion)); + } + catch (Exception e) + { + Debug.LogError("AddResultData jsonResult Deserialize ERROR : " + e.Message); + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData jsonResult Deserialize ERROR : " + e.Message); + } + break; + case APP_ID.ELARGIR: + HM_AppElargirUserResult resultElargir = new HM_AppElargirUserResult(); + resultElargir.activityId = 835; + resultElargir.resultId = System.Guid.NewGuid().ToString(); + resultElargir.userId = HM_DataController.currentChildUser.userID; + resultElargir.globalDuration = Time.realtimeSinceStartup; + resultElargir.playDuration = playDuration; + resultElargir.playDate = DateTime.UtcNow.AddDays(-addJours).AddMinutes(addMinutes).ToString("yyyy-MM-ddTHH:mm:ssK"); + resultElargir.revisionDate = resultElargir.playDate; + try + { + HM_AppElargirUserResult resultElargirTemp = JsonConvert.DeserializeObject<HM_AppElargirUserResult>(jsonResult); + resultElargir.appData = resultElargirTemp.appData; + resultElargir.taskId = resultElargirTemp.taskId; + Debug.Log(resultElargir.taskId); + + //audio présent + if (resultElargir.appData.audio != null && resultElargir.appData.audio.Length > 0 && resultElargir.appData.audio.Split('/').Length > 0) + { + List<HM_DataAudio> audioPending = new List<HM_DataAudio>(); + string audioData = PlayerPrefs.GetString("HM_DataAudio", ""); + + if (audioData != null && audioData.Length > 0) + { + audioPending = JsonConvert.DeserializeObject<List<HM_DataAudio>>(audioData); + } + + resultElargir.appData.audio = resultElargir.appData.audio.Replace('\\', '/'); + + string filename = resultElargir.appData.audio.Split('/')[resultElargir.appData.audio.Split('/').Length - 1]; + + HM_DataAudio da = new HM_DataAudio(); + da.localPath = resultElargir.appData.audio; + da.filename = filename; + da.resultID = resultElargir.resultId; + da.childIconID = HM_DataController.currentChildUser.userIconID; + da.childCode = HM_DataController.currentChildUser.loginCode; + da.teacherCode = HM_DataController.currentTeacherAccount.teacherCode; + + resultElargir.appData.audioLink = "audios/" + da.childIconID + "/" + da.childCode + "/" + da.resultID + "/" + da.filename; + + audioPending.Add(da); + + Debug.Log(resultElargir.appData.audioLink); + + PlayerPrefs.SetString("HM_DataAudio", JsonConvert.SerializeObject(audioPending)); + + PlayerPrefs.Save(); + } + + HM_DataController.currentChildUser.appElargirUserData.results.Add(resultElargir); + HM_Log.AppendTextToFile("HM_LogResult.txt", JsonConvert.SerializeObject(resultElargir)); + } + catch (Exception e) + { + Debug.LogError("AddResultData jsonResult Deserialize ERROR : " + e.Message); + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData jsonResult Deserialize ERROR : " + e.Message); + } + break; + case APP_ID.LUCIOLE: + HM_AppLucioleUserResult resultLuciole = new HM_AppLucioleUserResult(); + resultLuciole.activityId = 836; + resultLuciole.resultId = System.Guid.NewGuid().ToString(); + resultLuciole.userId = HM_DataController.currentChildUser.userID; + resultLuciole.globalDuration = Time.realtimeSinceStartup; + resultLuciole.playDuration = playDuration; + resultLuciole.playDate = DateTime.UtcNow.AddDays(-addJours).AddMinutes(addMinutes).ToString("yyyy-MM-ddTHH:mm:ssK"); + resultLuciole.revisionDate = resultLuciole.playDate; + resultLuciole.appData.parcours = HM_DataController.currentChildUser.appLucioleUserData.settings.parcours; + resultLuciole.appData.avancementGlobal = HM_DataController.currentChildUser.appLucioleUserData.progression.lucioleParameters.avancementGlobal; + resultLuciole.appData.avancementCurrentMission = HM_DataController.currentChildUser.appLucioleUserData.progression.lucioleParameters.avancementCurrentMission; + resultLuciole.appData.nbrEtoilesGain = HM_DataController.currentChildUser.appLucioleUserData.progression.lucioleParameters.nbrEtoilesGain; + resultLuciole.appData.currentGrade = HM_DataController.currentChildUser.appLucioleUserData.progression.lucioleParameters.currentGrade; + try + { + HM_AppLucioleUserResult resultLucioleTemp = JsonConvert.DeserializeObject<HM_AppLucioleUserResult>(jsonResult); + resultLuciole.appData = resultLucioleTemp.appData; + resultLuciole.taskId = resultLucioleTemp.taskId; + Debug.Log(resultLuciole.taskId); + + HM_DataController.currentChildUser.appLucioleUserData.results.Add(resultLuciole); + HM_Log.AppendTextToFile("HM_LogResult.txt", JsonConvert.SerializeObject(resultLuciole)); + } + catch (Exception e) + { + Debug.LogError("AddResultData jsonResult Deserialize ERROR : " + e.Message); + HM_Log.AppendTextToFile("HM_Log.txt", "AddResultData jsonResult Deserialize ERROR : " + e.Message); + } + break; + } + + HM_DataController.model.Save(); + + } + + public static void ResetCurrentUser() + { + if (HM_DataController.currentChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "ResetCurrentUser error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return; + } + + switch (HM_Scripts.pluginController.appID) + { + case APP_ID.ELARGIR: + HM_AppElargirUserData baseDataElargir = new HM_AppElargirUserData(); + HM_DataController.currentChildUser.appElargirUserData = baseDataElargir; + break; + case APP_ID.LUCIOLE: + HM_AppLucioleUserData baseDataLuciole = new HM_AppLucioleUserData(); + HM_DataController.currentChildUser.appLucioleUserData = baseDataLuciole; + break; + case APP_ID.EVASION: + HM_AppEvasionUserData baseDataEvasion = new HM_AppEvasionUserData(); + HM_DataController.currentChildUser.appEvasionUserData = baseDataEvasion; + break; + } + + HM_DataController.model.Save(); + } + + public static string GetCurrentTeacherCode() + { + if (HM_DataController.currentChildUser == null) + { + Debug.LogError("Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetCurrentTeacherCode error : Le plugin HM ne retrouve pas l'enfant actuellement connecté"); + return null; + } + + if (HM_DataController.currentTeacherAccount == null) + { + Debug.LogError("Le plugin HM ne retrouve pas le professeur actuellement lié à l'enfant connecté"); + HM_Log.AppendTextToFile("HM_Log.txt", "GetCurrentTeacherCode error : Le plugin HM ne retrouve pas le professeur actuellement lié à l'enfant connecté"); + return null; + } + + return HM_DataController.currentTeacherAccount.teacherCode; + + } + + public static List<string> GetAllTeacherAccounts() + { + List<string> teacherCodes = new List<string>(); + + foreach(HM_TeacherAccount t in HM_DataController.model.teacherAccounts) + { + teacherCodes.Add(t.teacherCode); + } + + return teacherCodes; + } + + public static List<HM_ChildUser> GetAllActiveChildsOfTeacher(string teacherCode) + { + List<HM_ChildUser> activeChildAccount = new List<HM_ChildUser>(); + + foreach (HM_TeacherAccount t in HM_DataController.model.teacherAccounts) + { + if(t.teacherCode.ToUpper().Equals(teacherCode.ToUpper())) + { + foreach (HM_ChildUser c in t.childUsers) + { + if (c.activeUser) + { + activeChildAccount.Add(c); + } + } + return activeChildAccount; + } + } + + List<HM_ChildUser> childUsers = GetAllActiveChildsOfTeacher("ABCDEF"); + + foreach(HM_ChildUser child in childUsers) + { + Debug.Log(child.userIconID); + Debug.Log(child.loginCode); + } + + return null; + } + + public void TestSecondUserLoginSuccess() + { + Debug.Log("TestSecondUserLoginSuccess"); + Debug.Log(GetSecondUserID()); + } + public void TestAppSettingsCancel() + { + Debug.Log("TestAppSettingsCancel"); + Debug.Log(GetSettingsSession()); + } + + public void TestAppSettingsEnd() + { + Debug.Log("TestAppSettingsEnd"); + Debug.Log(GetSettingsSession()); + } + + public static void CheckTraceExist(string fileURL, System.Action<int,string> callback, int userIconId = -1, int userLoginCode = -1) + { + HM_Scripts.pluginController.StartPlugin(); + + HM_ReturnInfo returnInfo = new HM_ReturnInfo(); + + if (userIconId == -1 && userLoginCode == -1 && HM_DataController.currentChildUser == null) + { + returnInfo.code = -1; + returnInfo.message = "Le plugin HM ne retrouve pas l'enfant actuellement connecté"; + HM_Scripts.pluginController.StartCoroutine(OnCheckTraceExistResponse(returnInfo, callback)); + return; + } + + if (Application.internetReachability == NetworkReachability.NotReachable) + { + returnInfo.code = -2; + returnInfo.message = "Pas de connexion Internet détecté"; + HM_Scripts.pluginController.StartCoroutine(OnCheckTraceExistResponse(returnInfo, callback)); + return; + } + + if (HM_DataController.currentTeacherAccount.dataAWS._idToken == null + || HM_DataController.currentTeacherAccount.dataAWS._idToken.Length == 0 + || HM_DataController.currentTeacherAccount.dataAWS.identityId == null + || HM_DataController.currentTeacherAccount.dataAWS.identityId.Length == 0) + { + returnInfo.code = -3; + returnInfo.message = "Compte professeur non authentifié"; + HM_Scripts.pluginController.StartCoroutine(OnCheckTraceExistResponse(returnInfo, callback)); + return; + } + + if ((userIconId == -1 && userLoginCode != -1) || (userIconId != -1 && userLoginCode == -1)) + { + returnInfo.code = -4; + returnInfo.message = "Une des deux données userIconId ou userLoginCode n'est pas renseigné"; + HM_Scripts.pluginController.StartCoroutine(OnCheckTraceExistResponse(returnInfo, callback)); + return; + } + + fileURL = fileURL.Replace('\\', '/'); + + //construction URL + string filename = fileURL.Split('/')[fileURL.Split('/').Length - 1]; + string appName = ""; + switch (HM_Scripts.pluginController.appID) + { + case APP_ID.NONE: + appName = "none"; + break; + case APP_ID.LUCIOLE: + appName = "luciole"; + break; + case APP_ID.ELARGIR: + appName = "elargir"; + break; + case APP_ID.EVASION: + appName = "evasion"; + break; + case APP_ID.EVALULU: + appName = "evalulu"; + break; + } + + string serverPath = "private/" + HM_DataController.currentTeacherAccount.dataAWS.identityId + "/traces/" + appName + "/"; + + if (userIconId != -1 && userLoginCode != -1) + { + serverPath += userIconId + "/" + userLoginCode + "/" + filename; + } + else + { + serverPath += HM_DataController.currentChildUser.userIconID + "/" + HM_DataController.currentChildUser.loginCode + "/" + filename; + } + + Task.Run(async () => + { + returnInfo = await HM_NetworkController.instance.S3List_v2(serverPath); + + UnityMainThreadDispatcher.Instance().Enqueue(OnCheckTraceExistResponse(returnInfo, callback)); + }); + } + + private static IEnumerator OnCheckTraceExistResponse(HM_ReturnInfo returnInfo, System.Action<int, string> callback) + { + HM_Scripts.pluginController.StopPlugin(); + + if (returnInfo.code > 0) + { + callback.Invoke(1, "Le fichier a été trouvé sur le serveur"); + } + else if(returnInfo.code == 0) + { + callback.Invoke(0, "Le fichier n'a pas été trouvé sur le serveur"); + } + else + { + callback.Invoke(returnInfo.code, returnInfo.message); + + string logMsg = "OnCheckTraceExistResponse ERROR " + returnInfo.code + " / " + returnInfo.message; + Debug.LogError(logMsg); + HM_Log.AppendTextToFile("HM_Log.txt", logMsg); + } + + yield return null; + } + + public static void UploadTrace(string fileURL, System.Action<int, string> callback, int userIconId = -1, int userLoginCode = -1) + { + HM_Scripts.pluginController.StartPlugin(); + + HM_ReturnInfo returnInfo = new HM_ReturnInfo(); + + if (userIconId == -1 && userLoginCode == -1 && HM_DataController.currentChildUser == null) + { + returnInfo.code = -1; + returnInfo.message = "Le plugin HM ne retrouve pas l'enfant actuellement connecté"; + HM_Scripts.pluginController.StartCoroutine(OnUploadTraceResponse(returnInfo, callback)); + return; + } + + if (Application.internetReachability == NetworkReachability.NotReachable) + { + returnInfo.code = -2; + returnInfo.message = "Pas de connexion Internet détecté"; + HM_Scripts.pluginController.StartCoroutine(OnUploadTraceResponse(returnInfo, callback)); + return; + } + + if (HM_DataController.currentTeacherAccount.dataAWS._idToken == null + || HM_DataController.currentTeacherAccount.dataAWS._idToken.Length == 0 + || HM_DataController.currentTeacherAccount.dataAWS.identityId == null + || HM_DataController.currentTeacherAccount.dataAWS.identityId.Length == 0) + { + returnInfo.code = -3; + returnInfo.message = "Compte professeur non authentifié"; + HM_Scripts.pluginController.StartCoroutine(OnUploadTraceResponse(returnInfo, callback)); + return; + } + + if ((userIconId == -1 && userLoginCode != -1) || (userIconId != -1 && userLoginCode == -1)) + { + returnInfo.code = -4; + returnInfo.message = "Une des deux données userIconId ou userLoginCode n'est pas renseigné"; + HM_Scripts.pluginController.StartCoroutine(OnUploadTraceResponse(returnInfo, callback)); + return; + } + + fileURL = fileURL.Replace('\\', '/'); + + //construction URL + string filename = fileURL.Split('/')[fileURL.Split('/').Length - 1]; + string appName = ""; + switch (HM_Scripts.pluginController.appID) + { + case APP_ID.NONE: + appName = "none"; + break; + case APP_ID.LUCIOLE: + appName = "luciole"; + break; + case APP_ID.ELARGIR: + appName = "elargir"; + break; + case APP_ID.EVASION: + appName = "evasion"; + break; + case APP_ID.EVALULU: + appName = "evalulu"; + break; + } + + string serverPath = "private/" + HM_DataController.currentTeacherAccount.dataAWS.identityId + "/traces/" + appName + "/"; + + if (userIconId != -1 && userLoginCode != -1) + { + serverPath += userIconId + "/" + userLoginCode + "/" + filename; + } + else + { + serverPath += HM_DataController.currentChildUser.userIconID + "/" + HM_DataController.currentChildUser.loginCode + "/" + filename; + } + + Task.Run(async () => + { + returnInfo = await HM_NetworkController.instance.S3Upload_v2(fileURL,serverPath); + + UnityMainThreadDispatcher.Instance().Enqueue(OnUploadTraceResponse(returnInfo, callback)); + }); + } + + private static IEnumerator OnUploadTraceResponse(HM_ReturnInfo returnInfo, System.Action<int, string> callback) + { + HM_Scripts.pluginController.StopPlugin(); + + if (returnInfo.code == 0) + { + callback.Invoke(0, "Le fichier a bien été uploadé"); + } + else + { + callback.Invoke(returnInfo.code, returnInfo.message); + + string logMsg = "OnUploadTraceResponse ERROR " + returnInfo.code + " / " + returnInfo.message; + Debug.LogError(logMsg); + HM_Log.AppendTextToFile("HM_Log.txt", logMsg); + } + + yield return null; + } +} diff --git a/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs.bak.meta b/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs.bak.meta new file mode 100644 index 0000000000000000000000000000000000000000..b3f445e34722b31ed9f1e3c5495749bbbf0d6958 --- /dev/null +++ b/Assets/TRANS3_PluginHM/Scripts/Controllers/HM_PluginController.cs.bak.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 96322bb3e8a6cbc45b69365da6e31613 +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/uploadTraces.cs b/Assets/uploadTraces.cs index 5d389dac6632c2647079137b5f30c9f35e3342c7..38d22ce14dd3d4bed3c091fedcaf2f7f5e4a3240 100644 --- a/Assets/uploadTraces.cs +++ b/Assets/uploadTraces.cs @@ -2,6 +2,7 @@ using System; using System.Collections; using System.Collections.Generic; using System.IO; +using System.Linq; using UnityEngine; public static class uploadTraces @@ -9,9 +10,7 @@ public static class uploadTraces private static bool currentlySending = false; private static int nbOfFilesToUpload = 0; private static int nbOfFilesUploaded = 0; - private static bool currentlydoingAncientArchiveFolder; - private static string[] savedFilesWaitingToBeUploaded; - private static string[] savedFilesWaitingToBeUploadedFromAncientArchiveFolder; + private static List<String> savedFilesWaitingToBeUploaded; private static string pathDirectory; private static string pathDirectoryArchive; private static string PathDirectoryTemporary; @@ -31,44 +30,71 @@ public static class uploadTraces public string userIconID; } - public static void sendTraces (string thisTeacherCode, string loginCode) + + + public static void sendTraces (List<string> successSynchroAccount) { - Debug.LogError("sendTraces thisTeacherCode="+ thisTeacherCode+ " loginCode = "+ loginCode); + //Debug.LogError("sendTraces thisTeacherCode="+ thisTeacherCode+ " loginCode = "+ loginCode); pathDirectory = Application.persistentDataPath + "/newSystemeTraces/"; pathDirectoryArchive = Application.persistentDataPath + "/newSystemeTraces/ArchiveReal"; pathDirectoryArchiveAncien = Application.persistentDataPath + "/newSystemeTraces/Archive"; PathDirectoryTemporary = Application.persistentDataPath + "/newSystemeTraces/Temporary"; + + if (!currentlySending) { + + currentlySending = true; nbOfFilesToUpload = 0; nbOfFilesUploaded = 0; - currentlydoingAncientArchiveFolder = false; - savedFilesWaitingToBeUploaded = Directory.GetFiles(pathDirectory, "*.json"); // attention, ici on prend TOUT les fichiers sans distinction alors qu'il faudrait à minima check le enseignant ID + savedFilesWaitingToBeUploaded = new List<string>(); + savedFilesWaitingToBeUploaded.Clear(); + string[] savedFilesWaitingToBeUploaded_temp1 = Directory.GetFiles(pathDirectory, "*.json"); // attention, ici on prend TOUT les fichiers sans distinction alors qu'il faudrait à minima check le enseignant ID + string[] savedFilesWaitingToBeUploaded_inOldArciveFolder_temp = Directory.GetFiles(pathDirectoryArchiveAncien, "*.json"); // attention, ici on prend TOUT les fichiers sans distinction alors qu'il faudrait à minima check le enseignant ID + string[] savedFilesWaitingToBeUploaded_temp = savedFilesWaitingToBeUploaded_temp1.Concat(savedFilesWaitingToBeUploaded_inOldArciveFolder_temp).ToArray(); - foreach (string filePath in savedFilesWaitingToBeUploaded) + foreach (string teacheraccount in successSynchroAccount) { - // Lire le contenu du fichier JSON - string jsonContent = System.IO.File.ReadAllText(filePath); - - // Désérialiser le JSON en une instance de la classe - NewSystemeDeTracesJSONRoot data = JsonUtility.FromJson<NewSystemeDeTracesJSONRoot>(jsonContent); - - // Accéder aux propriétés nécessaires - string teacherCode = data.teacherCode; - string userID = data.userID; - string logincodeuser = data.loginCode; - // Faire quelque chose avec les valeurs, par exemple, les imprimer dans la console - - if (teacherCode== thisTeacherCode && logincodeuser == loginCode) + //Debug.LogError("account in successSynchroAccount = " + account); + List<HM_ChildUser> childUsers = HM_PluginController.GetAllActiveChildsOfTeacher(teacheraccount); + if (childUsers != null) { - Debug.LogError("bingo"); - Debug.Log($"Fichier : {filePath}, teacherCode : {teacherCode}, userID : {userID}"); + foreach (HM_ChildUser child in childUsers) + { + //Debug.Log("userIconID="+child.userIconID+ " loginCode="+ child.loginCode+ " userID="+ child.userID); + //si besoin ça c'est l'UUID qui est aussi renvoyé par la fonction "GetMainUserID" (au où tu l'utilisais pour identifier les élèves, permettra du coup de faire le lien) + foreach (string filePath in savedFilesWaitingToBeUploaded_temp) + { + // Lire le contenu du fichier JSON + string jsonContent = System.IO.File.ReadAllText(filePath); + + // Désérialiser le JSON en une instance de la classe + NewSystemeDeTracesJSONRoot data = JsonUtility.FromJson<NewSystemeDeTracesJSONRoot>(jsonContent); + + // Accéder aux propriétés nécessaires + string teacherCode = data.teacherCode; + string userID = data.userID; + string logincodeuser = data.loginCode; + // Faire quelque chose avec les valeurs, par exemple, les imprimer dans la console + + if (teacherCode == teacheraccount && logincodeuser == child.loginCode && userID == child.userID) + { + Debug.LogError("bingo"); + Debug.Log($"Fichier : {filePath}, teacherCode : {teacherCode}, userID : {userID}"); + savedFilesWaitingToBeUploaded.Add(filePath); + } + } + } } } + + + + Debug.Log("au final on a à uploader " + savedFilesWaitingToBeUploaded.Count + " fichiers"); - /* + if (!Directory.Exists(pathDirectoryArchive)) { Directory.CreateDirectory(pathDirectoryArchive); @@ -81,13 +107,14 @@ public static class uploadTraces { deleteTemporaryFiles(); } - nbOfFilesToUpload = savedFilesWaitingToBeUploaded.Length; + nbOfFilesToUpload = savedFilesWaitingToBeUploaded.Count; if (nbOfFilesToUpload > 0) { uploadOnefichierTraceToHM(); } - */ + + } currentlySending = false; } @@ -117,7 +144,7 @@ public static class uploadTraces private static void uploadOnefichierTraceToHM() { - if (nbOfFilesUploaded > savedFilesWaitingToBeUploaded.Length - 1) + if (nbOfFilesUploaded > savedFilesWaitingToBeUploaded.Count - 1) { endAllUploads(); } @@ -126,8 +153,16 @@ public static class uploadTraces currentlySentFilePath = savedFilesWaitingToBeUploaded[nbOfFilesUploaded]; // Le fichier JSON existe, donc nous le lisons string dateEnvoi = DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"); + string nouveauNomAvecDate = Path.GetFileNameWithoutExtension(currentlySentFilePath) + "-" + dateEnvoi + ".json"; + if (currentlySentFilePath.Contains("Archive")) + { + Debug.LogError("on traite une archive là"); + nouveauNomAvecDate = Path.GetFileNameWithoutExtension(currentlySentFilePath) + ".json"; + } + currentlySentTemporaryFilePath = Path.Combine(PathDirectoryTemporary, nouveauNomAvecDate); + Debug.Log("nouveauNomAvecDate = " + nouveauNomAvecDate+ " currentlySentTemporaryFilePath="+ currentlySentTemporaryFilePath); // Copiez le fichier source vers le dossier de destination en le renommant si nécessaire. File.Copy(currentlySentFilePath, currentlySentTemporaryFilePath, true); if (File.Exists(currentlySentTemporaryFilePath)) @@ -140,14 +175,14 @@ public static class uploadTraces catch (Exception ex) { // Gérez toute exception survenue lors de l'appel à CheckTraceExist ici. - ////Debug.LogError("Erreur lors de l'appel à UploadTrace : " + ex.Message); + Debug.LogError("Erreur lors de l'appel à UploadTrace : " + ex.Message); deletecurrentFileFromTemporaryFolder(false); endAllUploads(); } } else { - ////Debug.LogError("Traces 2 - ne devrait jamais arriver"); + Debug.LogError("Traces 2 - ne devrait jamais arriver"); deletecurrentFileFromTemporaryFolder(false); endAllUploads(); /* sauf si : @@ -211,7 +246,7 @@ public static class uploadTraces private static void uploadOneFileAsynchroneFinished(int resultCode, string resultMessage) { - ////Debug.LogError("resultCode=" + resultCode + " resultMessage=" + resultMessage+ " nombreDeFichiersTraites="+ nombreDeFichiersTraites+ " nombreDeFichiersATransferer="+ nombreDeFichiersATransferer+ " doingAncientArchiveFolderNow="+ doingAncientArchiveFolderNow); + Debug.LogError("resultCode=" + resultCode + " resultMessage=" + resultMessage+ " nombreDeFichiersTraites="+ nbOfFilesUploaded+ " nombreDeFichiersATransferer="+ nbOfFilesToUpload); ////Debug.Log("transfertAsynchroneFinished resultCode = " + resultCode.ToString() + " resultMessage=" + resultMessage + " nombreDeFichiersTraites = " + nombreDeFichiersTraites); if (resultCode == 1 || resultCode == 0) @@ -219,32 +254,18 @@ public static class uploadTraces deletecurrentFileFromTemporaryFolder(true); if (nbOfFilesUploaded == nbOfFilesToUpload - 1) { - // on a atteint le bout - if (!currentlydoingAncientArchiveFolder) - { - // ce dernier envoie s'est bien passé mais on n'a pas encore regardé les anciennes archives + nbOfFilesToUpload = 0; nbOfFilesUploaded = 0; currentlySending = false; - checkFilesInAncientArchiveFolder(); - } - else - { endAllUploads(); - } + } else { // le transfeet précédent c'est bien passé (retour == 0) on lance le fichier suivant nbOfFilesUploaded++; - if (!currentlydoingAncientArchiveFolder) - { - uploadOnefichierTraceToHM(); - } - else - { - uploadOnefichierAncientArchiveTraceToHM(); - } + uploadOnefichierTraceToHM(); } @@ -259,88 +280,12 @@ public static class uploadTraces } - private static void checkFilesInAncientArchiveFolder() - { - //Debug.LogError("moveAllFilesFromAncientArchiveFolderToRegularFolder"); - // Obtenez la liste de tous les fichiers dans le dossier spécifié. - string[] files = Directory.GetFiles(pathDirectoryArchiveAncien); - - savedFilesWaitingToBeUploadedFromAncientArchiveFolder = Directory.GetFiles(pathDirectoryArchiveAncien, "*.json"); // ici il faut trier les fichier de l'enseigant - - if (savedFilesWaitingToBeUploadedFromAncientArchiveFolder != null && savedFilesWaitingToBeUploadedFromAncientArchiveFolder.Length > 0) - { - //Debug.LogError("il y a dans les archivrs des fichiers correspondants à ce joueur " + fichiersAncientToSauvegarde.Length); - // il y a des fichiers d'archive correspondant à ce joueur qui apparaissent encore dans l'ancien dossier archive. On va donc retenter de les envoyer au serveur HM - // si ils existent deja dans le serveur HM, on les bouge dans le nouveau dossier Archive - // si ils n'existent pas dans le serveur HM, on les envoit, puis on les bouge dans le nouveau dossier archive - currentlydoingAncientArchiveFolder = true; - nbOfFilesUploaded = 0; - nbOfFilesToUpload = savedFilesWaitingToBeUploadedFromAncientArchiveFolder.Length; - currentlySending = true; - uploadOnefichierAncientArchiveTraceToHM(); - - } - else - { - //Debug.LogError("il n'y a PAS dans les archivrs des fichiers correspondants à ce joueur voici cb il y a de fichiers dans archive " + files.Length+" looking for "+ nomFichierBase); - - // in n'y a rien dans les archives à envoyer - endAllUploads(); - } - - } - - - private static void uploadOnefichierAncientArchiveTraceToHM() - { - //Debug.LogError("sendOnefichierAncientArchiveTraceToHM"); - - if (nbOfFilesUploaded > savedFilesWaitingToBeUploadedFromAncientArchiveFolder.Length - 1) - { - endAllUploads(); - } - else - { - currentlySentFilePath = savedFilesWaitingToBeUploadedFromAncientArchiveFolder[nbOfFilesUploaded]; - // Le fichier JSON existe, donc nous le lisons - string dateEnvoi = DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss"); - string nom = Path.GetFileNameWithoutExtension(currentlySentFilePath) + ".json"; - currentlySentTemporaryFilePath = Path.Combine(PathDirectoryTemporary, nom); - // Copiez le fichier source vers le dossier de destination en le renommant si nécessaire. - File.Copy(currentlySentFilePath, currentlySentTemporaryFilePath, true); - if (File.Exists(currentlySentTemporaryFilePath)) - { - try - { - HM_PluginController.UploadTrace(currentlySentTemporaryFilePath, uploadOneFileAsynchroneFinished); - } - catch (Exception ex) - { - // Gérez toute exception survenue lors de l'appel à CheckTraceExist ici. - ////Debug.LogError("Erreur lors de l'appel à UploadTrace : " + ex.Message); - deletecurrentFileFromTemporaryFolder(false); - endAllUploads(); - } - } - else - { - ////Debug.LogError("Traces 2 - ne devrait jamais arriver"); - deletecurrentFileFromTemporaryFolder(false); - endAllUploads(); - /* sauf si : - * Fichier source inexistant : Si le fichier source spécifié n'existe pas, la copie échouera. - Permissions insuffisantes : Si l'application n'a pas les permissions nécessaires pour lire le fichier source ou écrire dans le répertoire de destination, la copie échouera. - Espace disque insuffisant : Si le disque de destination est plein ou manque d'espace, la copie échouera. - Fichier de destination verrouillé : Si le fichier de destination est déjà ouvert ou verrouillé par une autre application, la copie échouera. - Problèmes matériels : Des problèmes matériels, tels que des secteurs défectueux sur le disque, peuvent entraîner des erreurs lors de la copie - */ - } - } - - } - private static void endAllUploads() { + Debug.LogError("endTransferts"); + nbOfFilesUploaded = 0; + nbOfFilesToUpload = 0; + currentlySending = false; } diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index 28713ce9afc5081263d4e6278e94a67d4ef11394..b2e12915fe32f60875842b25102cdec48fd2576f 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -24,13 +24,13 @@ EditorUserSettings: value: 5057510250560c5d5d0a0a7312225d44424e4d737e7b246928781f61b6e4373c flags: 0 RecentlyUsedSceneGuid-6: - value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661 + value: 025701560657515e545d0926447508454e474f2f797820647b7d4c35e1b93661 flags: 0 RecentlyUsedSceneGuid-7: - value: 025701560657515e545d0926447508454e474f2f797820647b7d4c35e1b93661 + value: 52045152560d5d025858542140750e44404f4d2b74797431292b1f66b1e5373c flags: 0 RecentlyUsedSceneGuid-8: - value: 52045152560d5d025858542140750e44404f4d2b74797431292b1f66b1e5373c + value: 515250075c0c595e5f5a5e71122159444e4e4a2f7a7d7f602f284d66b4b76661 flags: 0 vcSharedLogLevel: value: 0d5e400f0650 diff --git a/UserSettings/Layouts/default-2022.dwlt b/UserSettings/Layouts/default-2022.dwlt index b041fe04185a2e99fe92372f9678b10c66b185ab..63e88469b68e2ad323d93a2754a15b0fe08248a5 100644 --- a/UserSettings/Layouts/default-2022.dwlt +++ b/UserSettings/Layouts/default-2022.dwlt @@ -19,7 +19,7 @@ MonoBehaviour: width: 1536 height: 772.8 m_ShowMode: 4 - m_Title: Game + m_Title: Console m_RootView: {fileID: 2} m_MinSize: {x: 875, y: 300} m_MaxSize: {x: 10000, y: 10000} @@ -119,7 +119,7 @@ MonoBehaviour: m_MinSize: {x: 300, y: 100} m_MaxSize: {x: 24288, y: 16192} vertical: 0 - controlID: 17 + controlID: 111 --- !u!114 &6 MonoBehaviour: m_ObjectHideFlags: 52 @@ -139,12 +139,12 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 1114.4 + width: 1203.2 height: 722.8 m_MinSize: {x: 200, y: 100} m_MaxSize: {x: 16192, y: 16192} vertical: 1 - controlID: 18 + controlID: 39 --- !u!114 &7 MonoBehaviour: m_ObjectHideFlags: 52 @@ -164,12 +164,12 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 1114.4 - height: 492.8 + width: 1203.2 + height: 443.2 m_MinSize: {x: 200, y: 50} m_MaxSize: {x: 16192, y: 8096} vertical: 0 - controlID: 19 + controlID: 40 --- !u!114 &8 MonoBehaviour: m_ObjectHideFlags: 52 @@ -187,8 +187,8 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 373.6 - height: 492.8 + width: 400 + height: 443.2 m_MinSize: {x: 200, y: 200} m_MaxSize: {x: 4000, y: 4000} m_ActualView: {fileID: 13} @@ -211,10 +211,10 @@ MonoBehaviour: m_Children: [] m_Position: serializedVersion: 2 - x: 373.6 + x: 400 y: 0 - width: 740.80005 - height: 492.8 + width: 803.19995 + height: 443.2 m_MinSize: {x: 200, y: 200} m_MaxSize: {x: 4000, y: 4000} m_ActualView: {fileID: 12} @@ -233,23 +233,23 @@ MonoBehaviour: m_Enabled: 1 m_EditorHideFlags: 1 m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0} - m_Name: ProjectBrowser + m_Name: ConsoleWindow m_EditorClassIdentifier: m_Children: [] m_Position: serializedVersion: 2 x: 0 - y: 492.8 - width: 1114.4 - height: 230 - m_MinSize: {x: 231, y: 271} - m_MaxSize: {x: 10001, y: 10021} - m_ActualView: {fileID: 15} + y: 443.2 + width: 1203.2 + height: 279.59998 + m_MinSize: {x: 100, y: 100} + m_MaxSize: {x: 4000, y: 4000} + m_ActualView: {fileID: 16} m_Panes: - {fileID: 15} - {fileID: 16} - m_Selected: 0 - m_LastSelected: 1 + m_Selected: 1 + m_LastSelected: 0 --- !u!114 &11 MonoBehaviour: m_ObjectHideFlags: 52 @@ -265,9 +265,9 @@ MonoBehaviour: m_Children: [] m_Position: serializedVersion: 2 - x: 1114.4 + x: 1203.2 y: 0 - width: 421.59998 + width: 332.80005 height: 722.8 m_MinSize: {x: 275, y: 50} m_MaxSize: {x: 4000, y: 4000} @@ -296,10 +296,10 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 373.6 + x: 400 y: 73.6 - width: 738.80005 - height: 471.8 + width: 801.19995 + height: 422.2 m_SerializedDataModeController: m_DataMode: 0 m_PreferredDataMode: 0 @@ -316,7 +316,7 @@ MonoBehaviour: m_ShowGizmos: 0 m_TargetDisplay: 0 m_ClearColor: {r: 0, g: 0, b: 0, a: 0} - m_TargetSize: {x: 923.50006, y: 563.5} + m_TargetSize: {x: 1001.49994, y: 501.5} m_TextureFilterMode: 0 m_TextureHideFlags: 61 m_RenderIMGUI: 1 @@ -331,10 +331,10 @@ MonoBehaviour: m_VRangeLocked: 0 hZoomLockedByDefault: 0 vZoomLockedByDefault: 0 - m_HBaseRangeMin: -369.40002 - m_HBaseRangeMax: 369.40002 - m_VBaseRangeMin: -225.40001 - m_VBaseRangeMax: 225.40001 + m_HBaseRangeMin: -400.59998 + m_HBaseRangeMax: 400.59998 + m_VBaseRangeMin: -200.6 + m_VBaseRangeMax: 200.6 m_HAllowExceedBaseRangeMin: 1 m_HAllowExceedBaseRangeMax: 1 m_VAllowExceedBaseRangeMin: 1 @@ -352,23 +352,23 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 21 - width: 738.80005 - height: 450.8 - m_Scale: {x: 0.99999994, y: 0.99999994} - m_Translation: {x: 369.40002, y: 225.4} + width: 801.19995 + height: 401.2 + m_Scale: {x: 1, y: 1} + m_Translation: {x: 400.59998, y: 200.6} m_MarginLeft: 0 m_MarginRight: 0 m_MarginTop: 0 m_MarginBottom: 0 m_LastShownAreaInsideMargins: serializedVersion: 2 - x: -369.40005 - y: -225.40001 - width: 738.8001 - height: 450.80002 + x: -400.59998 + y: -200.6 + width: 801.19995 + height: 401.2 m_MinimalGUI: 1 - m_defaultScale: 0.99999994 - m_LastWindowPixelSize: {x: 923.50006, y: 589.75} + m_defaultScale: 1 + m_LastWindowPixelSize: {x: 1001.49994, y: 527.75} m_ClearInEditMode: 1 m_NoCameraWarning: 1 m_LowResolutionForAspectRatios: 01000000000000000000 @@ -396,8 +396,8 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 73.6 - width: 372.6 - height: 471.8 + width: 399 + height: 422.2 m_SerializedDataModeController: m_DataMode: 0 m_PreferredDataMode: 0 @@ -411,9 +411,9 @@ MonoBehaviour: m_SceneHierarchy: m_TreeViewState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: 509b0000 - m_LastClickedID: 0 - m_ExpandedIDs: 6c83ffff36a3ffff64a6ffff2ec6ffff02ccffff5eecffff86f0ffff16fbffffec6200005ac30000f4f10000 + m_SelectedIDs: e4a3feff + m_LastClickedID: -89116 + m_ExpandedIDs: e6a3feff1eadfeff54c2feff0429ffff9e4dffff1052ffffde73ffff7a78ffffe498ffff0ad1ffff16fbffffec62000040c40000808f0100c8c9010022150200987b0300 m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -906,9 +906,9 @@ MonoBehaviour: m_Pos: serializedVersion: 2 x: 0 - y: 566.4 - width: 1113.4 - height: 209 + y: 441.6 + width: 890.2 + height: 333.8 m_SerializedDataModeController: m_DataMode: 0 m_PreferredDataMode: 0 @@ -930,7 +930,7 @@ MonoBehaviour: m_SkipHidden: 0 m_SearchArea: 1 m_Folders: - - Assets/Scenes + - Assets m_Globs: [] m_OriginalText: m_ImportLogFlags: 0 @@ -938,16 +938,16 @@ MonoBehaviour: m_ViewMode: 1 m_StartGridSize: 64 m_LastFolders: - - Assets/Scenes + - Assets m_LastFoldersGridSize: -1 m_LastProjectPath: C:\Users\guill\OneDrive\Bureau\LUCIOLE\EVALULULU_DEC2023_2\lulu-testing m_LockTracker: m_IsLocked: 0 m_FolderTreeState: scrollPos: {x: 0, y: 60} - m_SelectedIDs: 307c0000 - m_LastClickedID: 31792 - m_ExpandedIDs: 000000001e7c0000207c0000347c000000ca9a3bffffff7f + m_SelectedIDs: 1e7c0000 + m_LastClickedID: 31774 + m_ExpandedIDs: 000000001e7c0000207c0000227c000000ca9a3bffffff7f m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -975,7 +975,7 @@ MonoBehaviour: scrollPos: {x: 0, y: 0} m_SelectedIDs: m_LastClickedID: 0 - m_ExpandedIDs: 000000001e7c0000207c0000 + m_ExpandedIDs: 000000001e7c0000207c0000227c0000 m_RenameOverlay: m_UserAcceptedRename: 0 m_Name: @@ -1000,8 +1000,8 @@ MonoBehaviour: m_Icon: {fileID: 0} m_ResourceFile: m_ListAreaState: - m_SelectedInstanceIDs: - m_LastClickedInstanceID: 0 + m_SelectedInstanceIDs: e4a3feff + m_LastClickedInstanceID: -89116 m_HadKeyboardFocusLastEvent: 1 m_ExpandedInstanceIDs: c6230000 m_RenameOverlay: @@ -1027,7 +1027,7 @@ MonoBehaviour: m_Icon: {fileID: 0} m_ResourceFile: m_NewAssetIndexInList: -1 - m_ScrollPosition: {x: 0, y: 0} + m_ScrollPosition: {x: 0, y: 99.600006} m_GridSize: 64 m_SkipHiddenPackages: 0 m_DirectoriesAreaWidth: 184.2 @@ -1052,9 +1052,9 @@ MonoBehaviour: m_Pos: serializedVersion: 2 x: 0 - y: 566.4 - width: 1113.4 - height: 209 + y: 516.8 + width: 1202.2 + height: 258.59998 m_SerializedDataModeController: m_DataMode: 0 m_PreferredDataMode: 0 @@ -1085,9 +1085,9 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 1114.4 + x: 1203.2001 y: 73.6 - width: 420.59998 + width: 331.80005 height: 701.8 m_SerializedDataModeController: m_DataMode: 0