Beispiel #1
0
        /// <summary>
        /// Creates a stateful list of file type filters.
        /// </summary>
        /// <param name="policy">iFolder policy object</param>
        /// <returns>A hashtable containing the file type filters.</returns>
        private Hashtable CreateFileTypeSource(iFolderPolicy policy)
        {
            // Keep the state in a hashtable.
            Hashtable            ht      = new Hashtable();
            UserGroupAdminRights uRights = new UserGroupAdminRights(policy.AdminGroupRights);

            foreach (string s in policy.FileTypesExcludesEffective)
            {
                ht[s] = new FileTypeInfo(
                    s,
                    Utils.ConvertFromRegEx(s),
                    IsAllowed(policy.FileTypesIncludesEffective, s),
                    false);
            }

            foreach (string s in policy.FileTypesExcludes)
            {
                ht[s] = new FileTypeInfo(
                    s,
                    Utils.ConvertFromRegEx(s),
                    false,
                    uRights.AddToExcludePolicyAllowed);
            }

            return(ht);
        }
Beispiel #2
0
        public static string Run(FileType fileType, string path)
        {
            FileTypeInfo info = Common.FileTypes[fileType];

            Result[] results = new Rebuilder(path, info.Extension, info.GetReader, info.GetWriter).Run();

            if (results.Length == 0)
            {
                return("No files found");
            }

            var builder = new StringBuilder();

            builder.AppendLine($"Same: {results.Count(x => x.ByteCount == 0)}");
            builder.AppendLine($"Different: {results.Count(x => x.ByteCount > 0)}");
            builder.AppendLine($"Different size: {results.Count(x => x.ByteCount == -2)}");
            builder.AppendLine($"Error: {results.Count(x => x.ByteCount == -4)}");

            foreach (Result result in results.OrderByDescending(x => x.ByteCount == 0).ThenByDescending(x => x.ByteCount))
            {
                builder.AppendLine($"{result.ByteCount}, {result.Filename} {result.Error}");
            }

            builder.AppendLine($"Same: {results.Count(x => x.ByteCount == 0)}");
            builder.AppendLine($"Different: {results.Count(x => x.ByteCount > 0)}");
            builder.AppendLine($"Different size: {results.Count(x => x.ByteCount == -2)}");
            builder.AppendLine($"Error: {results.Count(x => x.ByteCount == -4)}");
            return(builder.ToString());
        }
Beispiel #3
0
        public int FileType_Add(FileTypeInfo info)
        {
            int rst = 0;

            try
            {
                OleDbParameter[] param = new OleDbParameter[5];
                param[0]       = new OleDbParameter("@ParentID", OleDbType.Integer);
                param[0].Value = info.ParentID;
                param[1]       = new OleDbParameter("@Code", OleDbType.VarWChar, 20);
                param[1].Value = info.Code;
                param[2]       = new OleDbParameter("@Alias", OleDbType.VarWChar, 20);
                param[2].Value = info.Alias;
                param[3]       = new OleDbParameter("@Title", OleDbType.VarWChar, 50);
                param[3].Value = info.Title;
                param[4]       = new OleDbParameter("@Remark", OleDbType.VarWChar, 100);
                param[4].Value = info.Remark;

                string sql = "insert into Cm_FileType (ParentID,Code,Alias,Title,Remark) values (@ParentID,@Code,@Alias,@Title,@Remark)";
                rst = DbHelper.ExecuteNonQuery(constring, CommandType.Text, sql, param);
            }
            catch
            {
                rst = -1;
            }

            return(rst);
        }
        internal void AddChange(Change change, Changeset cs, string localFilename, FileTypeInfo fileTypeInfo)
        {
            var info = new ChangedItemDeployInfo
            {
                FileType        = fileTypeInfo,
                LocalFilename   = localFilename,
                ServerPath      = change.Item.ServerItem,
                LastChangedBy   = cs.Owner,
                LastChangedDate = cs.CreationDate
            };

            info.AddChangeType(change.ChangeType.ToString());
            info.AddComments(cs.Comment);

            var key = localFilename.Replace(this.WorkItemDirectory, string.Empty);

            if (change.ChangeType != ChangeType.Delete)
            {
                if (!_flatChanges.ContainsKey(key))
                {
                    _flatChanges.Add(key, info);
                }
                else
                {
                    var existing = _flatChanges[key];
                    existing.LastChangedBy   = info.LastChangedBy;
                    existing.LastChangedDate = info.LastChangedDate;
                }
            }
            else
            {
                _flatDeletedChanges.Add(localFilename, info);
            }
        }
