コード例 #1
0
        public static bool LoadCDB(string dir, bool overwrite, bool clearData = false)
        {
            if (!File.Exists(dir))
            {
                return(false);
            }

            if (clearData)
            {
                CardData.Clear();
            }

            SqliteConnection connection = new SqliteConnection("Data Source=" + dir);
            List <string[]>  datas      = new List <string[]>();
            List <string[]>  texts      = new List <string[]>();

            try
            {
                connection.Open();
                datas = SQLiteCommands.LoadData(connection);
                texts = SQLiteCommands.LoadText(connection);
                connection.Close();
            }
            catch (Exception ex)
            {
                connection.Close();
                return(false);
            }

            foreach (string[] row in datas)
            {
                if (overwrite)
                {
                    CardManager.UpdateOrAddCard(new CardInfos(row));
                }
                else
                {
                    if (!CardManager.ContainsCard(Int32.Parse(row[0])))
                    {
                        CardManager.UpdateOrAddCard(new CardInfos(row));
                    }
                }
            }
            foreach (string[] row in texts)
            {
                if (CardManager.ContainsCard(Int32.Parse(row[0])))
                {
                    CardManager.GetCard(Int32.Parse(row[0])).SetCardText(row);
                }
            }

            if (File.Exists("setname.txt"))
            {
                LoadSetCodesFromFile(CreateFileStreamFromString(File.ReadAllText("setname.txt")));
            }
            SetCodesStringInit();

            return(true);
        }
コード例 #2
0
        public static bool LoadCDB(string dir, bool overwrite, bool clearData = false)
        {
            logger.Info("Start LOAD CDB {0}", dir);
            LoadPicsFile();

            if (!File.Exists(dir))
            {
                return(false);
            }

            if (clearData)
            {
                CardData.Clear();
            }

            SQLiteConnection connection = new SQLiteConnection("Data Source=" + dir);
            List <string[]>  datas      = new List <string[]>();
            List <string[]>  texts      = new List <string[]>();

            try
            {
                connection.Open();
                datas = SQLiteCommands.LoadData(connection);
                texts = SQLiteCommands.LoadText(connection);
                connection.Close();
            }
            catch (Exception ex)
            {
                logger.Error("LOADCDB :" + ex.ToString());
                connection.Close();
                return(false);
            }

            progress = 0;
            total    = datas.Count + texts.Count;
            foreach (string[] row in datas)
            {
                if (overwrite)
                {
                    CardManager.UpdateOrAddCard(new CardInfos(row));
                }
                else
                {
                    if (!CardManager.ContainsCard(int.Parse(row[0])))
                    {
                        CardManager.UpdateOrAddCard(new CardInfos(row));
                    }
                }

                if (!CheckPicsLoaded(Convert.ToInt32(row[0])))
                {
                    DownloadPics(row[0]);
                }
                else
                {
                    progress++;
                    Application.Current.Dispatcher.Invoke(() => LoadingProgress?.Invoke(progress, total));
                }
            }
            foreach (string[] row in texts)
            {
                progress++;
                Application.Current.Dispatcher.Invoke(() => LoadingProgress?.Invoke(progress, total));

                if (CardManager.ContainsCard(int.Parse(row[0])))
                {
                    CardManager.GetCard(int.Parse(row[0])).SetCardText(row);
                }
            }

            if (File.Exists(Path.Combine(FormExecution.path, "BattleCityAlpha", "strings.conf")))
            {
                LoadSetCodesFromFile(CreateFileStreamFromString(File.ReadAllText(Path.Combine(FormExecution.path, "BattleCityAlpha", "strings.conf"))));
            }
            SetCodesStringInit();

            while (progress != total)
            {
                Thread.Sleep(500);
            }
            Application.Current.Dispatcher.Invoke(() => LoadingFinished?.Invoke());

            return(true);
        }