Ejemplo n.º 1
0
        public static void LoadPic(int type, JObject elementData, PictureBox picture, TextBox box = null)
        {
            var url  = BstManager.GetItemPicUrl(type, elementData);
            var path = BstManager.GetItemPicTmpPath(type, elementData);

            BstPicLoader.RunLoading(url, path, picture, box);
        }
Ejemplo n.º 2
0
        public static byte[] DownloadImageFile(string url, string path)
        {
            var blob = BstManager.GetBytesFromWeb(url);

            if (blob == null)
            {
                return(null); // 下载失败
            }
            BstManager.WriteByteArrayToFile(path, blob);

            return(blob);
        }
Ejemplo n.º 3
0
        private BstLogger()
        {
            var logPath = BstManager.PathVsRoot + BstManager.PathVsLog + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss-ffff") + ".log";

            BstManager.CreateFile(logPath);
            var timer = new Timer(5000);

            this._buff      = new StringBuilder();
            timer.Elapsed  += (sender, args) => File.AppendAllText(logPath, _buff.ToString());
            timer.AutoReset = true;
            timer.Enabled   = true;
        }
Ejemplo n.º 4
0
        public void RunGrunt(TextBox box, string task = "", string[] args = null)
        {
            if (this._isGruntRunning)
            {
                BstLogger.Instance.Log(BstI18NLoader.Instance.LoadI18NValue("BstManager", "gruntAlreadyRun"));
                return; // 已经有grunt脚本在运行了,这里不再运行新的脚本
            }
            else
            {
                this._isGruntRunning = true;
            }

            var worker = new BackgroundWorker();

            worker.DoWork += (s, e) =>
            {
                var proc = new Process();

                var          cwd       = Directory.GetCurrentDirectory() + "/" + BstManager.PathRoot;
                const string cmd       = "cmd.exe";
                var          arguments = "/c grunt " + task + " " + ((args == null) ? "" : String.Join(" ", args)) + " --no-color --stack";
                // 打印命令信息
                var logMsg = string.Format(BstI18NLoader.Instance.LoadI18NValue("BstManager", "gruntStartLog"), cwd, cmd, arguments);
                BstManager.ShowMsgInTextBox(box, logMsg);

                proc.StartInfo.WorkingDirectory       = cwd;
                proc.StartInfo.FileName               = cmd;
                proc.StartInfo.Arguments              = arguments;
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.CreateNoWindow         = true;
                proc.StartInfo.RedirectStandardError  = true;
                proc.StartInfo.RedirectStandardOutput = true;

                proc.EnableRaisingEvents = true;
                proc.Exited += (es, ee) => BstManager.DisplayInfoMessageBox(
                    BstI18NLoader.Instance.LoadI18NValue("BstManager", "gruntResultTitle"),
                    BstI18NLoader.Instance.LoadI18NValue("BstManager", "gruntResultMsg")
                    );

                proc.OutputDataReceived += (dataSender, dataE) => BstManager.ShowMsgInTextBox(box, dataE.Data); // 注册输出接收事件
                proc.Start();                                                                                   // 启动
                proc.BeginOutputReadLine();                                                                     // 逐行读入输出
            };
            worker.RunWorkerCompleted += (s, e) =>
            {
                this._isGruntRunning = false;
                worker.Dispose();
            };
            worker.RunWorkerAsync();
        }
Ejemplo n.º 5
0
 public static void WriteJsonFile(string path, JObject json)
 {
     if (!File.Exists(path))
     {
         BstManager.CreateFile(path);
     }
     try
     {
         File.WriteAllText(path, json.ToString(Formatting.Indented));
     }
     catch (IOException ex)
     {
         BstLogger.Instance.Log(ex.ToString());
     }
 }
