Example #1
0
 private BitmapSource LoadIcon()
 {
     try
     {
         using (var context = new DatabaseContext())
         {
             VnUserData userData = context.VnUserData.FirstOrDefault(v => v.VnId == Globals.VnId);
             if (userData != null && Directory.Exists(userData.ExePath))
             {
                 //checks for existance of Iconpath first, then ExePath. If both are null/empty, it returns a null image
                 return(!string.IsNullOrEmpty(userData.IconPath) ? CreateIcon(userData.IconPath) : CreateIcon(!string.IsNullOrEmpty(userData.ExePath) ? userData.ExePath : null));
             }
         }
         return(null);
     }
     catch (Exception ex)
     {
         Globals.Logger.Error(ex);
         throw;
     }
 }
Example #2
0
        private void StartVn()
        {
            try
            {
                if (Globals.VnId < 1)
                {
                    return;
                }
                if (_isGameRunning)
                {
                    Messenger.Default.Send(new NotificationMessage("Game Already Running"));
                }
                if (_isGameRunning == false)
                {
                    _stopwatch.Reset();
                    Process process = null;
                    using (var context = new DatabaseContext())
                    {
                        VnInfo     idList     = context.VnInfo.FirstOrDefault(x => x.Title.Equals(_selectedVn));
                        VnUserData vnUserData = context.VnUserData.FirstOrDefault(x => x.VnId.Equals(idList.VnId));
                        if (vnUserData?.ExePath != null && Directory.Exists(vnUserData?.ExePath))
                        {
                            string exepath = vnUserData.ExePath;
                            string dirpath = Path.GetDirectoryName(exepath);
                            if (dirpath != null)
                            {
                                Directory.SetCurrentDirectory(dirpath);
                            }
                            process = new Process
                            {
                                StartInfo =
                                {
                                    FileName = exepath, UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true
                                },
                                EnableRaisingEvents = true
                            };
                            _processList.Add(process);
                            process.Start();
                            _isGameRunning = true;
                            _stopwatch.Start();
                            IsPlayEnabled = false;
                        }
                    }
                    Directory.SetCurrentDirectory(Directory.GetCurrentDirectory());
                    List <Process> children = process.GetChildProcesses();
                    _processList.AddRange(children);
                    int initialChildrenCount = children.Count;
                    if (process != null)
                    {
                        process.EnableRaisingEvents = true;
                        process.Exited += delegate(object o, EventArgs args)
                        {
                            //Only allows the HasExited event to trigger when there are no child processes
                            if (children.Count < 1 && initialChildrenCount == 0)
                            {
                                _stopwatch.Stop();
                                VnOrChildProcessExited(null, null);
                            }
                        };
                    }

                    foreach (Process proc in children)
                    {
                        proc.EnableRaisingEvents = true;
                        proc.Exited += VnOrChildProcessExited;
                    }
                }
            }
            catch (Exception exception)
            {
                Globals.Logger.Error(exception);
                throw;
            }
        }