<commit_before>/*
 * FSpot.Application.cs
 *
 * Author(s):
 *	<NAME>  <<EMAIL>>
 *
 * Copyright (c) 2009 <NAME>.
 *
 * This is open source software. See COPYING fro details.
 */

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;

using Unique;

using Mono.Unix;

using Hyena;

namespace FSpot
{
	public class App : Unique.App
	{
#region public API
		static App app;
		public static App Instance {
			get {
				if (app == null)
					app = new App ();
				return app;
			}
		}

		public MainWindow Organizer {
			get {
				if (organizer == null) {
					organizer = new MainWindow (Database);
					Register (organizer.Window);
				}
				return organizer;
			}
		}

		public Db Database {
			get {
				if (db == null) {
					if (!File.Exists (FSpot.Global.BaseDirectory))
						Directory.CreateDirectory (FSpot.Global.BaseDirectory);

					db = new Db ();

					try {
						db.Init (Path.Combine (FSpot.Global.BaseDirectory, "photos.db"), true);
					} catch (Exception e) {
						new FSpot.UI.Dialog.RepairDbDialog (e, db.Repair (), null);
						db.Init (Path.Combine (FSpot.Global.BaseDirectory, "photos.db"), true);
					}
				}
				return db;
			}
		}

		public void Import (string path)
		{
			if (IsRunning) {
				var md = new MessageData ();
				md.Text = path;
				SendMessage (Command.Import, md);
				return;
			}
			HandleImport (path);
		}

		public void Organize ()
		{
			if (IsRunning) {
				SendMessage (Command.Organize, null);
				return;
			}
			HandleOrganize ();
		}<commit_msg>Fix unsafe singleton construction.<commit_after>/*
 * FSpot.Application.cs
 *
 * Author(s):
 *	<NAME>  <<EMAIL>>
 *
 * Copyright (c) 2009 <NAME>.
 *
 * This is open source software. See COPYING fro details.
 */

using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading;

using Unique;

using Mono.Unix;

using Hyena;

namespace FSpot
{
	public class App : Unique.App
	{
		static object sync_handle = new object ();

#region public API
		static App app;
		public static App Instance {
			get {
				lock (sync_handle) {
					if (app == null)
						app = new App ();
				}
				return app;
			}
		}

		Thread constructing_organizer = null;

		public MainWindow Organizer {
			get {
				lock (sync_handle) {
					if (organizer == null) {
						if (constructing_organizer == Thread.CurrentThread) {
							throw new Exception ("Recursively tried to acquire App.Organizer!");
						}

						constructing_organizer = Thread.CurrentThread;
						organizer = new MainWindow (Database);
						Register (organizer.Window);
					}
				}
				return organizer;
			}
		}

		public Db Database {
			get {
				lock (sync_handle) {
					if (db == null) {
						if (!File.Exists (FSpot.Global.BaseDirectory))
							Directory.CreateDirectory (FSpot.Global.BaseDirectory);

						db = new Db ();

						try {
							db.Init (Path.Combine (FSpot.Global.BaseDirectory, "photos.db"), true);
						} catch (Exception e) {
							new FSpot.UI.Dialog.RepairDbDialog (e, db.Repair (), null);
							db.Init (Path.Combine (FSpot.Global.BaseDirectory, "photos.db"), true);
						}
					}
				}
				return db;
			}
		}

		public void Import (string path)
		{
			if (IsRunning) {
				var md = new MessageData ();
				md.Text = path;
				SendMessage (Command.Import, md);
				return;
			}
			HandleImport (path);
		}

		public void Organize ()
		{
			if (IsRunning) {
				SendMessage (Command.Organize, null);
				return;
			}
			HandleOrganize ();
		}
{'fraction_non_alphanumeric': 0.12407089765580331, 'fraction_numerical': 0.002287021154945683, 'mean_word_length': 2.541497975708502, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5063035', 'n_tokens_mistral': 1505, 'n_tokens_neox': 1137, 'n_words': 306}