Beispiel #1
0
        private void PostRelease(WatchFolderSettings folderConfiguration, UploadEntry nextUpload, FileSystemInfo toUpload, Boolean isDirectory)
        {
            nextUpload.UploadAttempts++;
            if (folderConfiguration.CleanName)
            {
                nextUpload.CleanedName =
                    folderConfiguration.PreTag + CleanName(toUpload.NameWithoutExtension()) + folderConfiguration.PostTag;
            }
            else
            {
                nextUpload.CleanedName =
                    folderConfiguration.PreTag + toUpload.NameWithoutExtension() + folderConfiguration.PostTag;
            }
            if (folderConfiguration.UseObfuscation)
            {
                nextUpload.ObscuredName      = Guid.NewGuid().ToString("N");
                nextUpload.NotifiedIndexerAt = null;
            }
            DBHandler.Instance.UpdateUploadEntry(nextUpload);   //This ensures we already notify the indexer of our obfuscated post before we start posting.

            UsenetPoster   poster = new UsenetPoster(configuration, folderConfiguration);
            FileSystemInfo toPost = null;

            try
            {
                if (isDirectory)
                {
                    toPost = PrepareDirectoryForPosting(folderConfiguration, nextUpload, (DirectoryInfo)toUpload);
                }
                else
                {
                    toPost = PrepareFileForPosting(folderConfiguration, nextUpload, (FileInfo)toUpload);
                }

                String password = folderConfiguration.RarPassword;
                if (folderConfiguration.ApplyRandomPassword)
                {
                    password = Guid.NewGuid().ToString("N");
                }

                var nzbFile = poster.PostToUsenet(toPost, password, false);
                if (configuration.NzbOutputFolder != null)
                {
                    nzbFile.Save(Path.Combine(configuration.NzbOutputFolder.FullName, nextUpload.CleanedName + ".nzb"));
                }

                nextUpload.RarPassword = password;
                nextUpload.UploadedAt  = DateTime.UtcNow;
                DBHandler.Instance.UpdateUploadEntry(nextUpload);
                log.InfoFormat("[{0}] was uploaded as obfuscated release [{1}] to usenet."
                               , nextUpload.CleanedName, nextUpload.ObscuredName);
            }
            finally
            {
                if (toPost != null)
                {
                    toPost.Refresh();
                    if (toPost.Exists)
                    {
                        FileAttributes attributes = File.GetAttributes(toPost.FullName);
                        if (attributes.HasFlag(FileAttributes.Directory))
                        {
                            Directory.Delete(toPost.FullName, true);
                        }
                        else
                        {
                            File.Delete(toPost.FullName);
                        }
                    }
                }
            }
        }
Beispiel #2
0
        private void PostRelease(WatchFolderSettings folderConfiguration, UploadEntry nextUpload, FileSystemInfo toUpload, Boolean isDirectory)
        {
            nextUpload.UploadAttempts++;
            if (folderConfiguration.CleanName)
            {
                nextUpload.CleanedName = ApplyTags(CleanName(folderConfiguration, StripNonAscii(toUpload.NameWithoutExtension())), folderConfiguration);
            }
            else
            {
                nextUpload.CleanedName = ApplyTags(StripNonAscii(toUpload.NameWithoutExtension()), folderConfiguration);
            }
            if (folderConfiguration.UseObfuscation)
            {
                nextUpload.ObscuredName      = Guid.NewGuid().ToString("N");
                nextUpload.NotifiedIndexerAt = null;
            }
            DBHandler.Instance.UpdateUploadEntry(nextUpload);

            UsenetPoster   poster = new UsenetPoster(configuration, folderConfiguration);
            FileSystemInfo toPost = null;

            try
            {
                if (isDirectory)
                {
                    toPost = PrepareDirectoryForPosting(folderConfiguration, nextUpload, (DirectoryInfo)toUpload);
                }
                else
                {
                    toPost = PrepareFileForPosting(folderConfiguration, nextUpload, (FileInfo)toUpload);
                }

                String password = folderConfiguration.RarPassword;
                if (folderConfiguration.ApplyRandomPassword)
                {
                    password = Guid.NewGuid().ToString("N");
                }

                var nzbFile = poster.PostToUsenet(toPost, password, false);

                nextUpload.NzbContents = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + Environment.NewLine + nzbFile.ToString();

                if (configuration.NzbOutputFolder != null)
                {
                    FileInfo file = new FileInfo(Path.Combine(configuration.NzbOutputFolder.FullName, nextUpload.CleanedName + ".nzb"));
                    File.WriteAllText(file.FullName, nextUpload.NzbContents);
                }

                nextUpload.RarPassword = password;
                nextUpload.UploadedAt  = DateTime.UtcNow;
                nextUpload.Move(configuration, Location.Backup);
                DBHandler.Instance.UpdateUploadEntry(nextUpload);
                log.InfoFormat("[{0}] was uploaded as obfuscated release [{1}] to usenet."
                               , nextUpload.CleanedName, nextUpload.ObscuredName);
            }
            finally
            {
                if (toPost != null)
                {
                    toPost.Refresh();
                    if (toPost.Exists)
                    {
                        FileAttributes attributes = File.GetAttributes(toPost.FullName);
                        if (attributes.HasFlag(FileAttributes.Directory))
                        {
                            Directory.Delete(toPost.FullName, true);
                        }
                        else
                        {
                            File.Delete(toPost.FullName);
                        }
                    }
                }
            }
        }