Ejemplo n.º 6
0
        private void Init()
        {
            this.SystemSettings     = BstManager.ReadJsonFile(BstManager.PathJsonSettings);
            this.DataCostume        = BstManager.ReadJsonFile(BstManager.PathJsonCostume);
            this.DataCostumeInvalid = BstManager.ReadJsonFile(BstManager.PathJsonCostumeInvalid);
            this.DataAttach         = BstManager.ReadJsonFile(BstManager.PathJsonAttach);
            this.DataAttachInvalid  = BstManager.ReadJsonFile(BstManager.PathJsonAttachInvalid);
            this.DataWeapon         = BstManager.ReadJsonFile(BstManager.PathJsonWeapon);
            this.DataWeaponInvalid  = BstManager.ReadJsonFile(BstManager.PathJsonWeaponInvalid);

            var lang = (string)this.SystemSettings["lang"];

            this.DataI18N = BstManager.ReadJsonFile(BstManager.PathI18N + lang + ".json");

            var raceNamesInConfig = (JArray)this.DataI18N["Game"]["raceNames"];

            this.RaceNames = new List <string>();
            this.RaceNames.AddRange(
                raceNamesInConfig.ToObject <List <string> >()
                );
            this.RaceTypes = new List <string>();
            this.RaceTypes.AddRange(new string[]
            {
                "KunN", "JinF", "JinM", "GonF", "GonM", "Lyn"
            });

            this.LanguageNames = new List <string>();
            this.LanguageNames.AddRange(new String[]
            {
                "简体中文", "English"
            });
            this.LanguageTypes = new List <string>();
            this.LanguageTypes.AddRange(new String[]
            {
                "zh_CN", "en_US"
            });

            this.LoadingGifBytes = BstManager.GetBytesFromFile(BstManager.PathLoadingGif);
            this.NoIconBytes     = BstManager.GetBytesFromFile(BstManager.PathNoIcon);
            this.ErrorIconBytes  = BstManager.GetBytesFromFile(BstManager.PathErrorIcon);
        }
Ejemplo n.º 7
0
        private static void RunLoading(string url, string path, PictureBox picture, TextBox box = null)
        {
            new Thread(() =>
            {
                Timer loadingTimer = null;
                if (!BstPicLoader.LoadingTimers.ContainsKey(picture))
                {
                    // 更新图片成读取状态,如果Dictionary里已经有这个PictureBox的Timer了,说明loading图已经加载了
                    var loadingGif = new BstGifImage(BstManager.PathLoadingGif)
                    {
                        ReverseAtEnd = false
                    };
                    loadingTimer          = new Timer(50);
                    loadingTimer.Elapsed += (s, e) =>
                    {
                        MethodInvoker loadingAction = () =>
                        {
                            picture.Image = loadingGif.GetNextFrame();
                        };
                        try
                        {
                            picture.BeginInvoke(loadingAction);
                        }
                        catch (InvalidOperationException ex)
                        {
                            BstLogger.Instance.Log(ex.ToString());
                            // 因为我们可能会在GUI_Picture的UI中的PictureBox里显示loading动态图
                            // 而上述的窗口可能在关闭后被销毁,这里我们需要处理窗口被销毁后的错误
                            // 这时候Timer应该在Dictionary里注册过了
                            if (BstPicLoader.LoadingTimers.ContainsKey(picture))
                            {
                                var timer     = BstPicLoader.LoadingTimers[picture];
                                timer.Enabled = false;
                                BstPicLoader.LoadingTimers.Remove(picture);
                                timer.Dispose();
                            }
                        }
                    };
                    BstPicLoader.LoadingTimers.Add(picture, loadingTimer);
                    loadingTimer.Enabled = true;
                }
                else
                {
                    loadingTimer = BstPicLoader.LoadingTimers[picture];
                }

                // 检查是否有本地缓存
                byte[] blob = null;
                if (File.Exists(path))
                {
                    // 本地缓存存在,直接读取
                    blob = BstManager.GetBytesFromFile(path);
                }
                else
                {
                    // 下载图片
                    blob = BstManager.DownloadImageFile(url, path);
                    if (blob == null)
                    {
                        // 图片下载失败
                        BstManager.ShowMsgInTextBox(box, string.Format(BstI18NLoader.Instance.LoadI18NValue("BstPicLoader", "picDownloadFailed"), url));
                        // 停止动态图更新
                        loadingTimer.Enabled = false;
                        BstPicLoader.LoadingTimers.Remove(picture);
                        loadingTimer.Dispose();
                        // 更新下载失败icon
                        var errorIconBitmap             = BstManager.ConvertByteToImage(BstManager.Instance.ErrorIconBytes);
                        MethodInvoker updateErrorAction = () => picture.Image = errorIconBitmap;
                        try
                        {
                            picture.BeginInvoke(updateErrorAction);
                        }
                        catch (Exception ex)
                        {
                            BstLogger.Instance.Log(ex.ToString());
                        }
                        return;
                    }
                }

                loadingTimer.Enabled = false;               // 加载完成,停止动态loading图的更新
                BstPicLoader.LoadingTimers.Remove(picture); // 加载完成,删除Dictionary里注册的Timer
                loadingTimer.Dispose();

                BstManager.ShowMsgInTextBox(box, string.Format(BstI18NLoader.Instance.LoadI18NValue("BstPicLoader", "picDownloadSucceed"), url));

                // 转换成位图
                var bitmap = BstManager.ConvertByteToImage(blob);
                // 更新图片内容
                MethodInvoker updateAction = () => picture.Image = bitmap;
                try
                {
                    picture.BeginInvoke(updateAction);
                }
                catch (Exception ex)
                {
                    BstLogger.Instance.Log(ex.ToString());
                }
            }).Start();
        }