Beispiel #5
0
        public int FileType_Edit(FileTypeInfo info)
        {
            int rst = 0;

            try
            {
                OleDbParameter[] param = new OleDbParameter[5];
                param[0]       = new OleDbParameter("@Code", OleDbType.VarWChar, 20);
                param[0].Value = info.Code;
                param[1]       = new OleDbParameter("@Alias", OleDbType.VarWChar, 20);
                param[1].Value = info.Alias;
                param[2]       = new OleDbParameter("@Title", OleDbType.VarWChar, 50);
                param[2].Value = info.Title;
                param[3]       = new OleDbParameter("@Remark", OleDbType.VarWChar, 100);
                param[3].Value = info.Remark;
                param[4]       = new OleDbParameter("@ID", OleDbType.VarWChar, 50);
                param[4].Value = info.ID;


                string sql = "update Cm_FileType set Code=@Code,Alias=@Alias,Title=@Title,Remark=@Remark where ID=@ID";
                rst = DbHelper.ExecuteNonQuery(constring, CommandType.Text, sql, param);
            }
            catch
            {
                rst = -1;
            }

            return(rst);
        }
Beispiel #6
0
        private static string GetProjectFileInfo(Project.NodejsProjectNode project)
        {
            var fileTypeInfo = new Dictionary <string, FileTypeInfo>();

            foreach (var node in project.DiskNodes)
            {
                var file       = node.Key;
                var matchedExt = _interestingFileExtensions.Where(ext => file.EndsWith(ext, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (!string.IsNullOrEmpty(matchedExt))
                {
                    var          recordKey = string.Format("{0} ({1})", matchedExt, node.Value.ItemNode?.IsExcluded ?? true ? "excluded from project" : "included in project");
                    FileTypeInfo record;
                    if (!fileTypeInfo.TryGetValue(recordKey, out record))
                    {
                        record = fileTypeInfo[recordKey] = new FileTypeInfo();
                    }
                    record.UpdateForFile(file);
                }
            }

            var res = new StringBuilder();

            res.AppendLine("Project Info:");
            foreach (var entry in fileTypeInfo)
            {
                res.AppendLine(Indent(1, entry.Key + ":"));
                res.AppendLine(Indent(2, "Number of Files: " + entry.Value.Count));
                res.AppendLine(Indent(2, "Average Line Count: " + entry.Value.AverageLineLength));
                res.AppendLine(Indent(2, "Max Line Count: " + entry.Value.MaxLineLength));
            }

            return(res.ToString());
        }
Beispiel #7
0
        /// <summary>
        /// Event handler that gets called when the all files checkbox is checked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnAllFilesChecked(Object sender, EventArgs e)
        {
            CheckBox allCheckBox = sender as CheckBox;

            foreach (DataGridItem item in FileTypeList.Items)
            {
                string fileName = item.Cells[0].Text;
                if (fileName != "&nbsp;")
                {
                    FileTypeInfo fti = FileTypeSource[fileName] as FileTypeInfo;
                    if (fti != null)
                    {
                        CheckBox checkBox = item.Cells[1].FindControl("FileTypeCheckBox") as CheckBox;
                        if ((checkBox != null) && checkBox.Enabled)
                        {
                            fti.IsChecked = checkBox.Checked = allCheckBox.Checked;
                        }
                    }
                }
            }

            // See if there are any checked members.
            bool hasEntries = allCheckBox.Checked ? true : HasCheckedEntries;

            DeleteButton.Enabled = hasEntries;
            AllowButton.Enabled  = HasDisallowedEntries && hasEntries;
            DenyButton.Enabled   = HasAllowedEntries && hasEntries;
        }
Beispiel #8
0
        public IList <FileTypeInfo> FileTypeByParentIDGetList(int ParentID)
        {
            IList <FileTypeInfo> ilist = new List <FileTypeInfo>();
            DataTable            dt    = new DataTable();

            OleDbParameter[] param = new OleDbParameter[1];
            param[0]       = new OleDbParameter("@ParentID", OleDbType.VarWChar, 20);
            param[0].Value = ParentID;

            string sql = "select * from Cm_FileType where ParentID=@ParentID order by ParentID,ID";

            dt = DbHelper.ExecuteTable(constring, CommandType.Text, sql, param);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                FileTypeInfo info = new FileTypeInfo();
                info.ID       = Convert.ToInt32(dt.Rows[i]["ID"].ToString());
                info.ParentID = int.Parse(dt.Rows[i]["ParentID"].ToString());
                info.Code     = dt.Rows[i]["Code"].ToString();
                info.Alias    = dt.Rows[i]["Alias"].ToString();
                info.Title    = dt.Rows[i]["Title"].ToString();
                info.Remark   = dt.Rows[i]["Remark"].ToString();
                ilist.Add(info);
            }
            return(ilist);
        }
Beispiel #9
0
 public void AddSubtype(FileTypeInfo subtype)
 {
     if (subtypes == null)
     {
         subtypes = new List <FileTypeInfo>();
     }
     subtypes.Add(subtype);
 }
Beispiel #10
0
 private static bool ContainExtension(FileTypeInfo info, string target)
 {
     foreach (string extension in info.Extensions)
     {
         if (extension.ToUpper().Equals(target))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #11
0
        private string GetExtensionsString(FileTypeInfo info)
        {
            List <string> builder = new List <string>();

            foreach (string extension in info.Extensions)
            {
                builder.Add(string.Format("*.{0}", extension));
            }

            return(string.Join(";", builder));
        }
        /// <summary>
        /// 递归获取实体
        /// </summary>
        /// <param name="ilist">节点</param>
        /// <param name="ninfo">实体</param>
        private void GetInfo(IList <FileTypeInfo> ilist, FileTypeInfo ninfo)
        {
            ilist.Add(ninfo);
            var list = from tl in menuList
                       where tl.ParentID == ninfo.ID
                       select tl;

            foreach (FileTypeInfo info in list)
            {
                GetInfo(ilist, info);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Creates a stateful list of file type filters.
        /// </summary>
        /// <param name="policy">System policy object</param>
        /// <returns>A hashtable containing the file type filters.</returns>
        private Hashtable CreateFileTypeSource(SystemPolicy policy)
        {
            // Keep the state in a hashtable.
            Hashtable ht = new Hashtable();

            foreach (string s in policy.FileTypesExcludes)
            {
                ht[s] = new FileTypeInfo(s, Utils.ConvertFromRegEx(s), false, true);
            }

            return(ht);
        }
Beispiel #14
0
        public static void Run(FileType fileType, string audioPath, string dllPath)
        {
            FileTypeInfo info = Common.FileTypes[fileType];

            string[]  files  = Directory.GetFiles(audioPath, info.Extension, SearchOption.AllDirectories);
            Stopwatch watch  = Stopwatch.StartNew();
            var       encode = new Encode(files, new DspToolDll(DspToolType.Cafe64, dllPath), new DspToolVGAudio(), info.GetReader);

            encode.Run().ForAll(x => Console.WriteLine(PrintResult(x)));

            watch.Stop();
            Console.WriteLine(watch.Elapsed.TotalMilliseconds);
        }
        /// <summary>
        /// 递归获取目录节点
        /// </summary>
        /// <param name="tn">节点</param>
        /// <param name="tinfo">实体</param>
        private void GetNode(TreeNode tn, FileTypeInfo tinfo)
        {
            var list = from tl in menuList
                       where tl.ParentID == tinfo.ID
                       select tl;

            foreach (FileTypeInfo info in list)
            {
                TreeNode tnode = new TreeNode(info.Title);
                GetNode(tnode, info);
                tnode.Tag = info;
                tn.Nodes.Add(tnode);
            }
        }
Beispiel #16
0
        private static string GetFileMimeType(IFormFile file)
        {
            IFileTypeInterrogator interrogator = new FileTypeInterrogator.FileTypeInterrogator();

            byte[] fileBytes;
            using (var stream = new MemoryStream())
            {
                file.CopyTo(stream);
                fileBytes = stream.ToArray();
            }

            FileTypeInfo fileTypeInfo = interrogator.DetectType(fileBytes);

            return(fileTypeInfo.MimeType.ToLower());
        }
        /// <summary>
        /// 显示菜单Treeview
        /// </summary>
        private void QueryMenu()
        {
            nodeid   = 0;
            menuList = menuDal.FileTypeGetList();
            TreeNode     tn   = new TreeNode("根目录");
            FileTypeInfo info = new FileTypeInfo();

            info.ID = 0;
            GetNode(tn, info);
            tn.ExpandAll();
            tv_left.Nodes.Clear();
            tv_left.Nodes.Add(tn);

            nodeMax1 = 0;
            TreeNodeCollection tnc = tv_left.Nodes;

            GetNodeNameMax(tnc);
        }
Beispiel #18
0
            public bool IsSameOrSubtype(FileTypeInfo possibleSubtype)
            {
                if (this == possibleSubtype)
                {
                    return(true);
                }

                if (subtypes != null)
                {
                    foreach (FileTypeInfo subtype in Subtypes)
                    {
                        if (subtype.IsSameOrSubtype(possibleSubtype))
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
Beispiel #19
0
        /// <summary>
        /// 查询显示文件类型
        /// </summary>
        private void QueryFileType()
        {
            IFileType            ftDal  = new FileType();
            IList <FileTypeInfo> ftlist = ftDal.FileTypeGetList();
            IList <FileTypeInfo> ilist  = new List <FileTypeInfo>();

            FileTypeInfo pinfo = new FileTypeInfo();

            pinfo.ID = 0;
            GetFileTypeInfo(ftlist, ilist, pinfo);

            cb_FileType.Items.Clear();
            cb_FileType.DataSource    = ilist;
            cb_FileType.DisplayMember = "Title";
            cb_FileType.ValueMember   = "ID";
            //加一个空行
            //ListItem litem=new ListItem("","0");
            //cb_FileType.Items.Add(litem);
            cb_FileType.SelectedValue = 0;
        }
Beispiel #20
0
        /// <summary>
        /// Event handler that gets called when the file type checkbox is changed.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnFileTypeCheckChanged(Object sender, EventArgs e)
        {
            CheckBox     checkBox = sender as CheckBox;
            DataGridItem item     = checkBox.Parent.Parent as DataGridItem;
            string       fileName = item.Cells[0].Text;

            if (fileName != "&nbsp;")
            {
                FileTypeInfo fti = FileTypeSource[fileName] as FileTypeInfo;
                if (fti != null)
                {
                    fti.IsChecked = checkBox.Checked;

                    bool hasEntries = checkBox.Checked ? true : HasCheckedEntries;
                    DeleteButton.Enabled = hasEntries;
                    AllowButton.Enabled  = HasDisallowedEntries && hasEntries;
                    DenyButton.Enabled   = HasAllowedEntries && hasEntries;
                }
            }
        }
Beispiel #21
0
        /// <summary>
        /// Event handler that gets called when the delete button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnDeleteFileType(Object sender, EventArgs e)
        {
            // Get all of the values from the hashtable.
            Hashtable ht = FileTypeSource;

            FileTypeInfo[] ftInfoList = new FileTypeInfo[ht.Count];
            ht.Values.CopyTo(ftInfoList, 0);

            foreach (FileTypeInfo fti in ftInfoList)
            {
                if (fti.IsChecked)
                {
                    ht.Remove(fti.RegExFileName);
                }
            }

            // Reset the all files check box.
            AllFilesCheckBox.Checked = false;
            DeleteButton.Enabled     = false;

            // If there are no entries in the current view, set the current page back one page.
            if (CurrentFileOffset >= ht.Count)
            {
                CurrentFileOffset -= FileTypeList.PageSize;
                if (CurrentFileOffset < 0)
                {
                    CurrentFileOffset = 0;
                }
            }

            // Refresh the policy view.
            FileTypeList.DataSource = CreateFileTypeListView();
            FileTypeList.DataBind();
            SetPageButtonState();

            // Indicate an event that the list has changed.
            if (ListChanged != null)
            {
                ListChanged(this, e);
            }
        }
Beispiel #22
0
        public static void RunDecode(string[] args)
        {
            if (args.Length < 4)
            {
                Console.WriteLine("Usage: Atrac9 decode <audio file path> <at9 tools path>");
                return;
            }
            string audioPath = args[2];
            string exePath   = args[3];

            FileTypeInfo info = Common.FileTypes[FileType.Atrac9];

            string[]  files  = Directory.GetFiles(audioPath, info.Extension, SearchOption.AllDirectories);
            Stopwatch watch  = Stopwatch.StartNew();
            var       decode = new Decode(files, new At9ToolVGAudio(), new At9ToolExe(exePath));

            decode.Run().ForAll(x => Console.WriteLine(PrintResult(x)));

            watch.Stop();
            Console.WriteLine(watch.Elapsed.TotalMilliseconds);
        }
Beispiel #23
0
        /// <summary>
        /// Event handler that gets called when the add button is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void OnFileTypeAddClick(Object sender, EventArgs e)
        {
            string fileName = NewFileTypeName.Text;

            if ((fileName != null) && (fileName != String.Empty))
            {
                // Make sure that this entry is not already in the list.
                if (!FileTypeExists(fileName))
                {
                    Hashtable ht = FileTypeSource;
                    ht[fileName] = new FileTypeInfo(Utils.ConvertToRegEx(fileName), fileName, false, true);

                    // A new file was added to the list. Update the page buttons.
                    ++TotalFiles;

                    // Clear out the old entry.
                    NewFileTypeName.Text = String.Empty;

                    // Indicate an event that the list has changed.
                    if (ListChanged != null)
                    {
                        ListChanged(this, e);
                    }

                    // Refresh the policy view.
                    FileTypeList.DataSource = CreateFileTypeListView();
                    FileTypeList.DataBind();
                    SetPageButtonState();
                }
                else
                {
                    ShowError(GetString("FILETYPEALREADYEXISTS"));
                }
            }
            else
            {
                AddButton.Enabled = false;
            }
        }
Beispiel #24
0
        public IList <FileTypeInfo> FileTypeGetList()
        {
            IList <FileTypeInfo> ilist = new List <FileTypeInfo>();
            DataTable            dt    = new DataTable();

            string sql = "select * from Cm_FileType order by ParentID,ID";

            dt = DbHelper.ExecuteTable(constring, CommandType.Text, sql, null);

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                FileTypeInfo info = new FileTypeInfo();
                info.ID       = Convert.ToInt32(dt.Rows[i]["ID"].ToString());
                info.ParentID = int.Parse(dt.Rows[i]["ParentID"].ToString());
                info.Code     = dt.Rows[i]["Code"].ToString();
                info.Alias    = dt.Rows[i]["Alias"].ToString();
                info.Title    = dt.Rows[i]["Title"].ToString();
                info.Remark   = dt.Rows[i]["Remark"].ToString();
                ilist.Add(info);
            }
            return(ilist);
        }
Beispiel #25
0
        public string FileType_GetPath(int ID)
        {
            string path = "";
            IList <FileTypeInfo> alist = FileTypeGetList();
            FileTypeInfo         info  = FileTypeGetInfo(ID);
            IList <FileTypeInfo> ilist = new List <FileTypeInfo>();

            GetFileTypeList(alist, ilist, info);
            int count = ilist.Count;

            for (int i = count; i > 0; i--)
            {
                if (path == "")
                {
                    path = ilist[i - 1].Alias;
                }
                else
                {
                    path = path + "\\" + ilist[i - 1].Alias;
                }
            }
            return(path);
        }
Beispiel #26
0
        public override void Execute(ScriptState state)
        {
            string path = state.ResolvePath(File);

            state.Log.Status($"Exporting to {path}");
            FileTypeInfo fti = ForceType;

            if (ForceType == null)
            {
                var ext = System.IO.Path.GetExtension(path);
                if (!FileTypeInfo.TryParseName(ext, out fti))
                {
                    throw new Exception($"Unrecognised file extension \"{ext}\". Use a conventional extension or specify the type explicitly.");
                }
            }

            if (!fti.CanExport)
            {
                throw new Exception($"Cannot export {fti.FormatName}");
            }

            fti.Export(state.Data, path);
        }
Beispiel #27
0
        public FileTypeInfo FileTypeGetInfo(int ID)
        {
            FileTypeInfo info = new FileTypeInfo();
            DataTable    dt   = new DataTable();

            OleDbParameter[] param = new OleDbParameter[1];
            param[0]       = new OleDbParameter("@ID", OleDbType.VarWChar, 20);
            param[0].Value = ID;

            string sql = "select * from Cm_FileType where ID=@ID";

            dt = DbHelper.ExecuteTable(constring, CommandType.Text, sql, param);
            if (dt.Rows.Count > 0)
            {
                info.ID       = Convert.ToInt32(dt.Rows[0]["ID"].ToString());
                info.ParentID = int.Parse(dt.Rows[0]["ParentID"].ToString());
                info.Code     = dt.Rows[0]["Code"].ToString();
                info.Alias    = dt.Rows[0]["Alias"].ToString();
                info.Title    = dt.Rows[0]["Title"].ToString();
                info.Remark   = dt.Rows[0]["Remark"].ToString();
            }
            return(info);
        }
 private void tv_left_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
 {
     tv_left.SelectedNode = e.Node;
     if (tv_left.SelectedNode != null)
     {
         ClearInput();
         if (tv_left.SelectedNode.Text == "根目录")
         {
             ParentInfo          = null;
             lb_ParentTitle.Text = "根目录";
         }
         else
         {
             FileTypeInfo info = tv_left.SelectedNode.Tag as FileTypeInfo;
             if (info != null)
             {
                 ParentInfo          = info;
                 lb_ParentTitle.Text = info.Title;
                 tb_Code.Text        = info.Code;
             }
         }
         QueryData();
     }
 }
        private static string GetProjectFileInfo(Project.NodejsProjectNode project)
        {
            var fileTypeInfo = new Dictionary<string, FileTypeInfo>();
            foreach (var node in project.DiskNodes) {
                var file = node.Key;
                var matchedExt = _interestingFileExtensions.Where(ext => file.EndsWith(ext, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

                if (!string.IsNullOrEmpty(matchedExt)) {
                    var recordKey = string.Format("{0} ({1})", matchedExt, node.Value.ItemNode?.IsExcluded ?? true ? "excluded from project" : "included in project");
                    FileTypeInfo record;
                    if (!fileTypeInfo.TryGetValue(recordKey, out record)) {
                        record = fileTypeInfo[recordKey] = new FileTypeInfo();
                    }
                    record.UpdateForFile(file);
                }
            }

            var res = new StringBuilder();

            res.AppendLine("Project Info:");
            foreach (var entry in fileTypeInfo) {
                res.AppendLine(Indent(1, entry.Key + ":"));
                res.AppendLine(Indent(2, "Number of Files: " + entry.Value.Count));
                res.AppendLine(Indent(2, "Average Line Count: " + entry.Value.AverageLineLength));
                res.AppendLine(Indent(2, "Max Line Count: " + entry.Value.MaxLineLength));
            }

            return res.ToString();
        }
Beispiel #30
0
        private void DefineFileTypes()
        {
            var oneWeek = _enableCaching ? TimeSpan.FromDays(7) : (TimeSpan?)null;
            var oneHour = _enableCaching ? TimeSpan.FromHours(1) : (TimeSpan?)null;

            var fileTypes = new Dictionary<string, FileTypeInfo>()
            {
                {".avi", new FileTypeInfo{MimeType = "video/avi", Expiry = oneWeek}},
                {".mov", new FileTypeInfo{MimeType = "video/quicktime", Expiry = oneWeek}},
                {".mp3", new FileTypeInfo{MimeType = "video/mpeg",  Expiry = oneWeek}},

                {".bmp", new FileTypeInfo{MimeType = "image/bmp",  Expiry = oneWeek}},
                {".ico", new FileTypeInfo{MimeType = "image/ico",  Expiry = oneWeek}},
                {".jpg", new FileTypeInfo{MimeType = "image/jpeg",  Expiry = oneWeek}},
                {".jfif", new FileTypeInfo{MimeType = "image/jpeg",  Expiry = oneWeek}},
                {".jpeg", new FileTypeInfo{MimeType = "image/jpeg",  Expiry = oneWeek}},
                {".png", new FileTypeInfo{MimeType = "image/png",  Expiry = oneWeek}},
                {".tif", new FileTypeInfo{MimeType = "image/tif",  Expiry = oneWeek}},
                {".tiff", new FileTypeInfo{MimeType = "image/tif",  Expiry = oneWeek}},
                {".gif", new FileTypeInfo{MimeType = "image/gif",  Expiry = oneWeek}},

                {".html", new FileTypeInfo{MimeType = "text/html", Expiry = oneHour, Processing = FileProcessing.Html}},
                {".txt", new FileTypeInfo{MimeType = "text/plain"}},
                {".css", new FileTypeInfo{MimeType = "text/css", Expiry = oneWeek, Processing = FileProcessing.Css}},

                {".js", new FileTypeInfo{MimeType = "application/javascript", Expiry = oneHour, Processing = FileProcessing.JavaScript}},
                {".dart", new FileTypeInfo{MimeType = "application/dart", Expiry = oneHour, Processing = FileProcessing.Dart}},
            };

            fileTypes.Add(".htm", fileTypes[".html"]);
            fileTypes.Add(".shtml", fileTypes[".html"]);

            _defaultFileTypeInfo = fileTypes[".html"];
            _fileTypes = fileTypes;
        }
        /// <summary>
        /// 保存数据
        /// </summary>
        private void SaveData()
        {
            FileTypeInfo info = new FileTypeInfo();

            info.Code   = tb_Code.Text.Trim();
            info.Title  = tb_Title.Text.Trim();
            info.Remark = tb_Remark.Text.Trim();
            info.Alias  = tb_Alias.Text.Trim();

            if (info.Code == "")
            {
                MessageBox.Show("请输入编码。");
                return;
            }
            if (info.Title == "")
            {
                MessageBox.Show("请输入名称。");
                return;
            }
            if (info.Alias == "")
            {
                MessageBox.Show("请输入别名。");
                return;
            }

            int rst = -1;

            if (lb_ID.Text == "")
            {
                if (ParentInfo == null)
                {
                    if (info.Code.Length != 3)
                    {
                        MessageBox.Show("请输入3位长度编码。");
                        return;
                    }
                    info.ParentID = 0;
                }
                else
                {
                    if (info.Code.Length - ParentInfo.Code.Length != 3)
                    {
                        MessageBox.Show("请输入3位长度编码。");
                        return;
                    }
                    info.ParentID = ParentInfo.ID;
                }
                rst = menuDal.FileType_Add(info);
            }
            else
            {
                info.ID = int.Parse(lb_ID.Text);
                rst     = menuDal.FileType_Edit(info);
            }

            QueryData();

            if (rst == 1)
            {
                MessageBox.Show("保存成功。");
            }
            else
            {
                MessageBox.Show("保存失败。");
            }
        }
 public void AddSubtype(FileTypeInfo subtype)
 {
     if (subtypes == null)
         subtypes = new List<FileTypeInfo>();
     subtypes.Add(subtype);
 }
            public bool IsSameOrSubtype(FileTypeInfo possibleSubtype)
            {
                if (this == possibleSubtype)
                    return true;

                if (subtypes != null)
                {
                    foreach (FileTypeInfo subtype in Subtypes)
                    {
                        if (subtype.IsSameOrSubtype(possibleSubtype))
                            return true;
                    }
                }

                return false;
            }
Beispiel #34
0
        private void PopulateFileTypes()
        {
            fileFactories = new List <FileFactory>
            {
                new LB83Factory(),
                new LABNFactory(),
                new KAPLFactory(),
                new BUNDFactory(),
                new ForgeFactory(),
                new TTARCH2Factory(),
                // SCUMM 3 and 5 files are very general (they'll accept anything with ASCII
                // chars at the right spot), so check more specific formats first
                new SCUMM3Factory(),
                new SCUMM5Factory(),
                new SCUMM1Factory(),
                // ttarch needs decryption checks for determining file format, so leave it for last
                new TTARCHFactory(),
                new UnknownFactory()
            };

            // Build file type info (for e.g. Open dialog):
            FileTypeInfos = new FileTypeInfos();

            Type         attrType     = typeof(FileTypeAttribute);
            FileTypeInfo allSupported = new FileTypeInfo("All supported files");

            FileTypeInfos.Add(allSupported);

            foreach (var factory in fileFactories)
            {
                var      type  = factory.GetType();
                object[] attrs = type.GetCustomAttributes(attrType, false);

                foreach (object attr in attrs)
                {
                    FileTypeAttribute ftAttr = attr as FileTypeAttribute;
                    if (ftAttr == null)
                    {
                        continue;
                    }

                    string       desc = ftAttr.Description;
                    FileTypeInfo info = FileTypeInfos.GetOrCreate(desc);

                    foreach (string ext in ftAttr.Extensions)
                    {
                        info.AddExtension("*." + ext);
                        allSupported.AddExtension("*." + ext);
                    }

                    info.SortExtensions();
                }
            }

            allSupported.SortExtensions();

            FileTypeInfo allFiles = new FileTypeInfo("All files");

            allFiles.AddExtension("*.*");
            FileTypeInfos.Add(allFiles);
        }
Beispiel #35
0
 public FileWrapper(DirectoryInfo rootDirectory, string relativePath, FileTypeInfo fileTypeInfo)
 {
     _fullFilePath = Path.Combine(rootDirectory.FullName, relativePath);
     _fileTypeInfo = fileTypeInfo;
 }