public void SaveMetaFile(string filename) { Meta_File mf = new Meta_File(); mf.files = Files; mf.Size_part = PartSize; mf.Size_treck = size; mf.name = Name; mf.IP_Port_Server = server; mf.ID_Client = IdClient; mf.ID_matirial = IdMaterial; BinaryFormatter bf = new BinaryFormatter(); FileStream fs = new FileStream(filename, FileMode.Create); bf.Serialize(fs, mf); fs.Close(); }
/// <summary> /// Конструктор, вызывается при добавлении раздачи из существующего метафайла /// </summary> /// <param name="PathToMetaFile">Путь к метафайлу</param> public Material(string dir, string PathToMetaFile) { ProgramMaterials.cur_file = 0; BinaryFormatter bf = new BinaryFormatter(); if (!System.IO.File.Exists(PathToMetaFile)) { throw new Exceptions.IsNotMetafile(); } FileStream metafile = new FileStream(PathToMetaFile, FileMode.Open); if (dir[dir.Length - 1] != '\\') { dir += "\\"; } try { Meta_File mf = (Meta_File)bf.Deserialize(metafile); IdClient = mf.ID_Client; IdMaterial = mf.ID_matirial; Name = mf.name; server = mf.IP_Port_Server; Files = new File[mf.files.Length]; for (int i = 0; i < mf.files.Length; i++) { ProgramMaterials.cur_file = i; Files[i] = new File(mf.files[i].path, dir + mf.files[i].path, mf.files[i].File_Size, mf.files[i].Count_Parts_, mf.files[i].Hashs, mf.files[i].Part_size); } filese_that_need_to_download = new int[Files.Length]; cread_map_download(); } catch (System.Runtime.Serialization.SerializationException) { throw new Exceptions.WrongMetafileFormat(); } finally { metafile.Close(); } SetSize(); SetStatus(); }