Beispiel #1
0
        /// <summary>
        /// メタファイルをパース
        /// </summary>
        /// <returns>true:パース成功、false:それ以外</returns>
        internal bool ParseMeta()
        {
            bool result = false;

            this.Index       = 0;
            this._rootDir    = "";
            this._contentDir = "";
            this._pages.Clear();
            this.Toc.Clear();
            try {
                var model = JsonConvert.DeserializeObject <MetaModel>(File.ReadAllText(this.MetaFile));
                this._rootDir    = new FileOperator(this.MetaFile).FileDir + @"\";
                this._contentDir = this._rootDir + this.ConvertWinPath(model.ContentDir) + @"\";
                this.Title       = model.Title;
                //if (0 < model.Cover?.Length) {
                //    this._pages.Add(this.ConvertWinPath(model.Cover));
                //}
                var contentDir = new DirectoryOperator(this._contentDir);
                contentDir.ParseChildren(false);
                foreach (var content in contentDir.Children)
                {
                    this._pages.Add(content.Name);
                }

                foreach (var content in model.TableOfContents)
                {
                    var toc = new TocModelEx(content);
                    if (0 < toc.Link?.Length)
                    {
                        if (this._pages.Contains(toc.Link))
                        {
                            toc.Index = this._pages.IndexOf(toc.Link);
                        }
                        toc.Link = this.ConvertWinPath(toc.Link);
                    }
                    if (0 < toc.Level && 0 < toc.Content?.Length)
                    {
                        var padding = " ";
                        if (2 == toc.Level)
                        {
                            padding = "  ";
                        }
                        else if (3 == toc.Level)
                        {
                            padding = "    ";
                        }
                        else if (4 == toc.Level)
                        {
                            padding = "      ";
                        }

                        toc.Content = padding + toc.Content;
                        if (0 < toc.Link.Length)
                        {
                            toc.FileIndex = string.Format("[{0:000}]  ", toc.Index + 1);
                        }
                        this.Toc.Add(toc);
                    }
                }
                result = true;
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }

            return(result);
        }
Beispiel #2
0
        /// <summary>
        /// 初期処理
        /// </summary>
        private void Initialize()
        {
            // delete cache icon
            var dirUtil = new DirectoryOperator(Constant.IconCache);

            dirUtil.Create();
            dirUtil.ParseChildren(false, new List <string>()
            {
                "tmp"
            });
            foreach (var child in dirUtil.Children)
            {
                ((FileOperator)child).Delete();
            }

            // set window position
            this._settings = AppRepository.Init(Constant.SettingFile);
            if (0 <= this._settings.Pos.X && (this._settings.Pos.X + this.Width) < SystemParameters.VirtualScreenWidth)
            {
                this.Left = this._settings.Pos.X;
            }
            if (0 <= this._settings.Pos.Y && (this._settings.Pos.Y + this.Height) < SystemParameters.VirtualScreenHeight)
            {
                this.Top = this._settings.Pos.Y;
            }

            // show title
            var fullname = typeof(App).Assembly.Location;
            var info     = System.Diagnostics.FileVersionInfo.GetVersionInfo(fullname);

            this._appTitle = $"MyQuickLauncher({info.ProductMajorPart}.{info.ProductMinorPart}.{info.ProductPrivatePart})";
            this.UpdateTitle();

            // setup grid items
            this._items = _items = ItemRepository.Init(Constant.AppDataFile);
            var index = 0;

            this._itemViews = new ItemView[Constant.ItemCount];
            for (int row = 0; row < this.cContainer.RowDefinitions.Count - 1; row++)
            {
                for (int col = 0; col < this.cContainer.ColumnDefinitions.Count; col++)
                {
                    var model = this._items.ItemList[this._settings.Page][index];
                    //model.PageNo = 1;
                    //model.Index = index;
                    if (!System.IO.File.Exists(model.Icon))
                    {
                        model.Icon = Constant.NoItemIcon;
                    }
                    var item = new ItemView(this, model, this._keybinding[index]);
                    this._itemViews[index] = item;
                    index++;
                    item.VerticalAlignment = VerticalAlignment.Bottom;
                    Grid.SetRow(item, row);
                    Grid.SetColumn(item, col);
                    item.ItemClick        += ItemClick;
                    item.ItemAdded        += ItemAdded;
                    item.ItemUpdated      += ItemUpdated;
                    item.ItemRemoved      += ItemRemoved;
                    item.ItemDir          += ItemDir;
                    item.VerticalAlignment = VerticalAlignment.Top;
                    this.cContainer.Children.Add(item);
                }
            }

            // register hot key
            this._hotkey.Register(ModifierKeys.None, Key.ImeNonConvert, (_, __) => {
                if (!this.ShowInTaskbar)
                {
                    NotifyMenuShow_Click(null, null);
                }
                else
                {
                    if (this.WindowState == WindowState.Minimized)
                    {
                        this.WindowState = WindowState.Normal;
                    }
                    this.Activate();
                }
            }
                                  );
        }