View | Details | Raw Unified | Return to bug 386548
Collapse All | Expand All

(-)Monsoon/MainWindow.cs (+5 lines)
Lines 349-354 Link Here
349
			}
349
			}
350
		}
350
		}
351
		
351
		
352
		public void LoadTorrent (string path)
353
		{
354
			torrentController.addTorrent (path, true, true); 
355
		}
356
		
352
		private void RestoreInterfaceSettings ()
357
		private void RestoreInterfaceSettings ()
353
		{
358
		{
354
			InterfaceSettings settings = interfaceSettings.Settings;
359
			InterfaceSettings settings = interfaceSettings.Settings;
(-)Monsoon/Main.cs (-5 / +48 lines)
Lines 81-87 Link Here
81
					GLib.Timeout.Add (1000, delegate {
81
					GLib.Timeout.Add (1000, delegate {
82
						try
82
						try
83
						{
83
						{
84
							mainWindow.TorrentController.addTorrent(arg);
84
							mainWindow.TorrentController.addTorrent (arg, true, true);
85
						}
85
						}
86
						catch (Exception ex)
86
						catch (Exception ex)
87
						{
87
						{
Lines 120-131 Link Here
120
			Console.WriteLine(_("Starting Monsoon"));
120
			Console.WriteLine(_("Starting Monsoon"));
121
			
121
			
122
			Application.Init("monsoon", ref args);
122
			Application.Init("monsoon", ref args);
123
			Monsoon.GconfPreferencesSettingsController sets = new GconfPreferencesSettingsController();
124
			sets.Load ();
125
126
			try
127
			{
128
				mainWindow = new MainWindow (settingsStorage, engineSettings.Settings,
129
				                             portController, isFirstRun);
130
			}
131
			catch(Exception ex)
132
			{
133
				logger.Info("Existing instance detected");
134
				if (args.Length > 0 && File.Exists(args[0]))
135
				{
136
					logger.Info ("Informing existing instance of new torrent");
137
					string oldPath = args[0];
138
					string newPath = Path.Combine(sets.Settings.TorrentStorageLocation, Path.GetFileName(args[0]));
139
					logger.Info ("Copying: {0} to {1}", oldPath, newPath);
140
					
141
					if (File.Exists (newPath))
142
						File.Delete (newPath);
143
					
144
					File.Copy(oldPath, newPath ,true);
145
				}
146
				else
147
				{
148
					logger.Info ("No new torrents detected");
149
				}
150
				Environment.Exit (0);
151
			}
123
			
152
			
124
			mainWindow = new MainWindow (settingsStorage, engineSettings.Settings,
153
			if (File.Exists(sets.Settings.TorrentStorageLocation))
125
									portController, isFirstRun);
154
				StartLocalFileWatcher (mainWindow, sets.Settings.TorrentStorageLocation);
126
			
155
			else
156
				StartLocalFileWatcher (mainWindow, Defines.TorrentFolder);
127
			GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(OnUnhandledException);
157
			GLib.ExceptionManager.UnhandledException += new GLib.UnhandledExceptionHandler(OnUnhandledException);
128
			
129
			Application.Run();
158
			Application.Run();
130
159
131
			try {
160
			try {
Lines 138-143 Link Here
138
			mainWindow.Stop ();
167
			mainWindow.Stop ();
139
			mainWindow.Destroy ();
168
			mainWindow.Destroy ();
140
		}
169
		}
170
		
171
		private static void StartLocalFileWatcher (MainWindow window, string path)
172
		{
173
			FileSystemWatcher watcher = new FileSystemWatcher(path, "*.torrent");
174
			
175
			watcher.Created += delegate (object o, System.IO.FileSystemEventArgs  e) {
176
				logger.Info ("Loading: {0}", e.FullPath);
177
				GLib.Timeout.Add (250, delegate {
178
					window.LoadTorrent (e.FullPath);
179
					return false;
180
				});
181
			};
182
			watcher.EnableRaisingEvents = true;
183
		}
141
184
142
		public static void SetProcessName(string name)
185
		public static void SetProcessName(string name)
143
		{
186
		{
(-)Monsoon/TorrentController.cs (-4 / +24 lines)
Lines 53-58 Link Here
53
		private Dictionary<TorrentManager, long> torrentPreviousUpload;
53
		private Dictionary<TorrentManager, long> torrentPreviousUpload;
54
		private Dictionary<TorrentManager, long> torrentPreviousDownload;
54
		private Dictionary<TorrentManager, long> torrentPreviousDownload;
55
		private MainWindow mainWindow;
55
		private MainWindow mainWindow;
56
		public MainWindow MainWindow
57
		{
58
			get { return mainWindow; }
59
		}
56
		
60
		
57
		private List<TorrentManager> torrentsDownloading;
61
		private List<TorrentManager> torrentsDownloading;
58
		private List<TorrentManager> torrentsSeeding;
62
		private List<TorrentManager> torrentsSeeding;
Lines 197-203 Link Here
197
			if (!isUrl && moveToStorage && (prefSettings.TorrentStorageLocation != Directory.GetParent(torrentPath).ToString()) ) {
201
			if (!isUrl && moveToStorage && (prefSettings.TorrentStorageLocation != Directory.GetParent(torrentPath).ToString()) ) {
198
				newPath = Path.Combine(prefSettings.TorrentStorageLocation, Path.GetFileName(torrentPath));
202
				newPath = Path.Combine(prefSettings.TorrentStorageLocation, Path.GetFileName(torrentPath));
199
				logger.Debug("Copying torrent to " + newPath);	
203
				logger.Debug("Copying torrent to " + newPath);	
200
				File.Copy(torrentPath, newPath, true);
204
				// The files should already be in the TorrentStorageLocation
205
				//File.Copy(torrentPath, newPath, true);
201
				
206
				
202
				if (removeOriginal) {
207
				if (removeOriginal) {
203
					logger.Info("Deleting original torrent " + torrentPath);
208
					logger.Info("Deleting original torrent " + torrentPath);
Lines 462-470 Link Here
462
		{
467
		{
463
			if(!prefSettings.ImportEnabled)
468
			if(!prefSettings.ImportEnabled)
464
				return;
469
				return;
465
				
470
			
466
			logger.Info("New torrent detected, adding " + args.TorrentPath);
471
			GLib.Timeout.Add (250, delegate {
467
			addTorrent(args.TorrentPath, prefSettings.StartNewTorrents, true, prefSettings.RemoveOnImport, null);
472
				string newPath = Path.Combine(MainWindow.Preferences.TorrentStorageLocation, Path.GetFileName(args.TorrentPath));
473
				logger.Info ("Copying: {0} to {1}", args.TorrentPath, newPath);
474
				try
475
				{
476
					if (File.Exists (newPath))
477
						File.Delete (newPath);
478
					
479
					File.Copy(args.TorrentPath, newPath ,true);
480
				}
481
				catch (Exception ex)
482
				{
483
					
484
				}
485
				return false;
486
			});
487
			//addTorrent(args.TorrentPath, prefSettings.StartNewTorrents, true, prefSettings.RemoveOnImport, null);
468
		}
488
		}
469
		
489
		
470
		public void LoadStoredTorrents()
490
		public void LoadStoredTorrents()
(-)Monsoon/TorrentTreeView.cs (-1 / +14 lines)
Lines 130-136 Link Here
130
				Uri uri = new Uri(s.TrimEnd());
130
				Uri uri = new Uri(s.TrimEnd());
131
				if(uri.IsFile){
131
				if(uri.IsFile){
132
					logger.Info("URI dropped " + uri);
132
					logger.Info("URI dropped " + uri);
133
						torrentController.addTorrent(uri.LocalPath);
133
					string newPath = System.IO.Path.Combine(torrentController.MainWindow.Preferences.TorrentStorageLocation,
134
					                                        System.IO.Path.GetFileName(uri.LocalPath));
135
					Console.Error.WriteLine("Copying: {0} to {1}", uri.LocalPath, newPath);
136
137
					try
138
					{
139
						if (System.IO.File.Exists (newPath))
140
							System.IO.File.Delete (newPath);
141
						System.IO.File.Copy(uri.LocalPath, newPath ,true); 
142
					}
143
					catch (Exception ex)
144
					{
145
						logger.Error ("Could not load DND torrent: {0}", ex);
146
					}
134
				}
147
				}
135
			}		
148
			}		
136
		}
149
		}

Return to bug 386548