Beispiel #1
0
        private List <FInfo> GetFilesFromPath(string srcPath, int plen)
        {
            List <FInfo> fileInfo = new List <FInfo>();

            try
            {
                // 得到源目录的文件列表,该里面是包含文件以及目录路径的一个数组
                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
                // 遍历所有的文件和目录
                foreach (string file in fileList)
                {
                    // 先当作目录处理如果存在这个目录就重新调用GetFileNum(string srcPath)
                    if (System.IO.Directory.Exists(file))
                    {
                        fileInfo.AddRange(GetFilesFromPath(file, plen));
                    }
                    else
                    {
                        FInfo f = new FInfo();
                        f.Name = file.Substring(plen + 1);
                        System.IO.FileInfo fif = new System.IO.FileInfo(file);
                        f.Time = fif.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");

                        fileInfo.Add(f);
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            return(fileInfo);
        }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            List <string> listExten = new List <string>();              //建立泛型集合物件
            DirectoryInfo DInfo     = new DirectoryInfo(textBox1.Text); //建立DirectoryInfo物件

            FileInfo[] FInfos   = DInfo.GetFiles();                     //取得資料夾中的所有文件
            string     strExten = "";                                   //定義一個變數,用來存儲文件擴展名

            foreach (FileInfo FInfo in FInfos)                          //深度搜尋所有文件
            {
                strExten = FInfo.Extension;                             //記錄文件擴展名
                if (!listExten.Contains(strExten))                      //判斷泛型集合中是否已經存在該擴展名
                {
                    listExten.Add(strExten.TrimStart('.'));             //將擴展名去掉.之後新增到泛型集合中
                }
            }
            for (int i = 0; i < listExten.Count; i++)                                             //深度搜尋泛型集合
            {
                Directory.CreateDirectory(textBox1.Text + listExten[i]);                          //建立資料夾
            }
            foreach (FileInfo FInfo in FInfos)                                                    //深度搜尋所有文件
            {
                FInfo.MoveTo(textBox1.Text + FInfo.Extension.TrimStart('.') + "\\" + FInfo.Name); //將文件移動到對應的資料夾中
            }
            MessageBox.Show("整理完畢!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            List <string> listExten = new List <string>();              //创建泛型集合对象
            DirectoryInfo DInfo     = new DirectoryInfo(textBox1.Text); //创建DirectoryInfo对象

            FileInfo[] FInfos   = DInfo.GetFiles();                     //获取文件夹中的所有文件
            string     strExten = "";                                   //定义一个变量,用来存储文件扩展名

            foreach (FileInfo FInfo in FInfos)                          //遍历所有文件
            {
                strExten = FInfo.Extension;                             //记录文件扩展名
                if (!listExten.Contains(strExten))                      //判断泛型集合中是否已经存在该扩展名
                {
                    listExten.Add(strExten.TrimStart('.'));             //将扩展名去掉.之后添加到泛型集合中
                }
            }
            for (int i = 0; i < listExten.Count; i++)                                             //遍历泛型集合
            {
                Directory.CreateDirectory(textBox1.Text + listExten[i]);                          //创建文件夹
            }
            foreach (FileInfo FInfo in FInfos)                                                    //遍历所有文件
            {
                FInfo.MoveTo(textBox1.Text + FInfo.Extension.TrimStart('.') + "\\" + FInfo.Name); //将文件移动到对应的文件夹中
            }
            MessageBox.Show("整理完毕!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Beispiel #4
0
        private static FieldInfo[] GetSaveableFields <T>(T Input) where T : Panel
        {
            List <FieldInfo> WorkingTable = new List <FieldInfo>();

            FieldInfo[] fields = Input.GetType().GetFields();
            foreach (FieldInfo FInfo in fields)
            {
                object[] FInfoAttribs   = FInfo.GetCustomAttributes(typeof(PackerAttrib), true);               // Add if PackerAttrib is assigned
                bool     ShouldContinue = false;
                foreach (PackerAttrib a in FInfoAttribs)
                {
                    if (a.ShouldIgnore)
                    {
                        ShouldContinue = true;
                    }
                }
                if (ShouldContinue)
                {
                    continue;
                }
                object[] FInfoAttribs_CA = FInfo.GetCustomAttributes(typeof(CategoryAttribute), true);                 // Add if CategoryAttribute is assigned
                if (!FInfoAttribs.Any() && !FInfoAttribs_CA.Any())
                {
                    continue;
                }
                WorkingTable.Add(FInfo);
            }
            return(WorkingTable.ToArray());
        }
Beispiel #5
0
        /// <summary>
        /// OLV Double Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void olvFiles_DoubleClick(object sender, EventArgs e)
        {
            if (olvFiles.SelectedIndex >= 0)                    // If selected Item
            {
                // ----- Objects -----
                if (objectForm)
                {
                    frmEditObjects form = new frmEditObjects();
                    form.ShowDialog(((Objects)olvFiles.SelectedObject).ID);
                    form.Dispose();
                    UpdateOLVObject();                  // Update OLV
                }
                // ----- Files -----
                else
                {
                    FInfo info = (FInfo)olvFiles.SelectedObject;

                    try
                    {
                        if (File.Exists(info.Path) || Directory.Exists(info.Path))
                        {
                            Process.Start(info.Path);
                        }
                        else
                        {
                            Process.Start(RelativePath + Path.DirectorySeparatorChar + info.Path);
                        }
                    }
                    catch (Exception Err)
                    {
                        Dialogs.ShowErr(Err.Message, Lng.Get("Error"));
                    }
                }
            }
        }
Beispiel #6
0
        private void frmEditFile_Load(object sender, EventArgs e)
        {
            FInfo info = global.GetFInfo(FileText);

            if (info != null)
            {
                txtName.Text        = info.Name;
                txtPath.Text        = info.Path;
                txtVersion.Text     = info.Version;
                txtGroup.Text       = info.Group;
                txtDescription.Text = info.Description;
            }
        }
        private static void zhengli(string path, string zi)
        {
            List <string> listExten = new List <string>();

            DirectoryInfo DInfo = new DirectoryInfo(zi);

            FileInfo[] FInfos   = DInfo.GetFiles();
            string     strExten = "";

            foreach (FileInfo FInfo in FInfos)
            {
                strExten = FInfo.Extension;
                if (!listExten.Contains(strExten))
                {
                    listExten.Add(strExten.TrimStart('.'));
                }
            }
            for (int i = 0; i < listExten.Count; i++)
            {
                Directory.CreateDirectory(path + "\\" + listExten[i]);
            }
            foreach (FileInfo FInfo in FInfos)
            {
                int    flag        = 1;
                string target      = path + "\\" + FInfo.Extension.TrimStart('.') + "\\" + FInfo.Name;
                string farget_name = "";
                while (File.Exists(target))//如果有重名的文件就重命名
                {
                    string   temp = "";
                    string[] tmp  = FInfo.Name.Split('.');
                    temp        = tmp[0] + "(" + flag.ToString() + ")";
                    farget_name = temp + "." + FInfo.Extension;

                    target = path + "\\" + FInfo.Extension.TrimStart('.') + "\\" + farget_name;
                    flag++;
                }


                FInfo.MoveTo(target);
            }



            string[] zimulu;
            zimulu = Directory.GetDirectories(zi);
            foreach (string s in zimulu)
            {
                zhengli(path, s);
            }
        }
Beispiel #8
0
        internal void GetFInfoVecs(int fIdx, out Vector3 texOrg,
                                   out Vector3 t2WU, out Vector3 t2WV, out Vector3 start)
        {
            FInfo fi = mFInfos[fIdx];

            if (fi == null)
            {
                texOrg = t2WU = t2WV = start = Vector3.One;
                return;
            }

            Vector3 center;

            mFInfos[fIdx].GetVecs(out texOrg, out t2WU, out t2WV, out center);

            start = mLightPoints[fIdx][0];              //should be reasonably close
        }
Beispiel #9
0
        public virtual string Write(object instance, FInfo i, string[] args)
        {
            if (args.Length != ExpectedArgCount)
            {
                return($"Writing {Type.Name}: Expected {ExpectedArgCount} arg, got {args.Length}.");
            }

            object o = Convert(args, out string error);

            if (error != null)
            {
                return(error);
            }

            i.SetValue(instance, o);
            return(null);
        }
Beispiel #10
0
        internal LightData(BinaryReader br, Map map, SharedForms.Output outForm)
        {
            mNumSamples = br.ReadInt32();
            int numFaces = br.ReadInt32();

            mLightPoints = new Vector3[numFaces][];
            mInSolid     = new bool[numFaces][];
            mPlanes      = new GFXPlane[numFaces];
            mFInfos      = new FInfo[numFaces];

            outForm.Print("Reading " + numFaces + " faces...\n");
            outForm.UpdateProgress(0, numFaces, 0);

            int numPointsTotal = 0;

            for (int i = 0; i < numFaces; i++)
            {
                int numPoints = br.ReadInt32();

                mLightPoints[i] = new Vector3[numPoints];
                mInSolid[i]     = new bool[numPoints];

                for (int j = 0; j < numPoints; j++)
                {
                    mLightPoints[i][j] = FileUtil.ReadVector3(br);
                    mInSolid[i][j]     = map.IsPointInSolidSpace(mLightPoints[i][j]);
                    numPointsTotal++;
                }

                mPlanes[i] = new GFXPlane();
                mPlanes[i].Read(br);

                bool bFInfo = br.ReadBoolean();
                if (bFInfo)
                {
                    mFInfos[i] = new FInfo();
                    mFInfos[i].ReadVecs(br);
                }
                outForm.UpdateProgress(0, numFaces, i);
            }

            outForm.UpdateProgress(0, numFaces, 0);
            outForm.Print("Read " + numPointsTotal + " total points.\n");
        }
Beispiel #11
0
        /// <summary>
        /// ShowDialog with ID (Edit)
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public DialogResult ShowDialog(ref string text, string relativePath)
        {
            FileText     = text;
            RelativePath = relativePath;
            DialogResult res = base.ShowDialog();       // Base ShowDialog

            if (res == DialogResult.OK)
            {
                FInfo info = new FInfo();

                info.Name        = txtName.Text;
                info.Path        = txtPath.Text;
                info.Version     = txtVersion.Text;
                info.Group       = txtGroup.Text;
                info.Description = txtDescription.Text;

                text = global.FInfoToText(info);
            }

            return(res);
        }
Beispiel #12
0
        public static Panel PanelFromPanelInfo(DPanelInfo ifo)
        {
            string type = ifo.GetString("___type");

            if (type == null)
            {
                return(null);
            }
            string ParentIndex = ifo.GetString("___parent");
            Panel  p           = Derma.New(type);

            FieldInfo[]    fields     = GetSaveableFields(p);
            PropertyInfo[] properties = GetSaveableProperties(p);
            foreach (FieldInfo FInfo in fields)
            {
                Type   CastType  = FInfo.FieldType;
                object SavedProp = ifo.GetObject(FInfo.Name, CastType);
                if (SavedProp == null)
                {
                    continue;
                }
                FInfo.SetValue(p, SavedProp);
            }
            foreach (PropertyInfo FInfo in properties)
            {
                Type   CastType  = FInfo.PropertyType;
                object SavedProp = ifo.GetObject(FInfo.Name, CastType);
                if (SavedProp == null)
                {
                    continue;
                }
                FInfo.SetValue(p, SavedProp, null);
            }
            if (ParentIndex != null)
            {
                p.parentIdentifier = ParentIndex;
            }
            return(p);
        }
Beispiel #13
0
        private static PropertyInfo[] GetSaveableProperties <T>(T Input) where T : Panel
        {
            List <PropertyInfo> WorkingTable = new List <PropertyInfo>();

            PropertyInfo[] fields = Input.GetType().GetProperties();
            foreach (PropertyInfo FInfo in fields)
            {
                if (FInfo.GetSetMethod() == null)
                {
                    continue;
                }
                if (FInfo.Name == "X" || FInfo.Name == "Y")
                {
                    continue;
                }
                object[] FInfoAttribs   = FInfo.GetCustomAttributes(typeof(PackerAttrib), true);               // Add if PackerAttrib is assigned
                bool     ShouldContinue = false;
                foreach (PackerAttrib a in FInfoAttribs)
                {
                    if (a.ShouldIgnore == true)
                    {
                        ShouldContinue = true;
                    }
                }
                if (ShouldContinue)
                {
                    continue;
                }
                object[] FInfoAttribs_CA = FInfo.GetCustomAttributes(typeof(CategoryAttribute), true);                 // Add if CategoryAttribute is assigned
                object[] FInfoAttribs_ED = FInfo.GetCustomAttributes(typeof(EditorAttribute), true);
                if (!FInfoAttribs.Any() && !FInfoAttribs_CA.Any() && !FInfoAttribs_ED.Any())
                {
                    continue;
                }
                WorkingTable.Add(FInfo);
            }
            return(WorkingTable.ToArray());
        }
Beispiel #14
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (olvFiles.SelectedObject != null)
            {
                // ----- Objects -----
                if (objectForm)
                {
                    frmAddObject form   = new frmAddObject();
                    Guid         ID     = ((Objects)olvFiles.SelectedObject).ID;
                    string       OrigID = ID.ToString();
                    form.ShowDialog(ref ID);
                    if (ID != Guid.Empty)
                    {
                        FileText   = FileText.Replace(OrigID, ID.ToString());
                        FileText   = FileText.Replace(";;", ";");
                        ObjectList = global.GetObjectsFromText(FileText);

                        UpdateOLVObject();
                    }
                }
                // ----- Files -----
                else
                {
                    FInfo       info     = (FInfo)olvFiles.SelectedObject;
                    string      text     = global.FInfoToText(info);
                    string      textOgig = text;
                    frmEditFile form     = new frmEditFile();
                    if (form.ShowDialog(ref text, RelativePath) == DialogResult.OK)
                    {
                        FileText = FileText.Replace(textOgig, text);
                        FileText = FileText.Replace(";;", ";");
                        FileList = global.GetFInfoList(FileText);

                        UpdateOLV();
                    }
                }
            }
        }
Beispiel #15
0
        /// <summary>
        /// Convert a Panel to a DPanelInfo
        /// </summary>
        /// <typeparam name="T">Derives from Panel</typeparam>
        /// <param name="Input">Any object deriving from Panel</param>
        /// <returns></returns>
        public static DPanelInfo PanelToInfo <T>(T Input) where T : Panel        // Must be a Panel
        {
            Type InputType = Input.GetType();

            FieldInfo[]    fields     = GetSaveableFields(Input);
            PropertyInfo[] properties = GetSaveableProperties(Input);
            DPanelInfo     ifo        = new DPanelInfo();

            foreach (FieldInfo FInfo in fields)
            {
                object val = FInfo.GetValue(Input);
                Type   t   = val.GetType();
                string key = FInfo.Name;
                // If I need to add more, tell me @Gbps
                if (t == typeof(string))
                {
                    ifo.Insert(key, Encoding.UTF8.GetBytes((string)val));
                }
                else if (t == typeof(int))
                {
                    ifo.Insert(key, BitConverter.GetBytes((int)val));
                }
                else if (t == typeof(bool))
                {
                    ifo.Insert(key, BitConverter.GetBytes((bool)val));
                }
                else if (t == typeof(char))
                {
                    ifo.Insert(key, BitConverter.GetBytes((char)val));
                }
                else if (t == typeof(float))
                {
                    ifo.Insert(key, BitConverter.GetBytes((float)val));
                }
                else if (t == typeof(double))
                {
                    ifo.Insert(key, BitConverter.GetBytes((double)val));
                }
                else if (t == typeof(List <string>))
                {
                    ifo.Insert(key, SerializeStringList((List <string>)val));
                }
            }
            foreach (PropertyInfo FInfo in properties)
            {
                object val = FInfo.GetValue(Input, null);
                Type   t   = val.GetType();
                string key = FInfo.Name;
                // If I need to add more, tell me @Gbps
                if (t == typeof(string))
                {
                    ifo.Insert(key, Encoding.UTF8.GetBytes((string)val));
                }
                else if (t == typeof(int))
                {
                    ifo.Insert(key, BitConverter.GetBytes((int)val));
                }
                else if (t == typeof(bool))
                {
                    ifo.Insert(key, BitConverter.GetBytes((bool)val));
                }
                else if (t == typeof(char))
                {
                    ifo.Insert(key, BitConverter.GetBytes((char)val));
                }
                else if (t == typeof(float))
                {
                    ifo.Insert(key, BitConverter.GetBytes((float)val));
                }
                else if (t == typeof(double))
                {
                    ifo.Insert(key, BitConverter.GetBytes((double)val));
                }
                else if (t == typeof(List <string>))
                {
                    ifo.Insert(key, SerializeStringList((List <string>)val));
                }
            }
            if (Input.hasParent && Input.parent)
            {
                ifo.Insert("___parent", Encoding.UTF8.GetBytes(Input.parent.varname));
            }
            ifo.Insert("___type", Encoding.UTF8.GetBytes(Input.GetType().Name));
            return(ifo);
        }
Beispiel #16
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int count = olvFiles.SelectedObjects.Count;

            // ----- If selected 1 Item -----
            if (count == 1)
            {
                // ----- Objects -----
                if (objectForm)
                {
                    Objects info   = (Objects)olvFiles.SelectedObject;
                    string  itemID = info.ID.ToString();

                    if (Dialogs.ShowQuest(Lng.Get("DeleteItem", "Really delete item") + " \"" + info.Name + "\"?", Lng.Get("Delete")) == DialogResult.Yes)
                    {
                        FileText = FileText.Replace(itemID, "");
                        FileText = FileText.Replace(";;", ";");
                        if (FileText == ";")
                        {
                            FileText = "";
                        }

                        ObjectList = global.GetObjectsFromText(FileText);

                        UpdateOLVObject();
                    }
                }
                // ----- Files -----
                else
                {
                    FInfo  info = (FInfo)olvFiles.SelectedObject;
                    string text = global.FInfoToText(info);

                    if (Dialogs.ShowQuest(Lng.Get("DeleteItem", "Really delete item") + " \"" + info.Name + "\"?", Lng.Get("Delete")) == DialogResult.Yes)
                    {
                        FileText = FileText.Replace(text, "");
                        FileText = FileText.Replace(";;", ";");
                        if (FileText == ";")
                        {
                            FileText = "";
                        }

                        FileList = global.GetFInfoList(FileText);

                        UpdateOLV();
                    }
                }
            }
            // ----- If selected more Items -----
            else if (count > 1)                 // If selected Item
            {
                // ----- Objects -----
                if (objectForm)
                {
                    if (Dialogs.ShowQuest(Lng.Get("DeleteItems", "Really delete selected items") + " (" + count.ToString() + ")?", Lng.Get("Delete")) == DialogResult.Yes)
                    {
                        foreach (var item in olvFiles.SelectedObjects) // Find Object
                        {
                            string itemID = ((Objects)item).ID.ToString();
                            FileText = FileText.Replace(itemID, "");
                            FileText = FileText.Replace(";;", ";");
                            if (FileText == ";")
                            {
                                FileText = "";
                            }
                        }
                        ObjectList = global.GetObjectsFromText(FileText);
                        UpdateOLVObject();
                    }
                }
                // ----- Files -----
                else
                {
                    if (Dialogs.ShowQuest(Lng.Get("DeleteItems", "Really delete selected items") + " (" + count.ToString() + ")?", Lng.Get("Delete")) == DialogResult.Yes)
                    {
                        foreach (var item in olvFiles.SelectedObjects) // Find Object
                        {
                            string text = global.FInfoToText((FInfo)item);
                            FileText = FileText.Replace(text, "");
                            FileText = FileText.Replace(";;", ";");
                            if (FileText == ";")
                            {
                                FileText = "";
                            }
                        }
                        FileList = global.GetFInfoList(FileText);
                        UpdateOLV();
                    }
                }
            }
        }
Beispiel #17
0
        /// <summary>
        /// Assign all variables to their configured values
        /// </summary>
        /// <param name="Config">Dictionary of variable names and values</param>
        public static void LoadConfig(Dictionary <string, object> Config)
        {
            foreach (Type AssemblyType in Assembly.GetExecutingAssembly().GetTypes()
                     ) // Loop through all types in the assembly
            {
                foreach (FieldInfo FInfo in AssemblyType.GetFields()
                         .Where(f => Attribute.IsDefined(f, typeof(SaveAttribute)))
                         )    // Loop through all fields with the save attribute defined
                {
                    // Get field name and type in our format
                    string Name   = $"{AssemblyType.Name}_{FInfo.Name}";
                    Type   FIType = FInfo.FieldType;

                    object DefaultInfo = FInfo.GetValue(null);                 // Get the default value for the fieldinfo


                    if (!Config.ContainsKey(Name))                 // If the field does not exist in the configuration dictionary
                    {
                        Config.Add(Name, DefaultInfo);
                    }

                    try                 //Try to parse intermediate JSON because the object itself isnt actually deserialized or something
                    {
                        // If field is an array, set the field variable to a JArray
                        if (Config[Name].GetType() == typeof(JArray))
                        {
                            Config[Name] = ((JArray)Config[Name]).ToObject(FInfo.FieldType);
                        }

                        // If field is an object, set the field variable to JObject
                        if (Config[Name].GetType() == typeof(JObject))
                        {
                            Config[Name] = ((JObject)Config[Name]).ToObject(FInfo.FieldType);
                        }

                        // Assign field values
                        FInfo.SetValue(null,
                                       FInfo.FieldType.IsEnum
                                                            ? Enum.ToObject(FInfo.FieldType, Config[Name])
                                                            : Convert.ChangeType(Config[Name], FInfo.FieldType));
                    }
                    catch
                    {
                        //#if DEBUG
                        DebugUtilities.Log("Error loading config value: " + Name);
                        //#endif
                        Config[Name] = DefaultInfo;
                    }
                }
            }

            DebugUtilities.Log("Setting default colors...");

            foreach (var identifier in ColorOptions.DefaultColorDict)
            {
                if (!ColorOptions.ColorDict.ContainsKey(identifier.Key))
                {
                    ColorOptions.ColorDict.Add(identifier.Key, new ColorVariable(identifier.Value));
                }
            }

            foreach (var newIdentifier in ColorOptions.ColorDict.ToList())
            {
                if (!ColorOptions.DefaultColorDict.ContainsKey(newIdentifier.Key))
                {
                    ColorOptions.ColorDict.Remove(newIdentifier.Key);
                }
            }

            DebugUtilities.Log("Setting defualt hotkeys...");

            foreach (var kvp in HotkeyOptions.DefaultHotkeyDict)
            {
                foreach (var kvp2 in kvp.Value)
                {
                    if (!HotkeyOptions.UnorganizedHotkeys.ContainsKey(kvp2.Key))
                    {
                        HotkeyOptions.UnorganizedHotkeys.Add(kvp2.Key, kvp2.Value);
                    }
                }
            }

            foreach (var str in HotkeyOptions.UnorganizedHotkeys.ToList())
            {
                if (HotkeyOptions.DefaultHotkeyDict.All(kvp => !kvp.Value.ContainsKey(str.Key)))
                {
                    HotkeyOptions.UnorganizedHotkeys.Remove(str.Key);
                }
            }

            DebugUtilities.Log("Saving config...");

            SaveConfig(Config);
        }
Beispiel #18
0
 public virtual string MakeString(object instance, FInfo i)
 {
     return(Read(instance, i)?.ToString() ?? "null");
 }
Beispiel #19
0
 public virtual object Read(object instance, FInfo i)
 {
     return(i.GetValue(instance));
 }