Ejemplo n.º 8
0
 public static string GetItemOriginJsonPath(int type)
 {
     return(BstManager.PathRoot + BstManager.PathDatabase + BstManager.GetTypeName(type) + "/data/origin.json");
 }
Ejemplo n.º 9
0
 public static string GetItemPicTmpPath(int type, JObject elementData)
 {
     return(BstManager.PathVsRoot + BstManager.PathVsTmp +
            BstManager.GetTypeName(type) + "/" +
            (string)elementData["core"] + "_" + (string)elementData["col"] + ".png");
 }
Ejemplo n.º 10
0
 public static string GetItemPicUrl(int type, JObject elementData)
 {
     return(BstManager.GithubRoot + BstManager.GithubBranch + "/" +
            BstManager.PathDatabase + BstManager.GetTypeName(type) + "/pics-cps/" +
            (string)elementData["core"] + "_" + (string)elementData["col"] + ".png");
 }
Ejemplo n.º 11
0
        public void Run()
        {
            var updatedCount  = 0;
            var isAnyTaskLeft = true;

            while (isAnyTaskLeft)
            {
                var task = this._queue.Dequeue();

                // 加载图片
                byte[] pic          = null;
                var    downloadUrl  = BstManager.GetIconPicUrl(task.ElementData);
                var    imgCachePath = BstManager.GetIconPicTmpPath(task.ElementData);
                if (File.Exists(imgCachePath))
                {
                    // 已有缓存文件
                    pic = BstManager.GetBytesFromFile(imgCachePath);
                }
                else
                {
                    // 没有缓存文件,需要下载
                    pic = BstManager.DownloadImageFile(downloadUrl, imgCachePath);
                }

                // 检查结果并更新UI
                if (pic == null)
                {
                    BstManager.ShowMsgInTextBox(task.Box, string.Format(BstI18NLoader.Instance.LoadI18NValue("BstIconLoader", "iconDownloadFailed"), downloadUrl));
                    // 更新加载失败icon
                    task.Table.Rows[task.RowId][task.ColId] = BstManager.Instance.ErrorIconBytes;
                }
                else
                {
                    BstManager.ShowMsgInTextBox(task.Box, string.Format(BstI18NLoader.Instance.LoadI18NValue("BstIconLoader", "iconDownloadSucceed"), downloadUrl));
                    // 更新图片
                    task.Table.Rows[task.RowId][task.ColId] = pic;
                }

                // 检查icon加载进度,并刷新ui
                updatedCount++;
                if (updatedCount >= BstIconLoader.UpdateThrottle)
                {
                    MethodInvoker tableUpdateAction = () => task.Grid.Refresh();
                    try
                    {
                        task.Grid.BeginInvoke(tableUpdateAction);
                    }
                    catch (Exception ex)
                    {
                        BstLogger.Instance.Log(ex.ToString());
                    }
                    updatedCount = 0;
                }

                if (this._queue.Count != 0)
                {
                    continue;                         // 仍旧还有工作未完成,继续轮询
                }
                // 当前工作队列已清空,最后更新UI,设置关闭状态
                MethodInvoker tableFinalUpdateAction = () => task.Grid.Refresh();
                task.Grid.BeginInvoke(tableFinalUpdateAction);
                BstManager.DisplayDataGridViewVerticalScrollBar(task.Grid);
                BstManager.ShowMsgInTextBox(task.Box, BstI18NLoader.Instance.LoadI18NValue("BstIconLoader", "iconDownloadAllDone"));
                BstLogger.Instance.Log("[BstIconLoader] Queued works all done, thread exit ...");
                isAnyTaskLeft = false;
            }
        }