Beispiel #1
0
        //Inicializador da pasta do ambiente
        public FolderModel(string FolderPath, bool IsNetsFolder = false)
        {
            FullPath     = Environment.CurrentDirectory + FolderPath;
            RelativePath = FolderPath;
            String PathPastaMae = FolderPath.Remove(FolderPath.LastIndexOf('\\'));

            if (!MainProps.EvryFolder.Exists(Obj => Obj.RelativePath == PathPastaMae) && !IsNetsFolder)
            {
                RootFolder = new FolderModel(PathPastaMae);
                RootFolder.ChildFolders.Add(this);
            }
            else if (MainProps.EvryFolder.Exists(Obj => Obj.RelativePath == PathPastaMae) && !IsNetsFolder)
            {
                RootFolder = MainProps.EvryFolder.Find(Obj => Obj.RelativePath == PathPastaMae);
                RootFolder.ChildFolders.Add(this);
            }
            if (IsNetsFolder)
            {
                RootFolder = null;
            }
            if (!Directory.Exists(FullPath))
            {
                Directory.CreateDirectory(FullPath);
            }
            MainProps.EvryFolder.Add(this);
        }
Beispiel #2
0
        /*Funcao usada para adicionar uma net existente na base de dados*/
        private void AddNet()
        {
            NetModel novaNet = FSDatabaseFunctions.GetNetModel(NetID);

            NetID         = novaNet.NetID;
            NetFolder     = new FolderModel("\\Nets\\" + NetID);
            TotalSize     = novaNet.TotalSize;
            NumberOfFiles = novaNet.NumberOfFiles;
        }
Beispiel #3
0
        private string CreateNet()
        {
            Random generator = new Random();
            String randomID  = generator.Next(10000, 99999).ToString("D6");

            NetID = NetID + "#" + randomID;
            FSDatabaseFunctions.CreateNet(NetID);
            NetFolder = new FolderModel("\\Nets\\" + NetID);
            return(NetID);
        }
Beispiel #4
0
        //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);
        }
Beispiel #5
0
        //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);
        }