Пример #1
0
        private void SetupPhpFastCgiServer()
        {
            this.PhpFastCgiServerPort1 = NetHelper.GetRandomFreePort();
            this.PhpFastCgiServerPort2 = NetHelper.GetRandomFreePort();
            this.PhpFastCgiServerPort3 = NetHelper.GetRandomFreePort();
            this.PhpFastCgiServerPort4 = NetHelper.GetRandomFreePort();
            this.PhpFastCgiServerPort5 = NetHelper.GetRandomFreePort();
            this.PhpFastCgiServerPort6 = NetHelper.GetRandomFreePort();
            this.PhpFastCgiServerPort7 = NetHelper.GetRandomFreePort();
            this.PhpFastCgiServerPort8 = NetHelper.GetRandomFreePort();

            Dictionary <string, string> environmentVariables = null;

            if (this.UserSettings.EnableBarcodeBuddyIntegration)
            {
                environmentVariables = this.BarcodeBuddyManager.GetEnvironmentVariables();
            }

            this.PhpFastCgiServer1 = new PhpManager(GrocyDesktopDependencyManager.PhpExecutingPath, GrocyDesktopDependencyManager.PhpExecutingPath, "-b 127.0.0.1:" + this.PhpFastCgiServerPort1.ToString(), true, environmentVariables);
            this.PhpFastCgiServer1.Start();
            this.PhpFastCgiServer2 = new PhpManager(GrocyDesktopDependencyManager.PhpExecutingPath, GrocyDesktopDependencyManager.PhpExecutingPath, "-b 127.0.0.1:" + this.PhpFastCgiServerPort2.ToString(), true, environmentVariables);
            this.PhpFastCgiServer2.Start();
            this.PhpFastCgiServer3 = new PhpManager(GrocyDesktopDependencyManager.PhpExecutingPath, GrocyDesktopDependencyManager.PhpExecutingPath, "-b 127.0.0.1:" + this.PhpFastCgiServerPort3.ToString(), true, environmentVariables);
            this.PhpFastCgiServer3.Start();
            this.PhpFastCgiServer4 = new PhpManager(GrocyDesktopDependencyManager.PhpExecutingPath, GrocyDesktopDependencyManager.PhpExecutingPath, "-b 127.0.0.1:" + this.PhpFastCgiServerPort4.ToString(), true, environmentVariables);
            this.PhpFastCgiServer4.Start();
            this.PhpFastCgiServer5 = new PhpManager(GrocyDesktopDependencyManager.PhpExecutingPath, GrocyDesktopDependencyManager.PhpExecutingPath, "-b 127.0.0.1:" + this.PhpFastCgiServerPort5.ToString(), true, environmentVariables);
            this.PhpFastCgiServer5.Start();
            this.PhpFastCgiServer6 = new PhpManager(GrocyDesktopDependencyManager.PhpExecutingPath, GrocyDesktopDependencyManager.PhpExecutingPath, "-b 127.0.0.1:" + this.PhpFastCgiServerPort6.ToString(), true, environmentVariables);
            this.PhpFastCgiServer6.Start();
            this.PhpFastCgiServer7 = new PhpManager(GrocyDesktopDependencyManager.PhpExecutingPath, GrocyDesktopDependencyManager.PhpExecutingPath, "-b 127.0.0.1:" + this.PhpFastCgiServerPort7.ToString(), true, environmentVariables);
            this.PhpFastCgiServer7.Start();
            this.PhpFastCgiServer8 = new PhpManager(GrocyDesktopDependencyManager.PhpExecutingPath, GrocyDesktopDependencyManager.PhpExecutingPath, "-b 127.0.0.1:" + this.PhpFastCgiServerPort8.ToString(), true, environmentVariables);
            this.PhpFastCgiServer8.Start();
        }
