//Inicializar um ficheiro a partir de um ficheiro local public FileModel(string NewFilePath, string OldFilePath, string NewNetID, bool NewWillDownload = true) { FileVersion = 1; FileName = NewFilePath.Substring(NewFilePath.LastIndexOf('\\') + 1); String PathPastaMae = NewFilePath.Remove(NewFilePath.LastIndexOf('\\')); if (!MainProps.EvryFolder.Exists(Obj => Obj.RelativePath == PathPastaMae)) { PastaRoot = new FolderModel(PathPastaMae); } else { PastaRoot = MainProps.EvryFolder.Find(Obj => Obj.RelativePath == PathPastaMae); } if (File.Exists(OldFilePath)) { File.Move(OldFilePath, Environment.CurrentDirectory + NewFilePath); } FilePath = NewFilePath; byte[] bytes = TCreator.GetBytesFromFile(NewFilePath); Torrent torrent = TCreator.GetTorrentFromByte(bytes); if (TorrentClientAPI.fastResume.ContainsKey(torrent.InfoHash.ToHex())) { Tmanager.LoadFastResume(new FastResume((BEncodedDictionary)TorrentClientAPI.fastResume[torrent.InfoHash.ToHex()])); } else { Tmanager = new TorrentManager(torrent, Environment.CurrentDirectory); } NetID = NewNetID; WillDownload = NewWillDownload; FileID = FSDatabaseFunctions.AddFileGetFileID(FilePath, NetID, bytes); ToggleWillDownload(); DEP = new SqlDependency(new SqlCommand("Select * FROM Files WHERE FileID = " + FileID, ConnectionStuff.con)); DEP.OnChange += new OnChangeEventHandler(FileChangedRemotelyEH); PastaRoot.ChildFiles.Add(this); }
//Inicializar ficheiro a partir de um ficheiro na base de dados public FileModel(int NewFileID, int NewFileVersion, byte[] TorrentBytes, string NewFilePath, string NewNetID, bool NewWillDownload = false) { FileID = NewFileID; FileVersion = NewFileVersion; FileName = NewFilePath.Substring(NewFilePath.LastIndexOf('\\') + 1); String PathPastaMae = NewFilePath.Remove(NewFilePath.LastIndexOf('\\')); if (!MainProps.EvryFolder.Exists(Obj => Obj.RelativePath == PathPastaMae)) { PastaRoot = new FolderModel(PathPastaMae); } else { PastaRoot = MainProps.EvryFolder.Find(Obj => Obj.RelativePath == PathPastaMae); } Tmanager = new TorrentManager(TCreator.GetTorrentFromByte(TorrentBytes), Environment.CurrentDirectory + PathPastaMae + "\\");; FilePath = NewFilePath; NetID = NewNetID; WillDownload = NewWillDownload; ToggleWillDownload(); DEP = new SqlDependency(new SqlCommand("Select * FROM Files WHERE FileId = " + FileID, ConnectionStuff.con)); DEP.OnChange += new OnChangeEventHandler(FileChangedRemotelyEH); PastaRoot.ChildFiles.Add(this); }