private bool downloadInitData() { string appDataFolder = TOLData.AppDataDirectory(); string serverUrl = urlServerTextBox.Text; string zipFilePath = Path.Combine(appDataFolder, "init.zip"); try { using (WebClient client = new WebClient()) { client.DownloadFile(Url.Combine(serverUrl, "appdata", "init.zip"), zipFilePath); } } catch (WebException e) { errorLabel.Text = "Can't download init data from " + serverUrl; return(false); } if (!Directory.Exists(appDataFolder)) { Directory.CreateDirectory(appDataFolder); } else { string soundsDataPath = Path.Combine(TOLData.AppDataDirectory(), "Datas", "Sounds"); if (Directory.Exists(soundsDataPath)) { DirectoryInfo soundsDir = new DirectoryInfo(soundsDataPath); soundsDir.Delete(true); } string imageDataPath = Path.Combine(TOLData.AppDataDirectory(), "Datas", "Images"); if (Directory.Exists(imageDataPath)) { DirectoryInfo imagesDir = new DirectoryInfo(imageDataPath); imagesDir.Delete(true); } string commentDataPath = Path.Combine(TOLData.AppDataDirectory(), "Datas", "Comments"); if (Directory.Exists(commentDataPath)) { DirectoryInfo commentsDir = new DirectoryInfo(commentDataPath); commentsDir.Delete(true); } string locationDataPath = Path.Combine(TOLData.AppDataDirectory(), "Datas", TaxonUtils.MyConfig.TaxonFileName + "_location"); if (Directory.Exists(locationDataPath)) { DirectoryInfo locationDir = new DirectoryInfo(locationDataPath); locationDir.Delete(true); } } ZipFile zip = ZipFile.Read(zipFilePath); zip.ExtractAll(appDataFolder, ExtractExistingFileAction.OverwriteSilently); TOLData.offline = false; TaxonUtils.MyConfig.rootDirectory = TOLData.AppDataDirectory(); TaxonUtils.MyConfig.serverUrl = urlServerTextBox.Text; TaxonUtils.MyConfig.offline = false; TaxonUtils.MyConfig.dataInitialized = true; return(true); }
public void Activate() { // retrouve la liste de toutes les especes / sous especes List <TaxonTreeNode> Species = new List <TaxonTreeNode>(); TaxonUtils.OriginalRoot.GetAllChildrenRecursively(Species, ClassicRankEnum.Espece); TaxonUtils.OriginalRoot.GetAllChildrenRecursively(Species, ClassicRankEnum.SousEspece); int beforeWith = 0; int beforeWithout = 0; Dictionary <string, TaxonTreeNode> dico = new Dictionary <string, TaxonTreeNode>(); foreach (TaxonTreeNode node in Species) { if (node.Desc.HasSound) { beforeWith++; } else { beforeWithout++; } node.Desc.HasSound = false; dico[node.Desc.RefMultiName.Main.ToLower()] = node; } if (TaxonUtils.MyConfig.offline) { string[] files = System.IO.Directory.GetFiles(TOLData.SoundsDataPath(), "*.wma"); foreach (string file in files) { string name = System.IO.Path.GetFileNameWithoutExtension(file).ToLower(); if (dico.ContainsKey(name)) { dico[name].Desc.HasSound = true; } } } else { List <string> availableSounds = TOLData.availableSounds; foreach (string name in availableSounds) { string nameLowerCase = name.ToLower(); if (dico.ContainsKey(nameLowerCase)) { dico[nameLowerCase].Desc.HasSound = true; } } } int afterWith = 0; int afterWithout = 0; foreach (TaxonTreeNode node in Species) { if (node.Desc.HasSound) { afterWith++; } else { afterWithout++; } } string message = "Update sound flag : \n\n"; message += String.Format(" Total with sound : {0}, (before: {1})\n", afterWith, beforeWith); message += String.Format(" Total without sound : {0}, (before: {1})\n\n", afterWithout, beforeWithout); Loggers.WriteInformation(LogTags.Sound, message); }