Пример #2
0
        protected override async Task DownloadImplementation()
        {
            string[] roots = Directory.GetDirectories(Directory.GetCurrentDirectory() + "\\" + Properties.Settings.Default.GameDirectory);
            if (roots.Length > 1)
            {
                throw new DirectoryNotFoundException(message: string.Format("Multiple roots:\n{0}", string.Join("\n", roots)));
            }
            if (roots.Length == 0)
            {
                ShowError("There are no files inside your installation directory.");
                throw new DirectoryNotFoundException();
            }
            string root = roots[0];

            foreach (string file in oldPath)
            {
                var fileInfo = new FileInfo(root + "\\" + file);
                if (fileInfo.Exists)
                {
                    fileInfo.Delete();
                }
            }
            double n_file     = newPath.Count;
            int    downloaded = 0;

            using (var webClient = new WebClient())
            {
                foreach (string file in newPath)
                {
                    string url = this.url + file;
                    System.Diagnostics.Debug.WriteLine(file);
                    System.Diagnostics.Debug.WriteLine(root + "\\" + file.Replace("/", "\\"));
                    System.Diagnostics.Debug.WriteLine(url);
                    var fileInfo = new FileInfo(root + "\\" + file.Replace("/", "\\"));
                    if (fileInfo.Exists)
                    {
                        fileInfo.Delete();
                    }
                    if (fileInfo.Directory.Exists == false)
                    {
                        fileInfo.Directory.Create();
                    }
                    try
                    {
                        await webClient.DownloadFileTaskAsync(url, root + "\\" + file.Replace("/", "\\"));
                    }
                    catch (WebException)
                    {
                        // The file is in newPath but it has been mooved or deleted in a future commit, so it cannot be downloaded, just do nothing
                    }
                    downloaded++;
                    ShowProgress(downloaded / n_file * 100);
                }
            }
            Properties.Settings.Default.Version       = (await handler.GetLatestRelease()).Tag;
            Properties.Settings.Default.CurrentCommit = (await handler.GetLatestRelease()).Commit;
            Properties.Settings.Default.Save();
            PhpManager.UpdateVersion((await handler.GetLatestRelease()).Tag);
        }
Пример #3
0
        private void SetupBarcodeBuddy()
        {
            this.BarcodeBuddyManager = new BarcodeBuddyManager(GrocyDesktopDependencyManager.BarcodeBuddyExecutingPath, this.UserSettings.BarcodeBuddyDataLocation, this.UserSettings.BarcodeBuddyWebserverDesiredPort);
            this.BarcodeBuddyManager.Setup(this.GrocyManager.LocalUrl.TrimEnd('/') + "/api/");

            this.BarcodeBuddyWebsocketServer = new PhpManager(GrocyDesktopDependencyManager.PhpExecutingPath, GrocyDesktopDependencyManager.BarcodeBuddyExecutingPath, "wsserver.php", false);
            this.BarcodeBuddyWebsocketServer.Start();
        }
Пример #4
0
        /// <summary>
        /// It is called when the GUI is loaded. It implements the main logic of the program.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string myVer = Properties.Settings.Default.Version;

            game_version_label.Content = String.Format(Properties.Langs.Lang.game_version, myVer);
            string version = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            launcher_version_label.Content = String.Format(Properties.Langs.Lang.launcher_version, version);

            updateHandler = new UpdateHandler(this);
            Boolean isServerReachable = true;
            Boolean isToUpdate;

            try
            {
                isToUpdate = await updateHandler.CheckUpdateAvailability();
            }
            catch (Exception ex)
            {
                isServerReachable = false;
                isToUpdate        = false;
                PhpManager.ReportError("updateHandler.CheckUpdateAvailability(); raised an Exception:\n" + ex.Message);
            }
            await MainLogic(isToUpdate, isServerReachable, myVer);

            //Loads all images in the current directory into a list
            DirectoryInfo dir_info = new DirectoryInfo(Environment.CurrentDirectory + "/Resources");

            foreach (FileInfo file_info in dir_info.GetFiles())
            {
                if ((file_info.Extension.ToLower() == ".jpg") ||
                    (file_info.Extension.ToLower() == ".png"))
                {
                    Images.Add(new BitmapImage(new Uri(file_info.FullName)));
                }
            }

            // Sets first image as source for bg
            bg.Source = Images[0];
            BottomBarBg.ImageSource = Images[0];
            TopBarBg.ImageSource    = Images[0];

            //Initializing Timer for slideshow
            PictureTimer.Interval = TimeSpan.FromSeconds(10);
            PictureTimer.Tick    += Tick;
            PictureTimer.Start();

            //Initializing the update timer
            UpdateTimer.Interval = TimeSpan.FromMilliseconds(10);
            UpdateTimer.Tick    += Update;
            UpdateTimer.Start();

            InitSaveButtons();
            id_label.Content = "ID: " + Properties.Settings.Default.ID;

            //Hide splash
            splash.Visibility = Visibility.Hidden;
        }
