private void AddMate(MateFile mate)
 {
     AddFiles(mate.Params
         .OfType<ParamTex>()
         .Where(i => i.TexAsset != null)
         .Select(i => DataManager.Instance.FindItem(i.TexFileName) as BaseFile)
         .Where(i => i != null));
 }
        private void SetData(MateFile value)
        {
            if(value == data)
                return;

            data    = value;

            UpdateView();
        }
 public static void ToFile(string file, MateFile data)
 {
     using(var s= File.OpenWrite(file))
     using(var w = new BinaryWriter(s))
     {
         WriteString(w, data.Magic);
         w.Write(data.Version);
         Write(w, WriteString, data.Descriptions);
         WriteParamList(w, data.Params);
         WriteString(w, "end");
         w.Flush();
         s.SetLength(s.Position);
     }
 }
        public static MateFile FromFile(string file)
        {
            var data= new MateFile() { FileName= file };

            using(var s= File.OpenRead(file))
            using(var r = new BinaryReader(s))
            {
                data.Magic      = ReadString(r);
                data.Version    = r.ReadInt32();
                data.Descriptions= ReadList(r, 4, ReadString);
                data.Params     = ReadParamList(r);
            }

            return data;
        }
        private void Add(MateFile data)
        {
            Materials[Path.GetFileName(data.FileName).ToUpper()]= data;

            OnDataAdded(new DataFileEventArgs(data));
        }
        private void CloneMateFile(MateFile file, string newname)
        {
            var clone       = MateFile.FromFile(file.FileName);
            clone.FileName  = newname;

            ReplaceDescription(clone.Descriptions);

            foreach(var i in clone.Params.OfType<ParamTex>())
            {
                if(null != i.TexName)
                    i.TexName  = Replacer.ReplaceFileName(i.TexName);

                if(i.TexAsset != null)
                    i.TexAsset  = Replacer.ReplaceFileName(i.TexAsset);
            }

            if(ConfirmOverride(clone.FileName) == DialogResult.Yes)
            {
                MateFile.ToFile(clone.FileName, clone);
                AddCopiedFile(clone);
            }
        }
 private void tsbLoadBackup_Click(object sender, EventArgs e)
 {
     try
     {
         var data        = MateFile.FromFile(Data.GetBackupFileName());
         data.FileName   = Path.ChangeExtension(data.FileName, ".mate");
         Data            = data;
     } catch {}
 }