2017-04-15 08:45:10 +00:00
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 ;
2017-04-15 08:45:10 +00:00
namespace Jackett.Updater
{
2018-06-24 01:31:08 +00:00
public class Program
2017-04-15 08:45:10 +00:00
{
2018-06-24 01:31:08 +00:00
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 ;
2018-06-24 01:31:08 +00:00
public static void Main ( string [ ] args )
2017-04-15 08:45:10 +00:00
{
2019-05-13 11:03:32 +00:00
AppDomain . CurrentDomain . UnhandledException + = UnhandledExceptionTrapper ;
2017-04-15 08:45:10 +00:00
new Program ( ) . Run ( args ) ;
}
private void Run ( string [ ] args )
{
2020-02-10 22:16:19 +00:00
var runtimeSettings = new RuntimeSettings ( )
2017-11-13 08:38:38 +00:00
{
CustomLogFileName = "updater.txt"
2018-06-24 01:31:08 +00:00
} ;
LogManager . Configuration = LoggingSetup . GetLoggingConfiguration ( runtimeSettings ) ;
logger = LogManager . GetCurrentClassLogger ( ) ;
logger . Info ( "Jackett Updater v" + GetCurrentVersion ( ) ) ;
logger . Info ( "Options \"" + string . Join ( "\" \"" , args ) + "\"" ) ;
2020-02-10 22:16:19 +00:00
var variants = new Variants ( ) ;
2019-03-03 04:44:18 +00:00
variant = variants . GetVariant ( ) ;
logger . Info ( "Jackett variant: " + variant . ToString ( ) ) ;
2020-02-10 22:16:19 +00:00
var isWindows = Environment . OSVersion . Platform = = PlatformID . Win32NT ;
2018-06-26 09:44:12 +00:00
if ( isWindows )
{
//The updater starts before Jackett closes
logger . Info ( "Pausing for 3 seconds to give Jackett & tray time to shutdown" ) ;
2018-06-27 12:02:51 +00:00
System . Threading . Thread . Sleep ( 3000 ) ;
2018-06-26 09:44:12 +00:00
}
2019-03-06 09:20:32 +00:00
2018-06-24 01:31:08 +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 ) ;
2017-11-13 08:38:38 +00:00
optionsResult . WithParsed ( options = >
2017-04-15 08:45:10 +00:00
{
ProcessUpdate ( options ) ;
}
2017-11-13 08:38:38 +00:00
) ;
optionsResult . WithNotParsed ( errors = >
2017-04-15 08:45:10 +00:00
{
2018-06-24 01:31:08 +00:00
logger . Error ( HelpText . AutoBuild ( optionsResult ) ) ;
logger . Error ( "Failed to process update arguments!" ) ;
2019-03-06 09:20:32 +00:00
logger . Error ( errors . ToString ( ) ) ;
2017-04-15 08:45:10 +00:00
Console . ReadKey ( ) ;
2017-11-13 08:38:38 +00:00
} ) ;
2017-04-15 08:45:10 +00:00
}
catch ( Exception e )
{
2020-09-24 20:02:45 +00:00
logger . Error ( $"Exception applying update!\n{e}" ) ;
2017-04-15 08:45:10 +00:00
}
}
private string GetCurrentVersion ( )
{
2017-11-13 08:38:38 +00:00
var assembly = Assembly . GetExecutingAssembly ( ) ;
2017-04-15 08:45:10 +00:00
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 ) ;
2018-06-24 01:31:08 +00:00
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 )
{
2020-09-24 20:02:45 +00:00
logger . Error ( $"Error while sending SIGTERM to {pid}\n{e}" ) ;
2018-09-03 14:35:56 +00:00
}
if ( ! exited )
2020-09-24 20:02:45 +00:00
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 ) ;
2017-04-15 08:45:10 +00:00
if ( ! exited )
2020-09-24 20:02:45 +00:00
logger . Info ( $"Process {pid} didn't exit within 5 seconds after a SIGKILL" ) ;
2017-04-15 08:45:10 +00:00
}
2017-06-28 05:31:38 +00:00
catch ( ArgumentException )
2017-04-15 08:45:10 +00:00
{
2020-09-24 20:02:45 +00:00
logger . Info ( $"Process {pid} is already dead" ) ;
2017-04-15 08:45:10 +00:00
}
catch ( Exception e )
{
2020-09-24 20:02:45 +00:00
logger . Error ( $"Error killing process {pid}\n{e}" ) ;
2017-04-15 08:45:10 +00:00
}
}
}
private void ProcessUpdate ( UpdaterConsoleOptions options )
{
var updateLocation = GetUpdateLocation ( ) ;
2018-06-24 01:31:08 +00:00
if ( ! ( updateLocation . EndsWith ( "\\" ) | | updateLocation . EndsWith ( "/" ) ) )
2017-04-15 08:45:10 +00:00
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 ) ) ;
}
2018-06-24 01:31:08 +00:00
var isWindows = Environment . OSVersion . Platform = = PlatformID . Win32NT ;
2017-04-15 08:45:10 +00:00
var trayRunning = false ;
var trayProcesses = Process . GetProcessesByName ( "JackettTray" ) ;
if ( isWindows )
{
2019-03-06 09:20:32 +00:00
if ( trayProcesses . Length > 0 )
2017-04-15 08:45:10 +00:00
foreach ( var proc in trayProcesses )
try
{
2020-09-24 20:02:45 +00:00
logger . Info ( $"Killing tray process {proc.Id}" ) ;
2017-04-15 08:45:10 +00:00
proc . Kill ( ) ;
trayRunning = true ;
}
2020-09-24 20:02:45 +00:00
catch ( Exception e )
{
logger . Error ( e ) ;
}
2017-04-15 08:45:10 +00:00
// 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 ) ;
}
2019-04-08 10:32:08 +00:00
2020-02-10 22:16:19 +00:00
var variants = new Variants ( ) ;
2019-04-08 10:32:08 +00:00
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
2020-02-10 22:16:19 +00:00
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 ) ;
2020-02-10 22:16:19 +00:00
foreach ( var fileForDelete in removeList )
2019-04-08 10:32:08 +00:00
{
2019-05-04 10:47:27 +00:00
try
2019-04-08 10:32:08 +00:00
{
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-04-08 10:32:08 +00:00
}
2019-05-04 10:47:27 +00:00
catch ( Exception e )
2019-04-08 10:32:08 +00:00
{
2019-05-04 10:47:27 +00:00
logger . Error ( e ) ;
2019-04-08 10:32:08 +00:00
}
}
}
2018-06-24 01:31:08 +00:00
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 ( ) ;
2020-09-24 20:02:45 +00:00
logger . Info ( $"{files.Count} update files found" ) ;
2017-04-15 08:45:10 +00:00
2019-05-11 03:04:07 +00:00
try
{
foreach ( var file in files )
2017-04-15 08:45:10 +00:00
{
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
2020-02-10 22:16:19 +00:00
var fileCopySuccess = CopyUpdateFile ( options . Path , file , updateLocation , false ) ;
2019-05-04 10:47:27 +00:00
2020-09-24 20:02:45 +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 ) ;
2017-04-15 08:45:10 +00:00
}
}
2020-09-24 20:02:45 +00:00
catch ( Exception e )
2019-05-11 03:04:07 +00:00
{
2020-09-24 20:02:45 +00:00
logger . Error ( e ) ;
2019-05-11 03:04:07 +00:00
}
2017-04-15 08:45:10 +00:00
2019-05-04 10:47:27 +00:00
logger . Info ( "File copying complete" ) ;
2017-04-15 08:45:10 +00:00
// delete old dirs
2020-02-10 22:16:19 +00:00
var oldDirs = new string [ ] { "Content/logos" } ;
2017-04-15 08:45:10 +00:00
foreach ( var oldDir in oldDirs )
{
try
{
var deleteDir = Path . Combine ( options . Path , oldDir ) ;
if ( Directory . Exists ( deleteDir ) )
{
2018-06-24 01:31:08 +00:00
logger . Info ( "Deleting directory " + deleteDir ) ;
2017-04-15 08:45:10 +00:00
Directory . Delete ( deleteDir , true ) ;
}
}
catch ( Exception e )
{
2018-06-24 01:31:08 +00:00
logger . Error ( e ) ;
2017-04-15 08:45:10 +00:00
}
}
// delete old files
2020-02-10 22:16:19 +00:00
var oldFiles = new string [ ] {
2020-02-09 02:43:32 +00:00
"appsettings.Development.json" ,
"Autofac.Integration.WebApi.dll" ,
"Content/congruent_outline.png" ,
"Content/crissXcross.png" ,
2017-04-15 08:45:10 +00:00
"Content/css/jquery.dataTables.css" ,
"Content/css/jquery.dataTables_themeroller.css" ,
2020-03-01 18:58:14 +00:00
"CsQuery.dll" ,
2020-02-09 02:43:32 +00:00
"CurlSharp.dll" ,
"CurlSharp.pdb" ,
2020-11-12 15:27:41 +00:00
"Definitions/32pages.yml" ,
2020-02-09 02:43:32 +00:00
"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" ,
2020-09-26 21:53:11 +00:00
"Definitions/alexfilm.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/anidex.yml" , // migrated to C#
2020-03-01 18:58:14 +00:00
"Definitions/aox.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/apollo.yml" , // migrated to C# gazelle base tracker
"Definitions/archetorrent.yml" ,
"Definitions/asiandvdclub.yml" ,
"Definitions/avg.yml" ,
2020-03-28 16:24:46 +00:00
"Definitions/awesomehd.yml" , // migrated to C#
2020-02-09 02:43:32 +00:00
"Definitions/b2s-share.yml" ,
2020-08-26 21:34:12 +00:00
"Definitions/badasstorrents.yml" , // to be migrated to c#
2020-02-09 02:43:32 +00:00
"Definitions/bithq.yml" ,
"Definitions/bitme.yml" ,
2020-04-10 04:01:29 +00:00
"Definitions/bittorrentam.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/blubits.yml" ,
2020-10-12 18:19:32 +00:00
"Definitions/brobits.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/bt-scene.yml" ,
"Definitions/btbit.yml" ,
2020-09-20 07:12:35 +00:00
"Definitions/bteye.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/btkitty.yml" ,
"Definitions/btstornet.yml" ,
"Definitions/btxpress.yml" ,
2020-06-06 23:32:13 +00:00
"Definitions/cili180.yml" , // renamed to liaorencili
2020-02-09 02:43:32 +00:00
"Definitions/cinefilhd.yml" ,
2020-05-13 05:39:53 +00:00
"Definitions/crazyscorner.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/czteam.yml" ,
2020-10-12 18:23:48 +00:00
"Definitions/cztorrent.yml" ,
2020-10-12 20:51:29 +00:00
"Definitions/darmowetorenty.yml" , // migrated to C#
2020-07-12 22:46:18 +00:00
"Definitions/demonsite.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/digbt.yml" ,
2020-09-16 21:15:17 +00:00
"Definitions/downloadville.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/dragonworld.yml" ,
"Definitions/dreamteam.yml" ,
2020-03-10 07:07:03 +00:00
"Definitions/eggmeon.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/elitehd.yml" ,
2020-10-24 17:18:29 +00:00
"Definitions/elitetorrent-biz.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/elittracker.yml" ,
"Definitions/eotforum.yml" ,
2020-04-29 23:04:05 +00:00
"Definitions/estrenosdtl.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/evolutionpalace.yml" ,
2020-06-16 22:08:21 +00:00
"Definitions/extratorrent-ag.yml" ,
2020-06-07 01:37:12 +00:00
"Definitions/exoticaz.yml" , // migrated to C#
2020-02-09 02:43:32 +00:00
"Definitions/extratorrentclone.yml" ,
2020-04-02 19:29:08 +00:00
"Definitions/feedurneed.yml" ,
2020-09-26 04:47:54 +00:00
"Definitions/filmsclub.yml" ,
2017-04-15 08:45:10 +00:00
"Definitions/freakstrackingsystem.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/freedomhd.yml" ,
"Definitions/gdf76.yml" ,
"Definitions/gfxnews.yml" ,
"Definitions/gods.yml" ,
"Definitions/gormogon.yml" ,
2020-03-08 19:21:26 +00:00
"Definitions/greeklegends.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/hachede-c.yml" ,
"Definitions/hd4free.yml" ,
2017-04-15 08:45:10 +00:00
"Definitions/hdbc.yml" , // renamed to hdbitscom
2020-02-09 02:43:32 +00:00
"Definitions/hdclub.yml" ,
"Definitions/hdplus.yml" ,
"Definitions/hon3yhd-net.yml" ,
"Definitions/horriblesubs.yml" ,
"Definitions/hyperay.yml" ,
2020-05-30 17:49:18 +00:00
"Definitions/icetorrent.yml" , // migrated to C# XtremeZone base tracker
2020-02-09 02:43:32 +00:00
"Definitions/idopeclone.yml" ,
"Definitions/iloveclassics.yml" ,
"Definitions/infinityt.yml" ,
2020-07-11 20:55:28 +00:00
"Definitions/inperil.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/isohunt.yml" ,
2020-09-12 09:37:36 +00:00
"Definitions/kapaki.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/katcrs.yml" ,
2020-09-11 19:23:10 +00:00
"Definitions/kaztorka.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/kikibt.yml" ,
2020-09-22 22:44:59 +00:00
"Definitions/liaorencili.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/lapausetorrents.yml" ,
"Definitions/lemencili.yml" ,
"Definitions/leparadisdunet.yml" ,
2020-10-04 14:20:10 +00:00
"Definitions/leporno.yml" ,
2017-08-11 11:45:49 +00:00
"Definitions/maniatorrent.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/manicomioshare.yml" ,
"Definitions/megabliz.yml" ,
2020-06-07 00:00:01 +00:00
"Definitions/metal-iplay-ro.yml" , // renamed to romanianmetaltorrents
2020-02-09 02:43:32 +00:00
"Definitions/mkvcage.yml" ,
2020-09-19 05:54:35 +00:00
"Definitions/moecat.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/music-master.yml" ,
2017-06-06 17:06:30 +00:00
"Definitions/nachtwerk.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/nexttorrent.yml" ,
2020-06-06 23:32:13 +00:00
"Definitions/nnm-club.yml" , // renamed to noname-club
2020-06-25 03:12:22 +00:00
"Definitions/nordichd.yml" ,
2020-06-06 23:32:13 +00:00
"Definitions/nostalgic.yml" , // renamed to vhstapes
2020-02-09 02:43:32 +00:00
"Definitions/nyaa.yml" ,
"Definitions/nyoo.yml" ,
"Definitions/passionetorrent.yml" ,
2017-09-11 13:10:54 +00:00
"Definitions/polishtracker.yml" ,
2020-09-17 05:13:45 +00:00
"Definitions/pt99.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/qctorrent.yml" ,
"Definitions/qxr.yml" ,
2017-09-22 06:04:52 +00:00
"Definitions/rapidetracker.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/rarbg.yml" ,
"Definitions/redtopia.yml" ,
"Definitions/rgu.yml" ,
2020-04-18 03:34:50 +00:00
"Definitions/rns.yml" , // site merged with audiobooktorrents
2020-02-09 02:43:32 +00:00
"Definitions/rockethd.yml" ,
"Definitions/rockhardlossless.yml" ,
2020-06-15 19:49:47 +00:00
"Definitions/rodvd.yml" ,
2020-05-30 17:49:18 +00:00
"Definitions/scenefz.yml" , // migrated to C# XtremeZone base tracker
2020-02-09 02:43:32 +00:00
"Definitions/scenehd.yml" , // migrated to C# (use JSON API)
"Definitions/scenereactor.yml" ,
2020-03-01 19:34:53 +00:00
"Definitions/scenexpress.yml" ,
2018-01-03 18:51:00 +00:00
"Definitions/secretcinema.yml" , // migrated to C# gazelle base tracker
2020-03-22 21:01:58 +00:00
"Definitions/seedpeer.yml" ,
2020-04-27 21:51:07 +00:00
"Definitions/sharespacedb.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/sharingue.yml" ,
2018-02-21 18:11:48 +00:00
"Definitions/skytorrents.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/solidtorrents.yml" , // migrated to C#
2020-10-05 20:43:56 +00:00
"Definitions/soundpark.yml" , // to be migrated to C#
2020-02-09 02:43:32 +00:00
"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" ,
2020-02-09 02:43:32 +00:00
"Definitions/themoviecave.yml" ,
2020-03-01 20:54:09 +00:00
"Definitions/theresurrection.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/thetorrents.yml" ,
2020-05-13 05:39:53 +00:00
"Definitions/the-madhouse.yml" ,
2020-09-24 02:13:17 +00:00
"Definitions/thepiratebay.yml" , // migrated to c#
2020-10-28 00:00:37 +00:00
"Definitions/theunknown.yml" , // became 3evils #9678
2020-02-09 02:43:32 +00:00
"Definitions/tigers-dl.yml" ,
2020-06-25 04:33:44 +00:00
"Definitions/tntvillage.yml" ,
2020-10-27 03:13:40 +00:00
"Definitions/topnow.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/torrentcouch.yml" ,
2020-07-21 22:42:11 +00:00
"Definitions/torrenthane.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/torrentkim.yml" ,
"Definitions/torrentproject.yml" ,
2020-04-21 00:07:39 +00:00
"Definitions/torrentrex.yml" ,
2020-10-14 00:01:13 +00:00
"Definitions/torrentseed.yml" , // renamed to latinop2p #9065
2020-03-10 07:11:35 +00:00
"Definitions/torrentseeds.yml" , // migrated to c#
2018-12-28 15:16:18 +00:00
"Definitions/torrentsmd.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/torrentvault.yml" ,
2020-03-15 03:35:05 +00:00
"Definitions/torrentwal.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/torrentwtf.yml" ,
"Definitions/torrof.yml" ,
"Definitions/torviet.yml" ,
"Definitions/tspate.yml" ,
2020-07-24 20:10:50 +00:00
"Definitions/turknova.yml" ,
2020-07-23 20:20:38 +00:00
"Definitions/u-torrents.yml" ,
2020-02-09 02:43:32 +00:00
"Definitions/ultimategamerclub.yml" ,
"Definitions/ultrahdclub.yml" ,
2020-08-26 21:34:12 +00:00
"Definitions/uniotaku.yml" , // to be migrated to c#
2020-02-09 02:43:32 +00:00
"Definitions/utorrents.yml" , // same as SzeneFZ now
2020-05-15 02:28:51 +00:00
"Definitions/vanila.yml" ,
2020-09-02 06:37:05 +00:00
"Definitions/vhstapes.yml" ,
2020-10-12 20:31:13 +00:00
"Definitions/world-of-tomorrow.yml" , // #9213
2020-02-09 02:43:32 +00:00
"Definitions/waffles.yml" ,
"Definitions/worldofp2p.yml" ,
"Definitions/worldwidetorrents.yml" ,
"Definitions/xktorrent.yml" ,
2020-08-24 05:16:52 +00:00
"Definitions/xtremefile.yml" ,
2020-05-30 17:49:18 +00:00
"Definitions/xtremezone.yml" , // migrated to C# XtremeZone base tracker
2020-05-15 22:13:30 +00:00
"Definitions/yourexotic.yml" , // renamed to exoticaz.yml
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" ,
2020-03-01 18:58:14 +00:00
"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" ,
2020-03-01 18:58:14 +00:00
"System.Xml.XPath.XmlDocument.dll"
2017-04-15 08:45:10 +00:00
} ;
2018-06-24 01:31:08 +00:00
foreach ( var oldFile in oldFiles )
2017-04-15 08:45:10 +00:00
{
try
{
2018-06-24 01:31:08 +00:00
var deleteFile = Path . Combine ( options . Path , oldFile ) ;
2017-04-15 08:45:10 +00:00
if ( File . Exists ( deleteFile ) )
{
2018-06-24 01:31:08 +00:00
logger . Info ( "Deleting file " + deleteFile ) ;
2017-04-15 08:45:10 +00:00
File . Delete ( deleteFile ) ;
}
}
catch ( Exception e )
{
2018-06-24 01:31:08 +00:00
logger . Error ( e ) ;
2017-04-15 08:45:10 +00:00
}
}
2020-05-15 23:43:42 +00:00
// remove .lock file to detect errors in the update process
var lockFilePath = Path . Combine ( options . Path , ".lock" ) ;
if ( File . Exists ( lockFilePath ) )
File . Delete ( lockFilePath ) ;
2017-04-15 08:45:10 +00:00
// kill pids after the update on UNIX
if ( ! isWindows )
KillPids ( pids ) ;
2019-03-06 09:20:32 +00:00
if ( ! options . NoRestart )
2017-04-15 08:45:10 +00:00
{
2018-06-27 12:02:51 +00:00
if ( isWindows & & ( trayRunning | | options . StartTray ) & & ! string . Equals ( options . Type , "WindowsService" , StringComparison . OrdinalIgnoreCase ) )
2017-04-15 08:45:10 +00:00
{
var startInfo = new ProcessStartInfo ( )
{
2018-06-26 09:44:12 +00:00
Arguments = $"--UpdatedVersion \" { EnvironmentUtil . JackettVersion } \ "" ,
2017-04-15 08:45:10 +00:00
FileName = Path . Combine ( options . Path , "JackettTray.exe" ) ,
UseShellExecute = true
} ;
2018-06-26 09:44:12 +00:00
logger . Info ( "Starting Tray: " + startInfo . FileName + " " + startInfo . Arguments ) ;
2017-04-15 08:45:10 +00:00
Process . Start ( startInfo ) ;
2018-06-24 01:31:08 +00:00
if ( ! windowsService . ServiceExists ( ) )
{
//User was running the tray icon, but not using the Windows service, starting Tray icon will start JackettConsole as well
return ;
}
2017-04-15 08:45:10 +00:00
}
2018-06-27 12:02:51 +00:00
if ( string . Equals ( options . Type , "WindowsService" , StringComparison . OrdinalIgnoreCase ) )
2017-04-15 08:45:10 +00:00
{
2018-06-26 09:44:12 +00:00
logger . Info ( "Starting Windows service" ) ;
2020-09-12 00:25:27 +00:00
try
2017-04-15 08:45:10 +00:00
{
2018-06-24 01:31:08 +00:00
windowsService . Start ( ) ;
2017-04-15 08:45:10 +00:00
}
2020-09-12 00:25:27 +00:00
catch
2018-06-26 09:44:12 +00:00
{
2020-09-12 00:25:27 +00:00
logger . Info ( "Failed to start service. Attempting to start console." ) ;
2018-06-26 09:44:12 +00:00
try
{
var consolePath = Path . Combine ( options . Path , "JackettConsole.exe" ) ;
processService . StartProcessAndLog ( consolePath , "--Start" , true ) ;
}
catch
{
2020-09-12 00:25:27 +00:00
logger . Error ( "Failed to start the service or console." ) ;
2018-06-26 09:44:12 +00:00
}
}
2018-06-24 01:31:08 +00:00
}
else
2017-04-15 08:45:10 +00:00
{
var startInfo = new ProcessStartInfo ( )
{
Arguments = options . Args ,
2019-03-03 04:44:18 +00:00
FileName = GetJackettConsolePath ( options . Path ) ,
2017-04-15 08:45:10 +00:00
UseShellExecute = true
} ;
2018-06-30 12:49:11 +00:00
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 )
2017-04-15 08:45:10 +00:00
{
startInfo . Arguments = startInfo . FileName + " " + startInfo . Arguments ;
startInfo . FileName = "mono" ;
}
2019-03-06 10:16:20 +00:00
if ( variant = = Variants . JackettVariant . CoreMacOs | | variant = = Variants . JackettVariant . CoreLinuxAmdx64
| | variant = = Variants . JackettVariant . CoreLinuxArm32 | | variant = = Variants . JackettVariant . CoreLinuxArm64 )
{
startInfo . UseShellExecute = false ;
startInfo . CreateNoWindow = true ;
}
2018-06-24 01:31:08 +00:00
logger . Info ( "Starting Jackett: " + startInfo . FileName + " " + startInfo . Arguments ) ;
2017-04-15 08:45:10 +00:00
Process . Start ( startInfo ) ;
}
}
}
2019-05-04 10:47:27 +00:00
private bool CopyUpdateFile ( string jackettDestinationDirectory , string fullSourceFilePath , string updateSourceDirectory , bool previousAttemptFailed )
{
2020-02-10 22:16:19 +00:00
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 ;
}
2017-04-15 08:45:10 +00:00
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
2020-01-04 18:49:53 +00:00
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 ;
2017-04-15 08:45:10 +00:00
}
2019-03-03 04:44:18 +00:00
private string GetJackettConsolePath ( string directoryPath )
{
2020-02-10 22:16:19 +00:00
var variants = new Variants ( ) ;
2020-09-24 20:02:45 +00:00
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 ) ;
}
2017-04-15 08:45:10 +00:00
}
}