Пример #1
0
        public MainWindow()
        {
            try
            {
                InitializeComponent();

                UpdateTarget = new CatalogApi.Settings.File(ConfigurationManager.AppSettings["UpdateTarget"]);

                Zip = new CatalogApi.Settings.File(ConfigurationManager.AppSettings["UpdateFileArchive"]);

                UpdateDirectory = ConfigurationManager.AppSettings["UpdateDirectory"];

                new Thread(() =>
                {
                    try
                    {
                        CheckTempFolderForUpdate();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message + " || " + ex.StackTrace);
                    }
                }).Start();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Dispatcher.BeginInvoke(new Action(() => Application.Current.Shutdown()));
            }
        }
Пример #2
0
        private void CheckForUpdateAndStartProcess()
        {
            string nameUpdateDirectory = string.Empty
            , nameAppVersionFile       = string.Empty;
            bool fileExists            = false;

            try
            {
                CatalogApi.Logging.Info(string.Format("::CheckForUpdateAndStartProcess() - вход..."));

                nameUpdateDirectory = ResourceManager.UpdateDirectory;
                nameAppVersionFile  = new CatalogApi.Settings.File(ConfigurationManager.AppSettings["FileAppVersion"]).Name;

                if (Directory.Exists(nameUpdateDirectory))
                {
                    IoHelper.DirectoryClear(nameUpdateDirectory);
                }

                AccountManager.Account = RequestHelper.Client.GetUnoccupiedAccount();

                launcherSettings = new SettingsFactory(categoryEventHandler).DownloadSettings(false, true);
                this.BuildWindow();

                if (System.IO.File.Exists(nameAppVersionFile))
                {
                    this.RefreshTitle(new Version(JsonConvert.DeserializeObject <VersionEntity>(IoHelper.OpenFile(nameAppVersionFile, out fileExists)).Version).ToString());
                }
                else
                {
                    ;
                }

                this.SetWindowVisibility(Visibility.Visible);

                CatalogApi.Logging.Info(string.Format("::CheckForUpdateAndStartProcess() - успех..."));
            }
            catch (Exception exception)
            {
                ErrorLogHelper.AddErrorInLog("CheckForUpdateAndStartProcess()", exception.Message + " | " + exception.StackTrace);
                MessageBox.Show(exception.Message + " | " + exception.StackTrace);

                Application.Current.Shutdown(-1);
            }
        }
