Exemple #1
0
        public static ConfigINI GetInstance()
        {
            if (Instance == null)
            {
                Uri    applicationDirectoryUri = new Uri(AppDomain.CurrentDomain.BaseDirectory);
                Uri    applicationIniFileUri   = new Uri(applicationDirectoryUri, "config.ini");
                string applicationIniFilePath  = Uri.UnescapeDataString(applicationIniFileUri.LocalPath);
                Instance = new ConfigINI(applicationIniFilePath);
            }

            return(Instance);
        }
        public AppContext()
        {
            properties = ConfigINI.GetInstance().Items;

            if (properties.ContainsKey("SOURCE_PATH"))
            {
                SourcePath = properties["SOURCE_PATH"].ToString();
                if (!FileFunctions.FileFunctions.IsValidRootedPath(SourcePath))
                {
                    MessageBox.Show($"Source path \"{SourcePath}\" is not a valid rooted path.", "Fermeture du programme");
                    Application.Exit();
                }
            }
            else
            {
                throw new Exception("Source path is undefined.");
            }

            if (properties.ContainsKey("DESTINATION_PATH"))
            {
                DestinationPath = properties["DESTINATION_PATH"].ToString();
                if (!FileFunctions.FileFunctions.IsValidRootedPath(DestinationPath))
                {
                    MessageBox.Show($"Destination path \"{DestinationPath}\" is not a valid rooted path.", "Fermeture du programme");
                    Application.Exit();
                }
            }
            else
            {
                throw new Exception("Destination path is undefined.");
            }

            CreateSystemTrayIcon();
            Application.ApplicationExit += OnApplicationExit;

            FileSystemWatcher2.EventIDs events = FileSystemWatcher2.EventIDs.NONE;
            if (properties.ContainsKey("MANAGE_EVENTS"))
            {
                foreach (string eventName in properties["MANAGE_EVENTS"].ToString().Split(','))
                {
                    switch (eventName)
                    {
                    case "Created":
                        events |= FileSystemWatcher2.EventIDs.CREATED;
                        break;

                    case "Changed":
                        events |= FileSystemWatcher2.EventIDs.CHANGED;
                        break;

                    case "Renamed":
                        events |= FileSystemWatcher2.EventIDs.RENAMED;
                        break;

                    case "Deleted":
                        events |= FileSystemWatcher2.EventIDs.DELETED;
                        break;

                    default:
                        // This is an invalid event name.
                        break;
                    }
                }
            }
            else
            {
                events = FileSystemWatcher2.EventIDs.ALL;
            }
            fileSystemWatcher = new FileSystemWatcher2(SourcePath, DestinationPath, events);
            StartFileSystemWatcher();
        }