Esempio n. 1
0
        public RootApplication(frmMenu frm)
        {
#if DEBUG
            IsDebug = true;
#endif
            Menu = frm;
            m_Documents.Add(null);             // because the editor will just assign the current document into the current index

            // folders...
            EXEFolder      = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            InternalFolder = EXEFolder;

            SharedFolder = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), AppName);
            ConfigFolder = SharedFolder;
            bool sharedCreated = false;
            // create shared folder and set permissions
            try
            {
                if (!System.IO.Directory.Exists(SharedFolder))
                {
                    System.IO.Directory.CreateDirectory(SharedFolder);
                    System.Security.AccessControl.DirectorySecurity    dirSecurity = System.IO.Directory.GetAccessControl(SharedFolder);
                    System.Security.Principal.SecurityIdentifier       user        = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
                    System.Security.AccessControl.FileSystemAccessRule newRule     = new System.Security.AccessControl.FileSystemAccessRule(user, System.Security.AccessControl.FileSystemRights.FullControl,
                                                                                                                                            System.Security.AccessControl.InheritanceFlags.ContainerInherit | System.Security.AccessControl.InheritanceFlags.ObjectInherit, System.Security.AccessControl.PropagationFlags.None, System.Security.AccessControl.AccessControlType.Allow);
                    dirSecurity.AddAccessRule(newRule);
                    System.IO.Directory.SetAccessControl(SharedFolder, dirSecurity);

                    sharedCreated = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cannot create required folder: " + SharedFolder + "\r\n" + "Error: " + ex);
                Application.Exit();
            }

#if DEBUG
            EXEFolder      = "d:\\data\\ace\\SAW\\Installer\\installer files";
            InternalFolder = EXEFolder;
            // config certainly needs to write back to the installation folder
            ConfigFolder = "d:\\data\\ace\\SAW\\test data";
            SharedFolder = "d:\\data\\ace\\SAW\\test data";
#else
            // Temporary version using folder location for everything
            //SharedFolder = EXEFolder + System.IO.Path.DirectorySeparatorChar + "Data";
            //ConfigFolder = SharedFolder;
#endif

            Globals.Root = this;
            try
            {
                Log                      = new CLogFile(SharedFolder + System.IO.Path.DirectorySeparatorChar + "log.txt");
                LogPermanent             = new CLogFile(SharedFolder + System.IO.Path.DirectorySeparatorChar + "permanent.txt", 100000);
                LogPermanent.TimeStampEx = TimeStamps.Date;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Could not create log files: " + ex.Message);
            }
            Log.WriteLine("Starting, version = " + SoftwareVersion.VersionString);
            Log.WriteLine("EXEFolder = " + EXEFolder);
            Log.WriteLine("SharedFolder = " + SharedFolder);
            Log.WriteLine("InternalFolder = " + InternalFolder);
            Log.WriteLine("OS = " + Environment.OSVersion);
            Log.WriteLine("64-bit = " + Environment.Is64BitOperatingSystem);
            Log.WriteLine("CLR = " + Environment.Version);
            Globals.CheckThemeOnStartup();

            if (sharedCreated)
            {
                // need to copy across from Splash 1 if applicable
                LogPermanent.WriteLine("Shared folder created");
            }

            Strings.Load();
            Log.WriteLine("SystemDPI = " + GUIUtilities.SystemDPI);

            Functions.Verb.CreateList();             // must before any configs loaded
            Functions.SAWVerbs.RegisterVerbs();

            // load configurations...
            Config.SystemConfig = LoadConfig("system" + Config.Extension, Config.Levels.System);
            Config.UserUser     = LoadConfig("User" + Config.Extension, Config.Levels.User, "user_Default" + Config.Extension);
            Config.UserUser.EnsureUserResources();
            if (!System.IO.Directory.Exists(Activities.ActivityConfigFolder))
            {
                System.IO.Directory.CreateDirectory(Activities.ActivityConfigFolder);
            }
            // activities are now loaded as needed

#if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += frmErrorReport.UnhandledException;
            Application.ThreadException += frmErrorReport.ThreadException;
#else
            Config.Delta.ApplyV8Changes();
#endif
            CurrentConfig = new AppliedConfig();
            CurrentConfig.AddConfigAtEnd(Config.SystemConfig);
            CurrentConfig.AddConfigWithPriority(Config.UserUser);
        }