Jackett/src/Jackett.Updater/Program.cs

942 lines
40 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
2020-02-09 18:08:34 +00:00
using CommandLine;
using CommandLine.Text;
using Jackett.Common.Models.Config;
using Jackett.Common.Services;
using Jackett.Common.Services.Interfaces;
using Jackett.Common.Utils;
using NLog;
namespace Jackett.Updater
{
public class Program
{
private IProcessService processService;
private IServiceConfigService windowsService;
2019-05-13 11:03:32 +00:00
public static Logger logger;
2019-03-06 09:20:32 +00:00
private Variants.JackettVariant variant = Variants.JackettVariant.NotFound;
public static void Main(string[] args)
{
2019-05-13 11:03:32 +00:00
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper;
new Program().Run(args);
}
private void Run(string[] args)
{
var runtimeSettings = new RuntimeSettings()
{
CustomLogFileName = "updater.txt"
};
LogManager.Configuration = LoggingSetup.GetLoggingConfiguration(runtimeSettings);
logger = LogManager.GetCurrentClassLogger();
logger.Info("Jackett Updater v" + GetCurrentVersion());
logger.Info("Options \"" + string.Join("\" \"", args) + "\"");
var variants = new Variants();
2019-03-03 04:44:18 +00:00
variant = variants.GetVariant();
logger.Info("Jackett variant: " + variant.ToString());
var isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
if (isWindows)
{
//The updater starts before Jackett closes
logger.Info("Pausing for 3 seconds to give Jackett & tray time to shutdown");
System.Threading.Thread.Sleep(3000);
}
2019-03-06 09:20:32 +00:00
processService = new ProcessService(logger);
windowsService = new WindowsServiceConfigService(processService, logger);
var commandLineParser = new Parser(settings => settings.CaseSensitive = false);
try
{
var optionsResult = commandLineParser.ParseArguments<UpdaterConsoleOptions>(args);
optionsResult.WithParsed(options =>
{
ProcessUpdate(options);
}
);
optionsResult.WithNotParsed(errors =>
{
logger.Error(HelpText.AutoBuild(optionsResult));
logger.Error("Failed to process update arguments!");
2019-03-06 09:20:32 +00:00
logger.Error(errors.ToString());
Console.ReadKey();
});
}
catch (Exception e)
{
logger.Error($"Exception applying update!\n{e}");
}
}
private string GetCurrentVersion()
{
var assembly = Assembly.GetExecutingAssembly();
var fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
return fvi.FileVersion;
}
private void KillPids(int[] pids)
{
foreach (var pid in pids)
{
try
{
var proc = Process.GetProcessById(pid);
logger.Info("Killing process " + proc.Id);
2018-09-03 14:35:56 +00:00
// try to kill gracefully (on unix) first, see #3692
var exited = false;
if (Environment.OSVersion.Platform == PlatformID.Unix)
{
try
{
2019-03-06 09:20:32 +00:00
var startInfo = new ProcessStartInfo
{
Arguments = "-15 " + pid,
FileName = "kill"
};
2018-09-03 14:35:56 +00:00
Process.Start(startInfo);
2018-09-03 15:23:18 +00:00
System.Threading.Thread.Sleep(1000); // just sleep, WaitForExit() doesn't seem to work on mono/linux (returns immediantly), https://bugzilla.xamarin.com/show_bug.cgi?id=51742
2018-09-03 15:10:43 +00:00
exited = proc.WaitForExit(2000);
2018-09-03 14:35:56 +00:00
}
catch (Exception e)
{
logger.Error($"Error while sending SIGTERM to {pid}\n{e}");
2018-09-03 14:35:56 +00:00
}
if (!exited)
logger.Info($"Process {pid} didn't exit within 2 seconds after a SIGTERM");
2018-09-03 14:35:56 +00:00
}
if (!exited)
proc.Kill(); // send SIGKILL
exited = proc.WaitForExit(5000);
if (!exited)
logger.Info($"Process {pid} didn't exit within 5 seconds after a SIGKILL");
}
catch (ArgumentException)
{
logger.Info($"Process {pid} is already dead");
}
catch (Exception e)
{
logger.Error($"Error killing process {pid}\n{e}");
}
}
}
private void ProcessUpdate(UpdaterConsoleOptions options)
{
var updateLocation = GetUpdateLocation();
if (!(updateLocation.EndsWith("\\") || updateLocation.EndsWith("/")))
updateLocation += Path.DirectorySeparatorChar;
var pids = new int[] { };
if (options.KillPids != null)
{
var pidsStr = options.KillPids.Split(',').Where(pid => !string.IsNullOrWhiteSpace(pid)).ToArray();
pids = Array.ConvertAll(pidsStr, pid => int.Parse(pid));
}
var isWindows = Environment.OSVersion.Platform == PlatformID.Win32NT;
var trayRunning = false;
var trayProcesses = Process.GetProcessesByName("JackettTray");
if (isWindows)
{
2019-03-06 09:20:32 +00:00
if (trayProcesses.Length > 0)
foreach (var proc in trayProcesses)
try
{
logger.Info($"Killing tray process {proc.Id}");
proc.Kill();
trayRunning = true;
}
catch (Exception e)
{
logger.Error(e);
}
// on unix we don't have to wait (we can overwrite files which are in use)
// On unix we kill the PIDs after the update so e.g. systemd can automatically restart the process
KillPids(pids);
}
var variants = new Variants();
if (variants.IsNonWindowsDotNetCoreVariant(variant))
{
// On Linux you can't modify an executable while it is executing
// https://github.com/Jackett/Jackett/issues/5022
// https://stackoverflow.com/questions/16764946/what-generates-the-text-file-busy-message-in-unix#comment32135232_16764967
// Delete the ./jackett executable
2019-05-04 10:47:27 +00:00
// pdb files are also problematic https://github.com/Jackett/Jackett/issues/5167#issuecomment-489301150
var jackettExecutable = options.Path.TrimEnd('/') + "/jackett";
var pdbFiles = Directory.EnumerateFiles(options.Path, "*.pdb", SearchOption.AllDirectories).ToList();
var removeList = pdbFiles;
2019-05-04 10:47:27 +00:00
removeList.Add(jackettExecutable);
foreach (var fileForDelete in removeList)
{
2019-05-04 10:47:27 +00:00
try
{
2019-05-04 10:47:27 +00:00
logger.Info("Attempting to remove: " + fileForDelete);
if (File.Exists(fileForDelete))
{
File.Delete(fileForDelete);
logger.Info("Deleted " + fileForDelete);
}
else
logger.Info("File for deleting not found: " + fileForDelete);
}
2019-05-04 10:47:27 +00:00
catch (Exception e)
{
2019-05-04 10:47:27 +00:00
logger.Error(e);
}
}
}
logger.Info("Finding files in: " + updateLocation);
2019-05-04 10:47:27 +00:00
var files = Directory.GetFiles(updateLocation, "*.*", SearchOption.AllDirectories).OrderBy(x => x).ToList();
logger.Info($"{files.Count} update files found");
2019-05-11 03:04:07 +00:00
try
{
foreach (var file in files)
{
2019-05-11 03:04:07 +00:00
var fileName = Path.GetFileName(file).ToLowerInvariant();
if (fileName.EndsWith(".zip") || fileName.EndsWith(".tar") || fileName.EndsWith(".gz"))
continue;
2019-05-04 10:47:27 +00:00
var fileCopySuccess = CopyUpdateFile(options.Path, file, updateLocation, false);
2019-05-04 10:47:27 +00:00
if (!fileCopySuccess) //Perform second attempt, this time removing the target file first
2019-05-11 03:04:07 +00:00
CopyUpdateFile(options.Path, file, updateLocation, true);
}
}
catch (Exception e)
2019-05-11 03:04:07 +00:00
{
logger.Error(e);
2019-05-11 03:04:07 +00:00
}
2019-05-04 10:47:27 +00:00
logger.Info("File copying complete");
// delete old dirs
var oldDirs = new string[] { "Content/logos" };
foreach (var oldDir in oldDirs)
{
try
{
var deleteDir = Path.Combine(options.Path, oldDir);
if (Directory.Exists(deleteDir))
{
logger.Info("Deleting directory " + deleteDir);
Directory.Delete(deleteDir, true);
}
}
catch (Exception e)
{
logger.Error(e);
}
}
// delete old files
var oldFiles = new string[] {
"appsettings.Development.json",
"Autofac.Integration.WebApi.dll",
"Content/congruent_outline.png",
"Content/crissXcross.png",
"Content/css/jquery.dataTables.css",
"Content/css/jquery.dataTables_themeroller.css",
"CsQuery.dll",
"CurlSharp.dll",
"CurlSharp.pdb",
"Definitions/32pages.yml",
"Definitions/420files.yml",
2020-09-18 02:49:50 +00:00
"Definitions/academictorrents.yml",
2020-03-08 19:14:16 +00:00
"Definitions/alein.yml",
"Definitions/alexfilm.yml",
"Definitions/anidex.yml", // migrated to C#
"Definitions/aox.yml",
"Definitions/apollo.yml", // migrated to C# gazelle base tracker
"Definitions/archetorrent.yml",
"Definitions/asiandvdclub.yml",
"Definitions/avg.yml",
"Definitions/awesomehd.yml", // migrated to C#
"Definitions/b2s-share.yml",
"Definitions/badasstorrents.yml", // to be migrated to c#
"Definitions/bithq.yml",
"Definitions/bitme.yml",
"Definitions/bittorrentam.yml",
"Definitions/blubits.yml",
"Definitions/brobits.yml",
"Definitions/bt-scene.yml",
"Definitions/btbit.yml",
2020-09-20 07:12:35 +00:00
"Definitions/bteye.yml",
2020-12-06 01:31:10 +00:00
"Definitions/btgigs.yml",
"Definitions/btkitty.yml",
"Definitions/btstornet.yml",
"Definitions/btxpress.yml",
"Definitions/cili180.yml", // renamed to liaorencili
"Definitions/cinefilhd.yml",
"Definitions/crazyscorner.yml",
"Definitions/czteam.yml",
"Definitions/cztorrent.yml",
"Definitions/darmowetorenty.yml", // migrated to C#
"Definitions/demonsite.yml",
"Definitions/digbt.yml",
"Definitions/downloadville.yml",
"Definitions/dragonworld.yml",
"Definitions/dreamteam.yml",
2020-03-10 07:07:03 +00:00
"Definitions/eggmeon.yml",
"Definitions/elitehd.yml",
"Definitions/elitetorrent-biz.yml",
"Definitions/elittracker.yml",
"Definitions/eotforum.yml",
"Definitions/estrenosdtl.yml",
2020-11-26 20:10:09 +00:00
"Definitions/ethor.yml",
"Definitions/evolutionpalace.yml",
"Definitions/exoticaz.yml", // migrated to C#
"Definitions/extratorrent-ag.yml",
"Definitions/extratorrentclone.yml",
"Definitions/feedurneed.yml",
"Definitions/filmsclub.yml",
"Definitions/freakstrackingsystem.yml",
"Definitions/freedomhd.yml",
"Definitions/gdf76.yml",
"Definitions/gfxnews.yml",
"Definitions/gods.yml",
"Definitions/gormogon.yml",
"Definitions/greeklegends.yml",
"Definitions/hachede-c.yml",
"Definitions/hd4free.yml",
"Definitions/hdbc.yml", // renamed to hdbitscom
"Definitions/hdclub.yml",
"Definitions/hdplus.yml",
"Definitions/hon3yhd-net.yml",
"Definitions/horriblesubs.yml",
"Definitions/hyperay.yml",
"Definitions/icetorrent.yml", // migrated to C# XtremeZone base tracker
"Definitions/idopeclone.yml",
"Definitions/iloveclassics.yml",
"Definitions/infinityt.yml",
2020-07-11 20:55:28 +00:00
"Definitions/inperil.yml",
"Definitions/isohunt.yml",
2020-09-12 09:37:36 +00:00
"Definitions/kapaki.yml",
"Definitions/katcrs.yml",
"Definitions/kaztorka.yml",
"Definitions/kickasstorrent.yml",
"Definitions/kikibt.yml",
"Definitions/korsar.yml",
"Definitions/lapausetorrents.yml",
"Definitions/lemencili.yml",
"Definitions/leparadisdunet.yml",
"Definitions/leporno.yml",
"Definitions/liaorencili.yml", // renamed to cilipro
"Definitions/magnetdl.yml",
"Definitions/maniatorrent.yml",
"Definitions/manicomioshare.yml",
"Definitions/megabliz.yml",
"Definitions/metal-iplay-ro.yml", // renamed to romanianmetaltorrents
"Definitions/mkvcage.yml",
2020-09-19 05:54:35 +00:00
"Definitions/moecat.yml",
"Definitions/music-master.yml",
2017-06-06 17:06:30 +00:00
"Definitions/nachtwerk.yml",
"Definitions/nexttorrent.yml",
"Definitions/nnm-club.yml", // renamed to noname-club
"Definitions/nordichd.yml",
"Definitions/nostalgic.yml", // renamed to vhstapes
"Definitions/nyaa.yml",
"Definitions/nyoo.yml",
"Definitions/passionetorrent.yml",
"Definitions/polishtracker.yml",
2020-09-17 05:13:45 +00:00
"Definitions/pt99.yml",
"Definitions/qctorrent.yml",
"Definitions/qxr.yml",
"Definitions/rapidetracker.yml",
"Definitions/rarbg.yml", // migrated to C#
"Definitions/redtopia.yml",
"Definitions/rgu.yml",
"Definitions/rns.yml", // site merged with audiobooktorrents
"Definitions/rockethd.yml",
"Definitions/rockhardlossless.yml",
2020-06-15 19:49:47 +00:00
"Definitions/rodvd.yml",
"Definitions/scenefz.yml", // migrated to C# XtremeZone base tracker
"Definitions/scenehd.yml", // migrated to C# (use JSON API)
"Definitions/scenereactor.yml",
"Definitions/scenexpress.yml",
2018-01-03 18:51:00 +00:00
"Definitions/secretcinema.yml", // migrated to C# gazelle base tracker
"Definitions/seedpeer.yml",
2020-04-27 21:51:07 +00:00
"Definitions/sharespacedb.yml",
"Definitions/sharingue.yml",
"Definitions/skytorrents.yml",
"Definitions/solidtorrents.yml", // migrated to C#
"Definitions/soundpark.yml", // to be migrated to C#
2020-11-30 17:39:38 +00:00
"Definitions/spacetorrent.yml",
"Definitions/speed-share.yml",
"Definitions/t411.yml",
"Definitions/t411v2.yml",
"Definitions/tazmaniaden.yml",
"Definitions/tbplus.yml",
2018-05-13 12:58:44 +00:00
"Definitions/tehconnection.yml",
2020-03-22 21:17:17 +00:00
"Definitions/tfile.yml",
"Definitions/the-madhouse.yml",
"Definitions/themoviecave.yml",
"Definitions/thepiratebay.yml", // migrated to c#
"Definitions/theresurrection.yml",
"Definitions/thetorrents.yml",
2020-10-28 00:00:37 +00:00
"Definitions/theunknown.yml", // became 3evils #9678
"Definitions/tigers-dl.yml",
"Definitions/tntvillage.yml",
"Definitions/topnow.yml",
"Definitions/torrentcouch.yml",
2020-07-21 22:42:11 +00:00
"Definitions/torrenthane.yml",
"Definitions/torrentkim.yml",
"Definitions/torrentquest.yml",
"Definitions/torrentrex.yml",
"Definitions/torrentseed.yml", // renamed to latinop2p #9065
"Definitions/torrentseeds.yml", // migrated to c#
2018-12-28 15:16:18 +00:00
"Definitions/torrentsmd.yml",
"Definitions/torrentvault.yml",
"Definitions/torrentwal.yml",
"Definitions/torrentwtf.yml",
"Definitions/torrof.yml",
"Definitions/torviet.yml",
"Definitions/tspate.yml",
2020-07-24 20:10:50 +00:00
"Definitions/turknova.yml",
"Definitions/u-torrents.yml",
"Definitions/ultimategamerclub.yml",
"Definitions/ultrahdclub.yml",
"Definitions/uniotaku.yml", // to be migrated to c#
"Definitions/utorrents.yml", // same as SzeneFZ now
"Definitions/vanila.yml",
"Definitions/vhstapes.yml",
"Definitions/waffles.yml",
"Definitions/world-of-tomorrow.yml", // #9213
"Definitions/worldofp2p.yml",
"Definitions/worldwidetorrents.yml",
2020-11-19 18:11:14 +00:00
"Definitions/xfsub.yml",
"Definitions/xktorrent.yml",
"Definitions/xtremefile.yml",
"Definitions/xtremezone.yml", // migrated to C# XtremeZone base tracker
"Definitions/yourexotic.yml", // renamed to exoticaz
"Indexers/32pages.json",
"Indexers/32pages.json.bak",
"Indexers/420files.json",
"Indexers/420files.json.bak",
"Indexers/academictorrents.json",
"Indexers/academictorrents.json.bak",
"Indexers/alein.json",
"Indexers/alein.json.bak",
"Indexers/alexfilm.json",
"Indexers/alexfilm.json.bak",
"Indexers/aox.json",
"Indexers/aox.json.bak",
"Indexers/apollo.json", // renamed to orpheus
"Indexers/apollo.json.bak", // renamed to orpheus
"Indexers/archetorrent.json",
"Indexers/archetorrent.json.bak",
"Indexers/asiandvdclub.json",
"Indexers/asiandvdclub.json.bak",
"Indexers/avg.json",
"Indexers/avg.json.bak",
"Indexers/b2s-share.json",
"Indexers/b2s-share.json.bak",
"Indexers/badasstorrents.json", // to be migrated to c#
"Indexers/badasstorrents.json.bak", // to be migrated to c#
"Indexers/bithq.json",
"Indexers/bithq.json.bak",
"Indexers/bitme.json",
"Indexers/bitme.json.bak",
"Indexers/bittorrentam.json",
"Indexers/bittorrentam.json.bak",
"Indexers/blubits.json",
"Indexers/blubits.json.bak",
"Indexers/brobits.json",
"Indexers/brobits.json.bak",
"Indexers/bt-scene.json",
"Indexers/bt-scene.json.bak",
"Indexers/btbit.json",
"Indexers/btbit.json.bak",
"Indexers/bteye.json",
"Indexers/bteye.json.bak",
"Indexers/btgigs.json",
"Indexers/btgigs.json.bak",
"Indexers/btkitty.json",
"Indexers/btkitty.json.bak",
"Indexers/btstornet.json",
"Indexers/btstornet.json.bak",
"Indexers/btxpress.json",
"Indexers/btxpress.json.bak",
"Indexers/cinefilhd.json",
"Indexers/cinefilhd.json.bak",
"Indexers/crazyscorner.json",
"Indexers/crazyscorner.json.bak",
"Indexers/czteam.json",
"Indexers/czteam.json.bak",
"Indexers/cztorrent.json",
"Indexers/cztorrent.json.bak",
"Indexers/demonsite.json",
"Indexers/demonsite.json.bak",
"Indexers/digbt.json",
"Indexers/digbt.json.bak",
"Indexers/downloadville.json",
"Indexers/downloadville.json.bak",
"Indexers/dragonworld.json",
"Indexers/dragonworld.json.bak",
"Indexers/dreamteam.json",
"Indexers/dreamteam.json.bak",
"Indexers/eggmeon.json",
"Indexers/eggmeon.json.bak",
"Indexers/elitehd.json",
"Indexers/elitehd.json.bak",
"Indexers/elitetorrent-biz.json",
"Indexers/elitetorrent-biz.json.bak",
"Indexers/elittracker.json",
"Indexers/elittracker.json.bak",
"Indexers/eotforum.json",
"Indexers/eotforum.json.bak",
"Indexers/estrenosdtl.json",
"Indexers/estrenosdtl.json.bak",
"Indexers/ethor.json",
"Indexers/ethor.json.bak",
"Indexers/evolutionpalace.json",
"Indexers/evolutionpalace.json.bak",
"Indexers/extratorrent-ag.json",
"Indexers/extratorrent-ag.json.bak",
"Indexers/extratorrentclone.json",
"Indexers/extratorrentclone.json.bak",
"Indexers/feedurneed.json",
"Indexers/feedurneed.json.bak",
"Indexers/filmsclub.json",
"Indexers/filmsclub.json.bak",
"Indexers/freakstrackingsystem.json",
"Indexers/freakstrackingsystem.json.bak",
"Indexers/freedomhd.json",
"Indexers/freedomhd.json.bak",
"Indexers/gdf76.json",
"Indexers/gdf76.json.bak",
"Indexers/gfxnews.json",
"Indexers/gfxnews.json.bak",
"Indexers/gods.json",
"Indexers/gods.json.bak",
"Indexers/gormogon.json",
"Indexers/gormogon.json.bak",
"Indexers/greeklegends.json",
"Indexers/greeklegends.json.bak",
"Indexers/hachede-c.json",
"Indexers/hachede-c.json.bak",
"Indexers/hd4free.json",
"Indexers/hd4free.json.bak",
"Indexers/hdbc.json", // renamed to hdbitscom
"Indexers/hdbc.json.bak", // renamed to hdbitscom
"Indexers/hdclub.json",
"Indexers/hdclub.json.bak",
"Indexers/hdplus.json",
"Indexers/hdplus.json.bak",
"Indexers/hon3yhd-net.json",
"Indexers/hon3yhd-net.json.bak",
"Indexers/horriblesubs.json",
"Indexers/horriblesubs.json.bak",
"Indexers/hyperay.json",
"Indexers/hyperay.json.bak",
"Indexers/idopeclone.json",
"Indexers/idopeclone.json.bak",
"Indexers/iloveclassics.json",
"Indexers/iloveclassics.json.bak",
"Indexers/infinityt.json",
"Indexers/infinityt.json.bak",
"Indexers/inperil.json",
"Indexers/inperil.json.bak",
"Indexers/isohunt.json",
"Indexers/isohunt.json.bak",
"Indexers/kapaki.json",
"Indexers/kapaki.json.bak",
"Indexers/katcrs.json",
"Indexers/katcrs.json.bak",
"Indexers/kaztorka.json",
"Indexers/kaztorka.json.bak",
"Indexers/kickasstorrent.json",
"Indexers/kickasstorrent.json.bak",
"Indexers/kikibt.json",
"Indexers/kikibt.json.bak",
"Indexers/korsar.json",
"Indexers/korsar.json.bak",
"Indexers/lapausetorrents.json",
"Indexers/lapausetorrents.json.bak",
"Indexers/lemencili.json",
"Indexers/lemencili.json.bak",
"Indexers/leparadisdunet.json",
"Indexers/leparadisdunet.json.bak",
"Indexers/leporno.json",
"Indexers/leporno.json.bak",
"Indexers/magnetdl.json",
"Indexers/magnetdl.json.bak",
"Indexers/maniatorrent.json",
"Indexers/maniatorrent.json.bak",
"Indexers/manicomioshare.json",
"Indexers/manicomioshare.json.bak",
"Indexers/megabliz.json",
"Indexers/megabliz.json.bak",
"Indexers/mkvcage.json",
"Indexers/mkvcage.json.bak",
"Indexers/moecat.json",
"Indexers/moecat.json.bak",
"Indexers/music-master.json",
"Indexers/music-master.json.bak",
"Indexers/nachtwerk.json",
"Indexers/nachtwerk.json.bak",
"Indexers/nexttorrent.json",
"Indexers/nexttorrent.json.bak",
"Indexers/nordichd.json",
"Indexers/nordichd.json.bak",
"Indexers/nostalgic.json", // renamed to vhstapes
"Indexers/nostalgic.json.bak", // renamed to vhstapes
"Indexers/nyaa.json",
"Indexers/nyaa.json.bak",
"Indexers/nyoo.json",
"Indexers/nyoo.json.bak",
"Indexers/passionetorrent.json",
"Indexers/passionetorrent.json.bak",
"Indexers/polishtracker.json",
"Indexers/polishtracker.json.bak",
"Indexers/pt99.json",
"Indexers/pt99.json.bak",
"Indexers/qctorrent.json",
"Indexers/qctorrent.json.bak",
"Indexers/qxr.json",
"Indexers/qxr.json.bak",
"Indexers/rapidetracker.json",
"Indexers/rapidetracker.json.bak",
"Indexers/redtopia.json",
"Indexers/redtopia.json.bak",
"Indexers/rgu.json",
"Indexers/rgu.json.bak",
"Indexers/rns.json", // site merged with audiobooktorrents
"Indexers/rns.json.bak", // site merged with audiobooktorrents
"Indexers/rockethd.json",
"Indexers/rockethd.json.bak",
"Indexers/rockhardlossless.json",
"Indexers/rockhardlossless.json.bak",
"Indexers/rodvd.json",
"Indexers/rodvd.json.bak",
"Indexers/scenereactor.json",
"Indexers/scenereactor.json.bak",
"Indexers/scenexpress.json",
"Indexers/scenexpress.json.bak",
"Indexers/seedpeer.json",
"Indexers/seedpeer.json.bak",
"Indexers/sharespacedb.json",
"Indexers/sharespacedb.json.bak",
"Indexers/sharingue.json",
"Indexers/sharingue.json.bak",
"Indexers/skytorrents.json",
"Indexers/skytorrents.json.bak",
"Indexers/soundpark.json", // to be migrated to C#
"Indexers/soundpark.json.bak", // to be migrated to C#
"Indexers/spacetorrent.json",
"Indexers/spacetorrent.json.bak",
"Indexers/speed-share.json",
"Indexers/speed-share.json.bak",
"Indexers/t411.json",
"Indexers/t411.json.bak",
"Indexers/t411v2.json",
"Indexers/t411v2.json.bak",
"Indexers/tazmaniaden.json",
"Indexers/tazmaniaden.json.bak",
"Indexers/tbplus.json",
"Indexers/tbplus.json.bak",
"Indexers/tehconnection.json",
"Indexers/tehconnection.json.bak",
"Indexers/tfile.json",
"Indexers/tfile.json.bak",
"Indexers/the-madhouse.json",
"Indexers/the-madhouse.json.bak",
"Indexers/themoviecave.json",
"Indexers/themoviecave.json.bak",
"Indexers/theresurrection.json",
"Indexers/theresurrection.json.bak",
"Indexers/thetorrents.json",
"Indexers/thetorrents.json.bak",
"Indexers/theunknown.json", // became 3evils #9678
"Indexers/theunknown.json.bak", // became 3evils #9678
"Indexers/tigers-dl.json",
"Indexers/tigers-dl.json.bak",
"Indexers/tntvillage.json",
"Indexers/tntvillage.json.bak",
"Indexers/topnow.json",
"Indexers/topnow.json.bak",
"Indexers/torrentcouch.json",
"Indexers/torrentcouch.json.bak",
"Indexers/torrenthane.json",
"Indexers/torrenthane.json.bak",
"Indexers/torrentkim.json",
"Indexers/torrentkim.json.bak",
"Indexers/torrentquest.json",
"Indexers/torrentquest.json.bak",
"Indexers/torrentrex.json",
"Indexers/torrentrex.json.bak",
"Indexers/torrentsmd.json",
"Indexers/torrentsmd.json.bak",
"Indexers/torrentvault.json",
"Indexers/torrentvault.json.bak",
"Indexers/torrentwal.json",
"Indexers/torrentwal.json.bak",
"Indexers/torrentwtf.json",
"Indexers/torrentwtf.json.bak",
"Indexers/torrof.json",
"Indexers/torrof.json.bak",
"Indexers/torviet.json",
"Indexers/torviet.json.bak",
"Indexers/tspate.json",
"Indexers/tspate.json.bak",
"Indexers/turknova.json",
"Indexers/turknova.json.bak",
"Indexers/u-torrents.json",
"Indexers/u-torrents.json.bak",
"Indexers/ultimategamerclub.json",
"Indexers/ultimategamerclub.json.bak",
"Indexers/ultrahdclub.json",
"Indexers/ultrahdclub.json.bak",
"Indexers/uniotaku.json", // to be migrated to c#
"Indexers/uniotaku.json.bak", // to be migrated to c#
"Indexers/utorrents.json", // same as SzeneFZ now
"Indexers/utorrents.json.bak", // same as SzeneFZ now
"Indexers/vanila.json",
"Indexers/vanila.json.bak",
"Indexers/vhstapes.json",
"Indexers/vhstapes.json.bak",
"Indexers/waffles.json",
"Indexers/waffles.json.bak",
"Indexers/world-of-tomorrow.json", // #9213
"Indexers/world-of-tomorrow.json.bak", // #9213
"Indexers/worldofp2p.json",
"Indexers/worldofp2p.json.bak",
"Indexers/worldwidetorrents.json",
"Indexers/worldwidetorrents.json.bak",
"Indexers/xfsub.json",
"Indexers/xfsub.json.bak",
"Indexers/xktorrent.json",
"Indexers/xktorrent.json.bak",
"Indexers/xtremefile.json",
"Indexers/xtremefile.json.bak",
2018-08-18 08:22:28 +00:00
"Microsoft.Owin.dll",
"Microsoft.Owin.FileSystems.dll",
"Microsoft.Owin.Host.HttpListener.dll",
"Microsoft.Owin.Hosting.dll",
"Microsoft.Owin.StaticFiles.dll",
"Owin.dll",
"System.ServiceModel.dll",
2018-08-18 08:22:28 +00:00
"System.Web.Http.dll",
"System.Web.Http.Owin.dll",
"System.Web.Http.Tracing.dll",
"System.Xml.XPath.XmlDocument.dll"
};
foreach (var oldFile in oldFiles)
{
try
{
var deleteFile = Path.Combine(options.Path, oldFile);
if (File.Exists(deleteFile))
{
logger.Info("Deleting file " + deleteFile);
File.Delete(deleteFile);
}
}
catch (Exception e)
{
logger.Error(e);
}
}
// remove .lock file to detect errors in the update process
var lockFilePath = Path.Combine(options.Path, ".lock");
if (File.Exists(lockFilePath))
File.Delete(lockFilePath);
// kill pids after the update on UNIX
if (!isWindows)
KillPids(pids);
2019-03-06 09:20:32 +00:00
if (!options.NoRestart)
{
if (isWindows && (trayRunning || options.StartTray) && !string.Equals(options.Type, "WindowsService", StringComparison.OrdinalIgnoreCase))
{
var startInfo = new ProcessStartInfo()
{
Arguments = $"--UpdatedVersion \" {EnvironmentUtil.JackettVersion}\"",
FileName = Path.Combine(options.Path, "JackettTray.exe"),
UseShellExecute = true
};
logger.Info("Starting Tray: " + startInfo.FileName + " " + startInfo.Arguments);
Process.Start(startInfo);
if (!windowsService.ServiceExists())
{
//User was running the tray icon, but not using the Windows service, starting Tray icon will start JackettConsole as well
return;
}
}
if (string.Equals(options.Type, "WindowsService", StringComparison.OrdinalIgnoreCase))
{
logger.Info("Starting Windows service");
try
{
windowsService.Start();
}
catch
{
logger.Info("Failed to start service. Attempting to start console.");
try
{
var consolePath = Path.Combine(options.Path, "JackettConsole.exe");
processService.StartProcessAndLog(consolePath, "--Start", true);
}
catch
{
logger.Error("Failed to start the service or console.");
}
}
}
else
{
var startInfo = new ProcessStartInfo()
{
Arguments = options.Args,
2019-03-03 04:44:18 +00:00
FileName = GetJackettConsolePath(options.Path),
UseShellExecute = true
};
if (isWindows)
{
//User didn't initiate the update from Windows service and wasn't running Jackett via the tray, must have started from the console
startInfo.Arguments = $"/K {startInfo.FileName} {startInfo.Arguments}";
startInfo.FileName = "cmd.exe";
startInfo.CreateNoWindow = false;
startInfo.WindowStyle = ProcessWindowStyle.Normal;
}
2019-03-06 09:20:32 +00:00
2019-03-03 04:44:18 +00:00
if (variant == Variants.JackettVariant.Mono)
{
startInfo.Arguments = startInfo.FileName + " " + startInfo.Arguments;
startInfo.FileName = "mono";
}
if (variant == Variants.JackettVariant.CoreMacOs || variant == Variants.JackettVariant.CoreLinuxAmdx64
|| variant == Variants.JackettVariant.CoreLinuxArm32 || variant == Variants.JackettVariant.CoreLinuxArm64)
{
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = true;
}
logger.Info("Starting Jackett: " + startInfo.FileName + " " + startInfo.Arguments);
Process.Start(startInfo);
}
}
}
2019-05-04 10:47:27 +00:00
private bool CopyUpdateFile(string jackettDestinationDirectory, string fullSourceFilePath, string updateSourceDirectory, bool previousAttemptFailed)
{
var success = false;
2019-05-04 10:47:27 +00:00
string fileName;
string fullDestinationFilePath;
string fileDestinationDirectory;
try
{
fileName = Path.GetFileName(fullSourceFilePath);
fullDestinationFilePath = Path.Combine(jackettDestinationDirectory, fullSourceFilePath.Substring(updateSourceDirectory.Length));
fileDestinationDirectory = Path.GetDirectoryName(fullDestinationFilePath);
}
catch (Exception e)
{
logger.Error(e);
return false;
}
logger.Info($"Attempting to copy {fileName} from source: {fullSourceFilePath} to destination: {fullDestinationFilePath}");
if (previousAttemptFailed)
{
logger.Info("The first attempt copying file: " + fileName + "failed. Retrying and will delete old file first");
try
{
if (File.Exists(fullDestinationFilePath))
{
logger.Info(fullDestinationFilePath + " was found");
System.Threading.Thread.Sleep(1000);
File.Delete(fullDestinationFilePath);
logger.Info("Deleted " + fullDestinationFilePath);
System.Threading.Thread.Sleep(1000);
}
else
{
logger.Info(fullDestinationFilePath + " was NOT found");
}
}
catch (Exception e)
{
logger.Error(e);
}
}
try
2020-02-09 02:35:16 +00:00
{
2019-05-04 10:47:27 +00:00
if (!Directory.Exists(fileDestinationDirectory))
{
logger.Info("Creating directory " + fileDestinationDirectory);
Directory.CreateDirectory(fileDestinationDirectory);
}
File.Copy(fullSourceFilePath, fullDestinationFilePath, true);
logger.Info("Copied " + fileName);
success = true;
}
catch (Exception e)
{
logger.Error(e);
}
return success;
}
private string GetUpdateLocation()
{
2020-02-09 02:35:16 +00:00
// Use EscapedCodeBase to avoid Uri reserved characters from causing bugs
// https://stackoverflow.com/questions/896572
var location = new Uri(Assembly.GetEntryAssembly().GetName().EscapedCodeBase);
// Use LocalPath instead of AbsolutePath to avoid needing to unescape Uri format.
return new FileInfo(location.LocalPath).DirectoryName;
}
2019-03-03 04:44:18 +00:00
private string GetJackettConsolePath(string directoryPath)
{
var variants = new Variants();
return Path.Combine(directoryPath, variants.IsNonWindowsDotNetCoreVariant(variant) ? "jackett" : "JackettConsole.exe");
2019-03-03 04:44:18 +00:00
}
2019-05-13 11:03:32 +00:00
private static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine(e.ExceptionObject.ToString());
logger.Error(e.ExceptionObject.ToString());
Environment.Exit(1);
}
}
}