Пример #3
0
        public LauncherSettings DownloadSettings(bool force, bool FullLoad = true)
        {
            string           nameFileDbSerialize = new CatalogApi.Settings.File(ConfigurationManager.AppSettings["FileDbSerialize"]).Name;
            LauncherSettings graph = new LauncherSettings();

            // режим "force" принажатии кнопки брэнда
            if ((force == true) &&
                (System.IO.File.Exists(nameFileDbSerialize) == true))
            {
                System.IO.File.Delete(nameFileDbSerialize);
            }
            else
            {
                ;
            }

            if (System.IO.File.Exists(nameFileDbSerialize) == true)
            {
                // для режима forse=false - прочитать и вернуть копию БД
                Stream          stream    = System.IO.File.OpenRead(nameFileDbSerialize);
                BinaryFormatter formatter = new BinaryFormatter();
                graph = (LauncherSettings)formatter.Deserialize(stream);
                stream.Close();

                return(graph);
            }
            else
            {
                ;
            }

            #region чтение БД, заполнение объектов значениями
            using (AvtoritetEntities entities = new AvtoritetEntities())
            {
                List <NewLauncher.DataContext.Brand> list = (from r in entities.Brand
                                                             where r.Enable
                                                             orderby r.NameAndFolder
                                                             select r).ToList <NewLauncher.DataContext.Brand>();
                List <Provider> list2 = (from r in entities.Provider
                                         where r.Enable & FullLoad
                                         orderby r.Order
                                         select r).ToList <Provider>();
                List <ProviderAccount> list3 = (from t in entities.ProviderAccount
                                                where t.Enable & FullLoad
                                                select t).ToList <ProviderAccount>();
                List <NewLauncher.DataContext.CommandFile> list4 = (from t in entities.CommandFile
                                                                    where FullLoad
                                                                    select t).ToList <NewLauncher.DataContext.CommandFile>();
                List <NewLauncher.DataContext.ProviderFile> list5 = (from t in entities.ProviderFile
                                                                     where FullLoad
                                                                     select t).ToList <NewLauncher.DataContext.ProviderFile>();
                List <Group> list6 = (from t in entities.Group
                                      where t.Enable
                                      orderby t.Order
                                      select t).ToList <Group>();
                List <NewLauncher.DataContext.GroupBox> list7 = (from r in entities.GroupBox
                                                                 where r.Enable
                                                                 orderby r.Title
                                                                 select r).ToList <NewLauncher.DataContext.GroupBox>();
                foreach (Group group in list6)
                {
                    GroupSet item = new GroupSet {
                        Name      = group.Name,
                        Width     = group.Width.Value,
                        Height    = group.Height.Value,
                        GroupBoxs = new List <CatalogApi.Settings.GroupBox>()
                    };
                    foreach (NewLauncher.DataContext.GroupBox box in list7)
                    {
                        if (box.GroupId == group.GroupId)
                        {
                            CatalogApi.Settings.GroupBox box2 = new CatalogApi.Settings.GroupBox {
                                Left          = box.Left.Value,
                                Top           = box.Top.Value,
                                Width         = box.Width.Value,
                                Height        = box.Height.Value,
                                Title         = box.Title,
                                VisibleBorder = box.VisibleBorder.Value,
                                Brands        = new List <CatalogApi.Settings.Brand>()
                            };
                            foreach (NewLauncher.DataContext.Brand brand in list)
                            {
                                if (brand.GroupBoxId == box.GroupBoxId)
                                {
                                    CatalogApi.Settings.Brand brand2 = new CatalogApi.Settings.Brand {
                                        NameAndFolder = brand.NameAndFolder,
                                        IconPath      = brand.IconPath,
                                        IconPath2     = brand.IconPath2,
                                        IconPathImg   = brand.IconPathImg,
                                        IconPath2Img  = brand.IconPath2Img
                                    };
                                    int?top = brand.Top;
                                    brand2.Top         = top.HasValue ? top.GetValueOrDefault() : 0;
                                    top                = brand.Left;
                                    brand2.Left        = top.HasValue ? top.GetValueOrDefault() : 0;
                                    top                = brand.Width;
                                    brand2.Width       = top.HasValue ? top.GetValueOrDefault() : 0;
                                    top                = brand.Height;
                                    brand2.Height      = top.HasValue ? top.GetValueOrDefault() : 0;
                                    brand2.BrandId     = brand.BrandId;
                                    brand2.ButtonStyle = brand.ButtonStyle;
                                    brand2.MenuWindow  = brand.MenuWindow.Value;
                                    brand2.Providers   = new List <BrandProvider>();
                                    foreach (Provider provider in list2)
                                    {
                                        int providerId;
                                        if (provider.BrandId != brand.BrandId)
                                        {
                                            continue;
                                        }
                                        BrandProvider provider2 = new BrandProvider {
                                            Uri        = provider.Uri.Trim(),
                                            IconPath   = provider.IconPath,
                                            Title      = provider.Title,
                                            Commands   = provider.commandcontent,
                                            ProviderId = provider.ProviderId,
                                            Login      = "",
                                            Password   = ""
                                        };
                                        foreach (ProviderAccount account in list3)
                                        {
                                            if (account.ProviderId == provider.ProviderId)
                                            {
                                                provider2.Login    = (account != null) ? account.Login.Trim() : string.Empty;
                                                provider2.Password = (account != null) ? account.Password.Trim() : string.Empty;
                                                break;
                                            }
                                        }
                                        provider2.CommandFiles = new List <CatalogApi.Settings.CommandFile>();
                                        foreach (NewLauncher.DataContext.CommandFile file in list4)
                                        {
                                            top        = file.ProviderId;
                                            providerId = provider.ProviderId;
                                            if ((top.GetValueOrDefault() == providerId) && top.HasValue)
                                            {
                                                CatalogApi.Settings.CommandFile file2 = new CatalogApi.Settings.CommandFile {
                                                    FileName    = file.FileName,
                                                    FileContent = file.FileContent
                                                };
                                                provider2.CommandFiles.Add(file2);
                                            }
                                        }
                                        provider2.ProviderFiles = new List <CatalogApi.Settings.ProviderFile>();
                                        foreach (NewLauncher.DataContext.ProviderFile file3 in list5)
                                        {
                                            top        = file3.ProviderId;
                                            providerId = provider.ProviderId;
                                            if ((top.GetValueOrDefault() == providerId) && top.HasValue)
                                            {
                                                CatalogApi.Settings.ProviderFile file4 = new CatalogApi.Settings.ProviderFile {
                                                    FileName    = file3.FileName,
                                                    FileExt     = file3.FileExt,
                                                    FileSize    = file3.FileSize.Value,
                                                    FileContent = file3.FileContent
                                                };
                                                provider2.ProviderFiles.Add(file4);
                                            }
                                        }
                                        brand2.Providers.Add(provider2);
                                    }
                                    box2.Brands.Add(brand2);
                                }
                            }
                            item.GroupBoxs.Add(box2);
                        }
                    }
                    graph.Groups.Add(item);
                }
            }
            #endregion

            if (System.IO.File.Exists(nameFileDbSerialize) == true)
            {
                //??? никогда не выполняется
                // , если forse=true файл будет удален
                // , если forse=false произодет возврат значения и выход из функции
                System.IO.File.Delete(nameFileDbSerialize);
            }
            else
            {
                ;
            }

            Stream serializationStream = System.IO.File.Create(nameFileDbSerialize);
            new BinaryFormatter().Serialize(serializationStream, graph);
            serializationStream.Close();

            if (force == true)
            {
                this.ExtractResourcesToFolder(graph);
            }
            else
            {
                ;
            }

            return(graph);
        }
