Beispiel #1
0
        internal void Start()
        {
            string ApplicationPrefix = GlobalConfig.ProductName.ToUpperInvariant();

            TraceDebug.Trace("Start {0}", GlobalConfig.ProductName);
#if PORTABLE
            Environment.SetEnvironmentVariable(ApplicationPrefix + "_PORTABLE", GlobalConfig.MainFolder, EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable(ApplicationPrefix + "_DRIVE", GlobalConfig.ApplicationDrive, EnvironmentVariableTarget.Process);
#endif

            Environment.SetEnvironmentVariable(ApplicationPrefix + "_DATA", GlobalConfig.MainFolder, EnvironmentVariableTarget.Process);

            messageID = NativeMethods.RegisterWindowMessage("KrentoStop"); //Do not localize!!!
            NativeMethods.AddRemoveMessageFilter(messageID, ChangeWindowMessageFilterFlags.Add);


            PrepareStandardProperties();

            showSplashScreen = true;

            ApplyGUILanguage();

            GlobalSettings.LoadGlobalSettings();
            GlobalSettings.ManagerLeft = Settings.Default.ManagerLeft;
            GlobalSettings.ManagerTop  = Settings.Default.ManagerTop;



            #region Parse command line
            foreach (string param in args)
            {
                if (TextHelper.SameText(param, @"/low"))
                {
                    GlobalConfig.LowMemory = true;
                }

                if (TextHelper.SameText(param, @"/ns"))
                {
                    showSplashScreen = false;
                }

                if (TextHelper.SameText(param, @"/nd"))
                {
                    KrentoContext.SkipDocklets = true;
                }

                if (TextHelper.SameText(param, @"/nt"))
                {
                    KrentoContext.SkipToys = true;
                }

                if (TextHelper.SameText(param, @"/desktop"))
                {
                    KrentoContext.CreateDesktopCircle = true;
                }

                if (param.IndexOf(@".circle", StringComparison.OrdinalIgnoreCase) > 0)
                {
                    KrentoContext.CircleParameter = param;
                }

                if (FileOperations.IsKrentoPackage(param))
                {
                    KrentoContext.PackageParameter = param;
                }
            }
            #endregion

            this.context = new KrentoContext();

            #region FirstRun
            if (NativeMethods.GlobalCheckAtom("krento_first_run"))
            {
                KrentoContext.FirstRun = true;
                NativeMethods.GlobalKillAtom("krento_first_run");
            }
#if PORTABLE
            string firstRunFile = Path.Combine(GlobalConfig.ApplicationFolder, "first.run");
            if (NativeMethods.FileExists(firstRunFile))
            {
                KrentoContext.FirstRun = true;
                NativeMethods.FileDelete(firstRunFile);
            }
#endif
            if (KrentoContext.FirstRun)
            {
                GlobalSettings.SaveGlobalSettings();
            }
            #endregion

            #region First Instance
            if (context.FirstInstance)
            {
                if ((showSplashScreen) && GlobalSettings.ShowSplashScreen)
                {
                    splashScreen = new SplashScreen();
                }
                else
                {
                    splashScreen = null;
                }



                this.mainForm            = new MainForm(context);
                mainForm.Text            = GlobalConfig.ProductName;
                InteropHelper.MainWindow = mainForm.Handle;

                if (showSplashScreen)
                {
                    if (splashScreen != null)
                    {
                        mainForm.SplashScreen = splashScreen;
                    }
                }


                if (NativeMethods.StartEngineEx(mainForm.Handle))
                {
                    if (GlobalSettings.ActivateServer)
                    {
                        if (NetworkOperations.PortAvailable(GlobalSettings.PortNumber))
                        {
                            context.StartServer();
                        }
                    }


                    appContext = new ApplicationContext();

                    //Load plugins. If the instance is the first instance and
                    //engine is activated, then plugins are loaded

                    try
                    {
                        context.LoadKrentoPlugins();
                    }
                    catch (Exception)
                    {
                        //do not stop on wrong plugins
                        TraceDebug.Trace("Exception on loading Krento plugin");
                    }

                    try
                    {
                        context.LoadKrentoToys();
                    }
                    catch (Exception)
                    {
                        //do not stop on wrong plugins
                        TraceDebug.Trace("Exception on loading Krento toy");
                    }
                    try
                    {
                        context.LoadKrentoDocklets();
                    }
                    catch
                    {
                        //do not stop on wrong docklet
                        TraceDebug.Trace("Exception on loading docklet");
                    }

                    NativeThemeManager.MakeSound("#110");
                    Application.Run(appContext);
                }
            }
            #endregion
        }
Beispiel #2
0
        internal void InstallKrentoPart(string fileName)
        {
            string destination    = null;
            bool   compressed     = false;
            bool   loadNewToy     = false;
            bool   loadNewDocklet = false;
            bool   reloadStones   = false;
            string mainFolderName = null;

            string ext = Path.GetExtension(fileName);

            if (TextHelper.SameText(ext, ".toy"))
            {
                destination = GlobalConfig.ToysFolder;
                compressed  = true;
                loadNewToy  = true;
            }
            else
            if (TextHelper.SameText(ext, ".kmenu"))
            {
                destination = GlobalConfig.MenusFolder;
                compressed  = true;
            }
            else
            if (TextHelper.SameText(ext, ".kskin"))
            {
                destination = GlobalConfig.SkinsFolder;
                compressed  = true;
            }
            else
            if (TextHelper.SameText(ext, ".stone"))
            {
                destination  = GlobalConfig.StoneClasses;
                compressed   = true;
                reloadStones = true;
            }
            else
            if (TextHelper.SameText(ext, ".lng"))
            {
                destination = GlobalConfig.LanguagesFolder;
                compressed  = false;
            }
            else
            if (TextHelper.SameText(ext, ".kadd"))
            {
                destination = GlobalConfig.AddInRootFolder;
                compressed  = true;
            }
            else
            if (TextHelper.SameText(ext, ".docklet"))
            {
                destination    = GlobalConfig.DockletsFolder;
                compressed     = true;
                loadNewDocklet = true;
            }
            else
            if (TextHelper.SameText(ext, ".circle"))
            {
                destination = GlobalConfig.RollingStonesFolder;
                compressed  = false;
            }

            if (string.IsNullOrEmpty(destination))
            {
                return;
            }

            if (!compressed)
            {
                string destinationName = Path.Combine(destination, Path.GetFileName(fileName));
                try
                {
                    FileOperations.CopyFile(fileName, destinationName);
                    if (TextHelper.SameText(destination, GlobalConfig.RollingStonesFolder))
                    {
                        if (FileOperations.FileExists(destinationName))
                        {
                            Manager.HistoryAdd(destinationName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    TraceDebug.Trace(ex);
                }
            }
            else
            {
                try
                {
                    destination = Path.Combine(destination, Path.GetFileNameWithoutExtension(fileName));
                    if (!Directory.Exists(destination))
                    {
                        Directory.CreateDirectory(destination);
                    }
                }
                catch (Exception ex)
                {
                    TraceDebug.Trace(ex);
                }

                NativeMethods.ExtractArchive(fileName, destination);
                FileOperations.CopyFile(fileName, Path.Combine(GlobalConfig.DownloadsFolder, Path.GetFileName(fileName)));

                if (reloadStones)
                {
                    try
                    {
                        string newStonePath;
                        if (!string.IsNullOrEmpty(mainFolderName))
                        {
                            newStonePath = Path.Combine(destination, mainFolderName);
                        }
                        else
                        {
                            newStonePath = destination;
                        }
                        Language.Merge(Path.Combine(newStonePath, GlobalSettings.Language + ".lng"));
                    }
                    catch (Exception ex)
                    {
                        //Toy load error happens
                        TraceDebug.Trace(ex);
                    }

                    //Loading of the new stone must be AFTER merging of the language
                    Manager.LoadStoneClasses();
                }
                else
                if (loadNewToy)
                {
                    try
                    {
                        string newToyPath;
                        if (!string.IsNullOrEmpty(mainFolderName))
                        {
                            newToyPath = Path.Combine(destination, mainFolderName);
                        }
                        else
                        {
                            newToyPath = destination;
                        }
                        context.LoadKrentoToys(newToyPath);
                    }
                    catch (Exception ex)
                    {
                        //Toy load error happens
                        TraceDebug.Trace(ex);
                    }
                }
                else
                if (loadNewDocklet)
                {
                    try
                    {
                        string newDockletPath;

                        if (!string.IsNullOrEmpty(mainFolderName))
                        {
                            newDockletPath = Path.Combine(destination, mainFolderName);
                        }
                        else
                        {
                            newDockletPath = destination;
                        }
                        context.LoadKrentoDocklets(newDockletPath);
                    }
                    catch (Exception ex)
                    {
                        //Toy load error happens
                        TraceDebug.Trace(ex);
                    }
                }
            }
        }