Пример #5
0
 /// <summary>
 /// This method is called when the program starts.<br/>
 /// It checks if the user has an ID assigned, if not it try to get a new ID from the database and assign it to the user.<br/>
 /// Then check if there are fonts to be installed and, if it is the case, installs them.<br/>
 /// Finally, initialise the GUI.
 /// </summary>
 public MainWindow()
 {
     ServicePointManager.Expect100Continue = true;
     ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;
     if (Properties.Settings.Default.ID == -1)
     {
         Properties.Settings.Default.ID = PhpManager.GetID(Properties.Settings.Default.Version);
         Properties.Settings.Default.Save();
     }
     InitializeComponent();
 }
Пример #6
0
 private void DownloadCommitInfoEventHandler(object sender, DownloadStringCompletedEventArgs e)
 {
     if (e.Error != null)
     {
         //TODO: show error on label
         PhpManager.ReportError(e.Error.Message);
     }
     else
     {
         Infos = JsonConvert.DeserializeObject(e.Result.ToString());
     }
 }
Пример #7
0
        /// <summary>
        /// Search for program executable and launch it.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LaunchGame(object sender, RoutedEventArgs e)
        {
            var     executable = Properties.Resources.Executable;
            Process process    = new Process();

            foreach (string f in Directory.EnumerateFiles(Directory.GetCurrentDirectory() + "\\" + FILE_NAME, executable, SearchOption.AllDirectories))
            {
                process.StartInfo.FileName = f;
                process.Start();
                PhpManager.UpdateVersion(Properties.Settings.Default.Version);
                CloseWindow(sender, e);
                return;
            }
            PhpManager.ReportError(String.Format("{0} not found in {1}", executable, Directory.GetCurrentDirectory() + "\\" + FILE_NAME));
            MessageBox.Show(String.Format(Properties.Langs.Lang.exe_not_found, executable), Properties.Langs.Lang.warning);
        }
Пример #8
0
        /// <summary>
        /// Template method that only handle exceptions and do some simples GUI changes.<br/>
        /// Real Download implementation is delegated to sublasses that must implement the abstract method <see cref="DownloadImplementation"/>.
        /// </summary>
        /// <returns></returns>
        public async Task Download()
        {

            try
            {
                await DownloadImplementation();
            }
            catch (Exception ex)
            {
                window.infoLabel.Content = String.Format(Properties.Langs.Lang.unable_download, ex.Message);
                PhpManager.ReportError(String.Format("Error in {0}.DownloadImplementation: {1}", GetType().Name, ex.Message));
                window.UpdateBarProgress(0);
                return;
            }
            window.infoLabel.Content = Properties.Langs.Lang.download_completed;
        }
Пример #9
0
 /// <summary>
 /// Unzip a file and show progress in <see cref="BarGrid"/>.
 /// </summary>
 /// <param name="zipPath">Archive to uzip's full path.</param>
 private async void Unzip(string zipPath)
 {
     try
     {
         string extractedDirectory = zipPath.Replace(".zip", "");
         using (ZipFile zip = ZipFile.Read(zipPath))
         {
             int totalFiles     = zip.Count;
             int filesExtracted = 0;
             foreach (ZipEntry d in zip)
             {
                 Debug.WriteLine(d.FileName);
                 d.Extract(extractedDirectory);
                 filesExtracted++;
                 float progress = (float)filesExtracted / totalFiles * 100;
                 this.Dispatcher.Invoke(() =>
                 {
                     this.infoLabel.Content = String.Format(Properties.Langs.Lang.installation_ip, progress);
                     UpdateBarProgress(progress);
                 });
             }
         }
         Properties.Settings.Default.Version       = (await updateHandler.GetLatestRelease()).Tag;
         Properties.Settings.Default.CurrentCommit = (await updateHandler.GetLatestRelease()).Commit;
         Properties.Settings.Default.Save();
         this.Dispatcher.Invoke(() =>
         {
             InitPlayButton();
         });
     }
     catch (Exception ex)
     {
         this.infoLabel.Content        = String.Format(Properties.Langs.Lang.installation_error, ex.Message);
         this.button.IsEnabled         = false;
         this.recoveryButton.IsEnabled = true;
         UpdateBarProgress(0);
         PhpManager.ReportError(String.Format("Error in MainWindow.Unzip({0}): {1}", zipPath, ex.Message));
     }
 }