Пример #4
0
        private static void LoadUpdates()
        {
            string nameFileSettingVersion = string.Empty
            , nameFileAppVersion          = string.Empty;
            Exception exception;
            bool      fileExists = false;

            try
            {
                nameFileSettingVersion = new CatalogApi.Settings.File(ConfigurationManager.AppSettings["FileSettingVersion"]).Name;
                nameFileAppVersion     = new CatalogApi.Settings.File(ConfigurationManager.AppSettings["FileAppVersion"]).Name;

                if ((string.IsNullOrWhiteSpace(nameFileSettingVersion) == false) &&
                    (string.IsNullOrWhiteSpace(nameFileAppVersion) == false))
                {
                    using (AvtoritetEntities entities = new AvtoritetEntities())
                    {
                        //if (!(entities.Database.Connection.State == ConnectionState.Closed))
                        //{
                        Version version = new Version(entities.VersionLog.FirstOrDefault().Value)
                        , version2      = new Version(JsonConvert.DeserializeObject <VersionEntity>(IoHelper.OpenFile(nameFileAppVersion, out fileExists)).Version)
                        , version3      = new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion);

                        if (version > version2)
                        {
                            try {
                            } catch (Exception exception1) {
                                exception = exception1;
                                ErrorLogHelper.AddErrorInLog("LoadUpdates()", string.Format("{0} | {1}", exception.Message, exception.StackTrace));
                            }
                        }
                        else
                        {
                            ;
                        }

                        if (!System.IO.File.Exists(nameFileSettingVersion))
                        {
                            System.IO.File.WriteAllText(nameFileSettingVersion, "1");
                        }
                        else
                        {
                            ;
                        }

                        int?settingVersion = entities.SettingUpdate.FirstOrDefault().SettingVersion;
                        int?nullable2      = settingVersion;

                        int num  = int.Parse(System.IO.File.ReadAllText(nameFileSettingVersion));
                        int num2 = num;

                        if ((nullable2.GetValueOrDefault() > num2) &&
                            (nullable2.HasValue == true))
                        {
                            launcherSettings = new SettingsFactory(categoryEventHandler).DownloadSettings(true, true);
                            System.IO.File.WriteAllText(nameFileSettingVersion, settingVersion.ToString());
                            HaveNewUpdate = true;
                        }
                        else
                        {
                            ;
                        }
                        //}
                        //else
                        //ErrorLogHelper.AddErrorInLog("Обновление приложения - LoadUpdates() - ...", string.Format("Состояние БД={0}", entities.Database.Connection.State.ToString()));
                    }
                }
                else
                {
                    ErrorLogHelper.AddErrorInLog("Обновление приложения - LoadUpdates() - ...", string.Format("Неизвестна версия приложения или версия конфигурация БД"));
                }
                ;
            }
            catch (Exception exception2)
            {
                exception = exception2;
                ErrorLogHelper.AddErrorInLog("Обновление приложения - LoadUpdates()", string.Format("{0} | {1}", exception.Message, exception.StackTrace));
                MessageBox.Show(string.Format("{0}{1}{2}", Environment.NewLine, exception.Message, exception.StackTrace));
            }
        }