Ejemplo n.º 1
0
        private void loadTokenLibraryFiles()
        {
            string[] files;

            try
            {
                files = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory + TokenData.TOKEN_LIBRARY_FOLDER);
            }
            catch (DirectoryNotFoundException e)
            {
                // Token library folder not found
                Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + TokenData.TOKEN_LIBRARY_FOLDER);
                return;
            }

            foreach (string file in files)
            {
                if (Path.GetExtension(file) == ".token")
                {
                    try
                    {
                        TokenData loadedToken = TokenData.LoadFromFile(file);
                        gameState.TokenLibrary.Add(ref loadedToken);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("Error loading token from file: " + file);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void TokenImportButton_Click(object sender, EventArgs e)
        {
            importTokenFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);

            if (importTokenFileDialog.ShowDialog() == DialogResult.OK)
            {
                string[] filePaths = importTokenFileDialog.FileNames;

                foreach (string filePath in filePaths)
                {
                    try
                    {
                        TokenData loadedData = TokenData.LoadFromFile(filePath);
                        string    localPath  = AppDomain.CurrentDomain.BaseDirectory + TokenData.TOKEN_LIBRARY_FOLDER + loadedData.Name + ".token";

                        if (File.Exists(localPath))
                        {
                            if (MessageBox.Show("A token named " + loadedData.Name + " already exists in the current library. Overwrite?", "Overwrite existing token?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                            {
                                continue;
                            }
                        }

                        File.Copy(filePath, localPath, true);

                        if (gameState.TokenLibrary.Contains(loadedData.Name))
                        {
                            gameState.TokenLibrary[loadedData.Name] = loadedData;
                        }
                        else
                        {
                            gameState.TokenLibrary.Add(ref loadedData);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error loading token file: " + Path.GetFileName(filePath) + "\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }