Exemplo n.º 1
0
        static public async Task AddModpack(MainWindow sender, string nome, string token)
        {
            sender.Message("Creo file di salvataggio del Modpack...");

            if (File.Exists(ModpackSavePath))
            {
                Modpacks modpacks = JsonConvert.DeserializeObject <Modpacks>(await File.ReadAllTextAsync(ModpackSavePath));
                if (!modpacks.modpack.ContainsKey(nome))
                {
                    modpacks.modpack.Add(nome, new Modpack()
                    {
                        Name = nome, Token = token
                    });
                    File.Delete(ModpackSavePath);
                    await File.WriteAllTextAsync(ModpackSavePath, JsonConvert.SerializeObject(modpacks, Formatting.Indented));
                }
            }
            else
            {
                Modpacks modpacks = new Modpacks();
                modpacks.modpack = new Dictionary <string, Modpack>();
                modpacks.modpack.Add(nome, new Modpack()
                {
                    Name = nome, Token = token
                });
                await File.WriteAllTextAsync(ModpackSavePath, JsonConvert.SerializeObject(modpacks, Formatting.Indented));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Crea un nuovo token e lo segna sul server
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="token"></param>
        /// <param name="nome"></param>
        /// <returns></returns>
        public async Task <string> CreateCredentials(MainWindow sender, string token, string nome)
        {
            string NewToken = "";

            sender.Message($"Creazione del Token...");

            FirebaseResponse response = await client.GetAsync("/");

            Modpacks modpacks = response.ResultAs <Modpacks>();

            bool alreadyExist()
            {
                foreach (KeyValuePair <string, Modpack> mod in modpacks.modpack)
                {
                    if (mod.Value.Token == token)
                    {
                        NewToken = mod.Key;
                        return(true);
                    }
                }
                return(false);
            }

            if (!alreadyExist())
            {
                NewToken = Utilities.GenerateToken(7);
                modpacks.modpack.Add(NewToken, new Modpack()
                {
                    Name = nome, Token = token
                });
                SetResponse setResponse = await client.SetAsync("/", modpacks);
            }

            return(NewToken);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Aggiorna un modpack
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public async void CheckUpdatesBtn(object sender, RoutedEventArgs e)
        {
            Modpacks modpacks = JsonConvert.DeserializeObject <Modpacks>(await File.ReadAllTextAsync(ModpackSavePath));

            foreach (KeyValuePair <string, Modpack> str in modpacks.modpack)
            {
                if (str.Value.Name == (string)modpackCBox.SelectedItem)
                {
                    nome.Text        = str.Value.Name;
                    token.Text       = str.Value.Token;
                    tab.SelectedItem = this.FindControl <TabItem>("tabPage1");
                    DownloadModpack(sender, e);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Controlla se il modpack esiste e prepara per il download del modpack
        /// </summary>
        /// <param name="nome">nome del modpack</param>
        /// <param name="Firebasetoken"></param>
        /// <returns></returns>
        public async Task <bool> ModpackExists(string nome, string Firebasetoken)
        {
            FirebaseResponse response = await client.GetAsync("/");

            ModpacksList = response.ResultAs <Modpacks>();

            if (ModpacksList.modpack.ContainsKey(Firebasetoken))
            {
                modpack = ModpacksList.modpack[Firebasetoken];
                if (await Utilities.isDropboxTokenValid(modpack.Token))
                {
                    if (nome != "")
                    {
                        if (nome.Contains("*") || nome.Contains(".") || nome.Contains("\"") || nome.Contains("/") || nome.Contains("[") || nome.Contains("]") || nome.Contains(":") || nome.Contains(";") || nome.Contains("|") || nome.Contains(","))
                        {
                            return(false);
                        }
                        else
                        {
                            ModpackBaseDirectory = Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances", nome);
                            ModpackModsDirectory = Path.Combine(ModpackBaseDirectory, "mods");
                            modpack.Name         = nome;
                            return(true);
                        }
                    }
                    else
                    {
                        ModpackBaseDirectory = Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances", nome);
                        ModpackModsDirectory = Path.Combine(ModpackBaseDirectory, "mods");
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        static public async Task RemoveModpack(MainWindow sender, string ModpackName)
        {
            Directory.Delete(Path.Combine(MinecraftPath.GetOSDefaultPath(), "Istances", ModpackName), true);

            if (File.Exists(ModpackSavePath))
            {
                Modpacks modpacks = JsonConvert.DeserializeObject <Modpacks>(await File.ReadAllTextAsync(ModpackSavePath));
                modpacks.modpack.Remove(ModpackName);

                File.Delete(ModpackSavePath);
                await File.WriteAllTextAsync(ModpackSavePath, JsonConvert.SerializeObject(modpacks, Formatting.Indented));

                List <string> items = new List <string>();
                foreach (KeyValuePair <string, Modpack> modpack in modpacks.modpack)
                {
                    items.Add(modpack.Value.Name);
                }
                sender.modpackCBox.Items = items;
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Ogni volta che si cambia scheda il aggiorna la lista di modpack
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public async void Tab_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (First)
     {
         First = false;
     }
     else
     {
         if (this.FindControl <TabItem>("tabPage3").IsSelected)
         {
             if (File.Exists(ModpackSavePath))
             {
                 Modpacks      modpacks = JsonConvert.DeserializeObject <Modpacks>(await File.ReadAllTextAsync(ModpackSavePath));
                 List <string> items    = new List <string>();
                 foreach (KeyValuePair <string, Modpack> modpack in modpacks.modpack)
                 {
                     items.Add(modpack.Value.Name);
                 }
                 modpackCBox.Items = items;
             }
         }
     }
 }