private void HandleLoading(
     ExplorerModel model,
     IList <MessageModel> messageModels)
 {
     //Console.WriteLine("End next");
     model.SourceItems.AddRange(messageModels);
 }
 public MainWindow()
 {
     InitializeComponent();
     var serviceLocator = this.FindResource<ModelServiceLocator>("serviceLocator");
     this.model = serviceLocator.ExplorerModel;
     this.model.ErrorOccurred += errorOccurred;
 }
Exemple #3
0
        public ExplorerModel Index(string realpath = "")
        {
            ExplorerModel explorerModel;

            if (string.IsNullOrEmpty(realpath))
            {
                IEnumerable <string> drivesList      = Environment.GetLogicalDrives();
                List <DirModel>      drivesListModel = drivesList.Select(drive => new DirModel {
                    DirName = drive
                }).ToList();
                explorerModel = new ExplorerModel(drivesListModel, null, realpath);
            }
            else
            {
                IEnumerable <string> dirList = Directory.EnumerateDirectories(realpath);

                List <DirModel> dirListModel = (from dir in dirList let d = new DirectoryInfo(dir) select new DirModel {
                    DirName = Path.GetFileName(dir)
                }).ToList();

                IEnumerable <string> fileList      = Directory.EnumerateFiles(realpath);
                List <FileModel>     fileListModel =
                    (from file in fileList
                     let f = new FileInfo(file)
                             select new FileModel
                {
                    Name = Path.GetFileName(file),
                    FileSize = (f.Length < 1024) ? f.Length : (double)f.Length / 1024
                }).ToList();

                explorerModel = new ExplorerModel(dirListModel, fileListModel, realpath);
            }

            return(explorerModel);
        }
        private void HandleLoading(
            ExplorerModel model,
            Chat chat,
            IList <MessageModel> messageModels)
        {
            //Console.WriteLine("End prev");

            ItemModel targetItem = null;

            // find item which is currently visible to scroll to it later
            if (model.SourceItems.Count > 0)
            {
                targetItem = model.SourceItems.Items
                             .Skip(model.VisibleRange.Index)
                             .OfType <MessageModel>()
                             .FirstOrDefault();
            }

            // or take last added item
            if (targetItem == null && messageModels.Count > 0)
            {
                targetItem = messageModels[messageModels.Count - 1];
            }

            model.TargetItem = targetItem;
            model.SourceItems.InsertRange(messageModels, 0);
        }
        public ActionResult Index()
        {
            var model = new ExplorerModel();

            model.Load(AirportBusinessService);

            return(View("Explorer", model));
        }
Exemple #6
0
        public MainWindow()
        {
            InitializeComponent();
            var serviceLocator = this.FindResource <ModelServiceLocator>("serviceLocator");

            this.model = serviceLocator.ExplorerModel;
            this.model.ErrorOccurred += errorOccurred;
        }
Exemple #7
0
        public virtual void Dispose()
        {
            InformerModel?.Dispose();
            CatalogModel?.Dispose();
            ExplorerModel?.Dispose();
            EditorModel?.Dispose();

            _modelDisposable.Dispose();
        }
Exemple #8
0
        private IDisposable BindExplorer()
        {
            Model.ExplorerModel = ExplorerModel.Hidden();

            return(SubscribeToTarget(target =>
            {
                _explorerActivator.Deactivate(ref _explorerController);
                var model = _explorerActivator.Activate(target, ref _explorerController);
                Model.ExplorerModel = model;
            }));
        }
Exemple #9
0
 public IDisposable Bind(
     ExplorerModel model,
     Chat chat)
 {
     return(model.WhenAnyValue(m => m.VisibleRange)
            .Where(r => model.SourceItems.Count == 0) // only initial
            .Where(r => !_conductor.IsBusy)           // ignore if other load are already in progress
            .Synchronize(_conductor.Locker)
            .SelectSeq(r => StartLoading(chat))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Accept(list => HandleLoading(model, chat, list)));
 }
Exemple #10
0
        private ExplorerModel GetExplorerModel(string realPath)
        {
            var dirListModel  = directoryService.GetAllDirectories(realPath).Select(d => d.ToMvcDirectory());
            var fileListModel = fileService.GetAllFiles(realPath).Select(f => f.ToMvcFile());

            var explorerModel = new ExplorerModel
            {
                Directories = dirListModel,
                Files       = fileListModel
            };

            return(explorerModel);
        }
        /// <summary>
        /// Instantiation of ExplorerViewModel
        /// </summary>
        public ExplorerViewModel()
        {
            Model = new ExplorerModel();

            if (MacroUI.GetInstance().IsLoaded())
            {
                Initialize();
            }
            else
            {
                Events.SubscribeEvent("ApplicationLoaded", (Action)Initialize);
            }
            //Routing.EventManager.ApplicationLoadedEvent += Initialize;
        }
 public IDisposable Bind(
     ExplorerModel model,
     Chat chat)
 {
     return(model.WhenAnyValue(m => m.VisibleRange)
            .Throttle(TimeSpan.FromSeconds(1))
            .Select(r => r.LastIndex)
            .DistinctUntilChanged()
            .Where(index => model.SourceItems.Count != 0)        // skip initial
            .Where(index => index + 4 > model.SourceItems.Count) // bottom is within 4 items
            .Where(index => !_conductor.IsBusy)                  // ignore if other load are already in progress
            .Synchronize(_conductor.Locker)
            .SelectSeq(r => StartLoading(model, chat))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Accept(list => HandleLoading(model, list)));
 }
Exemple #13
0
        public ExplorerModelVM GetExplorerModel(string path, Uri requestURL, int?homeworkID = null)
        {
            ExplorerModel model = manager.GetExplorerModel(path, requestURL);

            ExplorerModelVM vm = new ExplorerModelVM();

            vm.dirModelList = new List <Models.DirModel>();
            foreach (ServiceHelpers.Model.DirModel item in model.dirModelList)
            {
                if (homeworkID != null)
                {
                    vm.dirModelList.Add(
                        new BusinessLayer.Models.DirModel()
                    {
                        DirAccessed = item.DirAccessed,
                        DirName     = item.DirName,
                        Deadline    = homeworkRepository.GetHomework((int)homeworkID).Deadline
                    });
                }
                else
                {
                    vm.dirModelList.Add(
                        new BusinessLayer.Models.DirModel()
                    {
                        DirAccessed = item.DirAccessed,
                        DirName     = item.DirName,
                        Deadline    = homeworkRepository.GetHomework(Convert.ToInt32(item.DirName.Split('_')[1])).Deadline
                    });
                }
            }

            vm.fileModelList = new List <Models.FileModel>();
            foreach (ServiceHelpers.Model.FileModel item in model.fileModelList)
            {
                vm.fileModelList.Add(new BusinessLayer.Models.FileModel()
                {
                    FileAccessed = item.FileAccessed,
                    FileName     = item.FileName,
                    FileSizeText = item.FileSizeText
                });
            }

            vm.isFile = model.isFile;

            return(vm);
        }
Exemple #14
0
        private void HandleLoading(
            ExplorerModel model,
            Chat chat,
            IList <MessageModel> messageModels)
        {
            //Console.WriteLine("End init");

            // find last read message to scroll to it later
            var targetItem = messageModels
                             .FirstOrDefault(m => m.Message.MessageData.Id == chat.ChatData.LastReadInboxMessageId);

            if (targetItem == null && messageModels.Count > 0)
            {
                targetItem = messageModels[messageModels.Count / 2];
            }

            model.SourceItems.AddRange(messageModels);
            model.TargetItem = targetItem;
        }
        private IObservable <IList <MessageModel> > StartLoading(
            ExplorerModel model,
            Chat chat)
        {
            //Console.WriteLine("Start next: {0}", Thread.CurrentThread.ManagedThreadId);
            _conductor.IsBusy = true;

            var fromMessage = model.SourceItems.Items
                              .OfType <MessageModel>()
                              .Last()
                              .Message;

            return(LoadNextMessages(chat, fromMessage)
                   .ObserveOn(RxApp.TaskpoolScheduler)
                   .SubscribeOn(RxApp.MainThreadScheduler)
                   .Finally(() =>
            {
                _conductor.IsBusy = false;
            }));;
        }
Exemple #16
0
        private IDisposable BindExplorer(IFactory <Target, ExplorerModel> explorerModelFactory)
        {
            var chatSubscription = SubscribeToSelectedChat(chat =>
            {
                ExplorerModel?.Dispose();
                ExplorerModel = explorerModelFactory.Create(chat);
            });

            var aggregateSubscription = SubscribeToSelectedAggregate(aggregate =>
            {
                ExplorerModel?.Dispose();
                ExplorerModel = explorerModelFactory.Create(aggregate);
            });

            return(Disposable.Create(() =>
            {
                chatSubscription.Dispose();
                aggregateSubscription.Dispose();
            }));
        }
Exemple #17
0
        public ActionResult ExploreFiles()
        {
            int subjectID   = Convert.ToInt32(Session["choosenSubject"]);
            var subjectName = db.Przedmioty.Find(subjectID).nazwa;

            ViewBag.subjectName = subjectName;

            string realPath = Server.MapPath("~/Files/" + subjectName);

            if (Directory.Exists(realPath))
            {
                List <FileModel> fileListModel = new List <FileModel>();

                IEnumerable <string> fileList = Directory.EnumerateFiles(realPath);

                foreach (string file in fileList)
                {
                    FileInfo f = new FileInfo(file);

                    FileModel fileModel = new FileModel();

                    if (f.Extension.ToLower() != "aspx" && f.Extension.ToLower() != "asp")
                    {
                        fileModel.FileName     = Path.GetFileName(file);
                        fileModel.FileAccessed = f.LastAccessTime;
                        fileModel.FileSizeText = (f.Length < 1024) ? f.Length.ToString() + " B" : f.Length / 1024 + " KB";

                        fileListModel.Add(fileModel);
                    }
                }

                ExplorerModel explorerModel = new ExplorerModel(fileListModel);

                return(View(explorerModel));
            }
            else
            {
                return(Content("Nie można otworzyć zasobu"));
            }
        }
        public static IDisposable BindExplorer(this MessengerModel model)
        {
            model.ExplorerModel = ExplorerModel.Hidden();

            return(model.SubscribeToSelection(entry =>
            {
                switch (entry)
                {
                case ChatEntryModel chatEntryModel:
                    model.ExplorerModel = new ExplorerModel(chatEntryModel.Chat);
                    break;

                case AggregateEntryModel aggregateEntryModel:
                    //model.ExplorerModel = new ExplorerModel(aggregateEntryModel.Aggregate);
                    break;

                case HomeEntryModel _:
                    model.ExplorerModel = ExplorerModel.Hidden();
                    break;
                }
            }));
        }
Exemple #19
0
        public ActionResult downFile(string path)
        {
            string strFileName = "";

            //For test
            //Session["userid"] = mUsrTest;
            //Session["pass"] = mPwd;
            path = path.Replace("aabbccddee", ":");
            path = path.Replace("asdfghjkl", "/");
            path = path.Replace("aqwsedrf", "+");
            path = HttpUtility.UrlDecode(path);
            int iIndex = path.IndexOf('/');

            if (iIndex > -1)
            {
                path = path.Substring(iIndex + 1);

                iIndex = path.IndexOf('/');

                if (iIndex == 0)
                {
                    path = path.TrimStart('/');
                }

                int iLastIndex = path.LastIndexOf('/');
                if (iLastIndex > -1)
                {
                    strFileName = path.Substring(iLastIndex + 1);
                }


                path = "ftp://" + path;
            }


            //http://stackoverflow.com/questions/1176022/unknown-file-type-mime
            //return base.File(ftpPath, "application/octet-stream");

            //LARGE FILE
            try
            {
                FtpWebRequest request = (FtpWebRequest)WebRequest.Create(path);
                request.KeepAlive   = true;
                request.UsePassive  = true;
                request.UseBinary   = true;
                request.Method      = WebRequestMethods.Ftp.DownloadFile;
                request.Credentials = new NetworkCredential(ftpaccount, ftppass);
                FtpWebResponse ftpResponse = (FtpWebResponse)request.GetResponse();

                //LARGE FILE

                // **************************************************
                Response.Buffer = false;

                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName);

                // **************************************************
                // 8KB

                //---------------------------------------------------
                long lngFileLength = GetFTPFileSize(path, ftpaccount, ftppass);
                Response.AddHeader("Content-Length", lngFileLength.ToString());

                using (Stream responseStream = ftpResponse.GetResponseStream())
                {
                    int intBufferSize = 8 * 1024;

                    // Create buffer for reading [intBufferSize] bytes from file
                    byte[] bytBuffers = new System.Byte[intBufferSize];

                    // Total bytes that should be read
                    long lngDataToRead = lngFileLength;

                    // Read the bytes of file
                    while (lngDataToRead > 0)
                    {
                        // Verify that the client is connected or not?
                        if (Response.IsClientConnected)
                        {
                            // Read the data and put it in the buffer.
                            int intTheBytesThatReallyHasBeenReadFromTheStream =
                                responseStream.Read(buffer: bytBuffers, offset: 0, count: intBufferSize);

                            // Write the data from buffer to the current output stream.
                            Response.OutputStream.Write(buffer: bytBuffers, offset: 0, count: intTheBytesThatReallyHasBeenReadFromTheStream);

                            // Flush (Send) the data to output
                            // (Don't buffer in server's RAM!)
                            Response.Flush();

                            lngDataToRead =
                                lngDataToRead - intTheBytesThatReallyHasBeenReadFromTheStream;
                        }
                        else
                        {
                            // Prevent infinite loop if user disconnected!
                            lngDataToRead = -1;
                        }
                    }

                    if (responseStream != null)
                    {
                        //Close the file.
                        responseStream.Close();
                        responseStream.Dispose();
                    }
                }

                //END LARGER FILE
            }
            catch (WebException we)
            {
                FtpWebResponse response = (FtpWebResponse)we.Response;
                return(Content("Lỗi: " + response.StatusDescription));
            }
            catch (Exception ex)
            {
                return(Content("Lỗi không đọc được file: " + ex.Message + " !"));
            }
            finally
            {
                //Response.Close();
                //nen dung
                this.HttpContext.ApplicationInstance.CompleteRequest();
            }
            //END LARGER FILE


            List <DirModel>  dirModels  = new List <DirModel>();
            List <FileModel> fileModels = new List <FileModel>();

            ExplorerModel explorerModel = new ExplorerModel(dirModels, fileModels);

            return(View(explorerModel));
        }
Exemple #20
0
        public ActionResult Index(string path)
        {
            bool upload = false;

            ViewBag.ftp = ftpPath;
            phongban    = Session["phongban"].ToString();
            username    = Session["username"].ToString().Replace(".", "");
            chinhanh    = Session["chinhanh"].ToString();
            string[] a = Session["username"].ToString().Split('.');
            username         = a[0].ToString();
            ViewBag.username = username;


            if (String.IsNullOrEmpty(path))
            {
                path = ftpPath + chinhanh + "/USERS/" + username;
                // path = ftpPath + chinhanh + "/" + phongban;
            }

            //else
            //{
            //    path = ftpPath + path;
            //}
            //ViewBag.home = path;// ftpPath+path;// + "Khanh";// phongban;
            ExplorerModel explorerModel = new ExplorerModel();

            path = HttpUtility.UrlDecode(path);
            path = path.Replace("aabbccddee", ":");
            path = path.Replace("asdfghjkl", "/");
            path = path.Replace("aqwsedrf", "+");

            ViewBag.home = path.Replace("ftp://intranet.appsgt.net:4200/", "");
            upload       = bool.Parse(Session["upload"].ToString());
            if (upload)
            {
                string duongdan = ViewBag.home;
                if (duongdan.Contains(chinhanh) && duongdan.Contains(phongban))
                {
                    upload = true;
                }
                else
                {
                    upload = false;
                }
            }
            ViewBag.upload = upload;
            ViewBag.path   = path;

            int iIndex = path.IndexOf('/');

            if (iIndex > -1)
            {
                path = path.Substring(iIndex + 1);

                iIndex = path.IndexOf('/');

                if (iIndex == 0)
                {
                    path = path.TrimStart('/');
                }

                path = "ftp://" + path;
            }

            string sFlagUrl = "~/Content/image/folder-close-icon48.png";

            Session["sUncPath"] = path;
            List <DirModel>  dirModels  = new List <DirModel>();
            List <FileModel> fileModels = new List <FileModel>();

            string[] dirs = GetDirectoryListing(path, ftpaccount, ftppass);
            string   sTmp = "";

            foreach (string d in dirs)
            {
                sTmp = d;
                // bo dau /
                if (sTmp.StartsWith("/"))
                {
                    sTmp = sTmp.TrimStart('/');
                }
                // bo cac ten file
                if (d.IndexOf('.') == -1)
                {
                    // get dir
                    DirModel dd = new DirModel();
                    dd.DirName     = sTmp;
                    dd.DirAccessed = DateTime.Now;
                    dd.FullDirName = path + "/" + sTmp;
                    dd.FlagUrl     = sFlagUrl;
                    dirModels.Add(dd);
                }
                else
                {
                    // get file extension
                    int    indexExt    = sTmp.LastIndexOf('.');
                    string sExt        = sTmp.Substring(indexExt + 1);
                    long   lFileLenght = GetFTPFileSize(path + "/" + sTmp, ftpaccount, ftppass);
                    if (allowDisplay.Contains(sExt.ToLower()))
                    {
                        FileModel ff = new FileModel();
                        ff.FileName = sTmp;

                        ff.FileAccessed = DateTime.Now;
                        ff.FileSizeText = (lFileLenght < 1024) ? lFileLenght.ToString() + " B" : String.Format("{0:0,0}", (lFileLenght / 1024)) + " KB";
                        //ff.FileSizeText = GetSizeString(lFileLenght);
                        ff.FileExt       = sExt;
                        ff.ParentFileDir = path;
                        fileModels.Add(ff);
                    }
                }
            }
            explorerModel = new ExplorerModel(dirModels, fileModels);
            return(View(explorerModel));
        }
        public bool Load(string[] args)
        {
            // Fetch the game version and store, so it can be retrieved during crash if the toolbox makes it this far.
            GlobalSettings.Default.SEVersion = SpaceEngineersConsts.GetSEVersion();

            // Test the Space Engineers version to make sure users are using an version that is new enough for SEToolbox to run with!
            // This is usually because a user has not updated a manual install of a Dedicated Server, or their Steam did not update properly.
            if (GlobalSettings.Default.SEVersion < GlobalSettings.GetAppVersion(true))
            {
                MessageBox.Show(string.Format(Res.DialogOldSEVersionMessage, SpaceEngineersConsts.GetSEVersion(), GlobalSettings.Default.SEBinPath, GlobalSettings.GetAppVersion()), Res.DialogOldSEVersionTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                Application.Current.Shutdown();
                return(false);
            }

            //string loadWorld = null;

            //foreach (var arg in args)
            //{
            //    if (arg.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 && !File.Exists(arg))
            //        continue;

            //    string file = Path.GetFileName(arg);
            //    if (file.Equals("Sandbox.sbc", StringComparison.InvariantCultureIgnoreCase)
            //        || file.Equals("SANDBOX_0_0_0_.sbs", StringComparison.InvariantCultureIgnoreCase))
            //        loadWorld = Path.GetDirectoryName(arg);
            //}

            // Force pre-loading of any Space Engineers resources.
            SpaceEngineersCore.LoadDefinitions();

            // Load the Space Engineers assemblies, or dependant classes after this point.
            var explorerModel = new ExplorerModel();

            if (args.Any(a => a.ToUpper() == "/WR" || a.ToUpper() == "-WR"))
            {
                ResourceReportModel.GenerateOfflineReport(explorerModel, args);
                Application.Current.Shutdown();
                return(false);
            }

            var eViewModel = new ExplorerViewModel(explorerModel);
            var eWindow    = new WindowExplorer(eViewModel);

            //if (allowClose)
            //{
            eViewModel.CloseRequested += (sender, e) =>
            {
                SaveSettings(eWindow);
                Application.Current.Shutdown();
            };
            //}
            eWindow.Loaded += (sender, e) =>
            {
                Splasher.CloseSplash();
                if (GlobalSettings.Default.WindowLeft.HasValue)
                {
                    eWindow.Left = GlobalSettings.Default.WindowLeft.Value;
                }
                if (GlobalSettings.Default.WindowTop.HasValue)
                {
                    eWindow.Top = GlobalSettings.Default.WindowTop.Value;
                }
                if (GlobalSettings.Default.WindowWidth.HasValue)
                {
                    eWindow.Width = GlobalSettings.Default.WindowWidth.Value;
                }
                if (GlobalSettings.Default.WindowHeight.HasValue)
                {
                    eWindow.Height = GlobalSettings.Default.WindowHeight.Value;
                }
                if (GlobalSettings.Default.WindowState.HasValue)
                {
                    eWindow.WindowState = GlobalSettings.Default.WindowState.Value;
                }
            };
            eWindow.ShowDialog();

            return(true);
        }
Exemple #22
0
        public ExplorerModel GetExplorerModel(string path, Uri requestURL)
        {
            string realPath;

            realPath = path;
            // or realPath = "FullPath of the folder on server"

            ExplorerModel explorerModel = new ExplorerModel();

            if (System.IO.File.Exists(realPath))
            {
                //http://stackoverflow.com/questions/1176022/unknown-file-type-mime
                explorerModel.isFile = true;
                return(explorerModel);
            }
            else if (System.IO.Directory.Exists(realPath))
            {
                List <FileModel> fileListModel = new List <FileModel>();

                List <DirModel> dirListModel = new List <DirModel>();

                IEnumerable <string> dirList = Directory.EnumerateDirectories(realPath);
                foreach (string dir in dirList)
                {
                    DirectoryInfo d = new DirectoryInfo(dir);

                    DirModel dirModel = new DirModel();

                    dirModel.DirName     = Path.GetFileName(dir);
                    dirModel.DirAccessed = d.LastAccessTime;

                    dirListModel.Add(dirModel);
                }

                IEnumerable <string> fileList = Directory.EnumerateFiles(realPath);
                foreach (string file in fileList)
                {
                    FileInfo f = new FileInfo(file);

                    FileModel fileModel = new FileModel();

                    if (f.Extension.ToLower() != "php" && f.Extension.ToLower() != "aspx" &&
                        f.Extension.ToLower() != "asp")
                    {
                        fileModel.FileName     = Path.GetFileName(file);
                        fileModel.FileAccessed = f.LastAccessTime;
                        fileModel.FileSizeText = (f.Length < 1024) ? f.Length.ToString() + " B" : f.Length / 1024 + " KB";

                        fileListModel.Add(fileModel);
                    }
                }

                explorerModel        = new ExplorerModel(dirListModel, fileListModel);
                explorerModel.isFile = false;

                return(explorerModel);
            }
            else
            {
                return(new ExplorerModel());
            }
        }
 private void OnLoaded(object sender, RoutedEventArgs e)
 {
     explorerModel            = new ExplorerModel();
     DirectoryBox.Text        = Environment.CurrentDirectory;
     ExplorerTree.ItemsSource = explorerModel.Model.Items;
 }
Exemple #24
0
        public bool Load(string[] args)
        {
            // Fetch the game version and store, so it can be retrieved during crash if the toolbox makes it this far.
            Version gameVersion = SpaceEngineersConsts.GetSEVersion();
            bool    newVersion  = GlobalSettings.Default.SEVersion != gameVersion;

            GlobalSettings.Default.SEVersion = gameVersion;

            // Test the Space Engineers version to make sure users are using an version that is new enough for SEToolbox to run with!
            // This is usually because a user has not updated a manual install of a Dedicated Server, or their Steam did not update properly.
            if (GlobalSettings.Default.SEVersion < GlobalSettings.GetAppVersion(true))
            {
                MessageBox.Show(string.Format(Res.DialogOldSEVersionMessage, SpaceEngineersConsts.GetSEVersion(), GlobalSettings.Default.SEBinPath, GlobalSettings.GetAppVersion()), Res.DialogOldSEVersionTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                Application.Current.Shutdown();
                return(false);
            }

            // the /B argument indicates the SEToolboxUpdate had started SEToolbox after fetching updated game binaries.
            if (newVersion && args.Any(a => a.Equals("/B", StringComparison.OrdinalIgnoreCase) || a.Equals("-B", StringComparison.OrdinalIgnoreCase)))
            {
                // Reset the counter used to indicate if the game binaries have updated.
                GlobalSettings.Default.TimesStartedLastGameUpdate = null;
            }

            //string loadWorld = null;

            //foreach (var arg in args)
            //{
            //    if (arg.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0 && !File.Exists(arg))
            //        continue;

            //    string file = Path.GetFileName(arg);
            //    if (file.Equals("Sandbox.sbc", StringComparison.InvariantCultureIgnoreCase)
            //        || file.Equals("SANDBOX_0_0_0_.sbs", StringComparison.InvariantCultureIgnoreCase))
            //        loadWorld = Path.GetDirectoryName(arg);
            //}

            // Force pre-loading of any Space Engineers resources.
            SpaceEngineersCore.LoadDefinitions();

            // Load the Space Engineers assemblies, or dependant classes after this point.
            var explorerModel = new ExplorerModel();

            if (args.Any(a => a.ToUpper() == "/WR" || a.ToUpper() == "-WR"))
            {
                ResourceReportModel.GenerateOfflineReport(explorerModel, args);
                Application.Current.Shutdown();
                return(false);
            }

            var eViewModel = new ExplorerViewModel(explorerModel);
            var eWindow    = new WindowExplorer(eViewModel);

            //if (allowClose)
            //{
            eViewModel.CloseRequested += (sender, e) =>
            {
                SaveSettings(eWindow);
                Application.Current.Shutdown();
            };
            //}
            eWindow.Loaded += (sender, e) =>
            {
                Splasher.CloseSplash();

                double left   = GlobalSettings.Default.WindowLeft ?? eWindow.Left;
                double top    = GlobalSettings.Default.WindowTop ?? eWindow.Top;
                double width  = GlobalSettings.Default.WindowWidth ?? eWindow.Width;
                double height = GlobalSettings.Default.WindowHeight ?? eWindow.Height;

                System.Drawing.Rectangle windowRect = new System.Drawing.Rectangle((int)left, (int)top, (int)width, (int)height);
                bool isInsideDesktop = false;

                foreach (System.Windows.Forms.Screen screen in System.Windows.Forms.Screen.AllScreens)
                {
                    try
                    {
                        isInsideDesktop |= screen.Bounds.IntersectsWith(windowRect);
                    }
                    catch
                    {
                        // some virtual screens have been know to cause issues.
                    }
                }
                if (isInsideDesktop)
                {
                    eWindow.Left   = left;
                    eWindow.Top    = top;
                    eWindow.Width  = width;
                    eWindow.Height = height;
                    if (GlobalSettings.Default.WindowState.HasValue)
                    {
                        eWindow.WindowState = GlobalSettings.Default.WindowState.Value;
                    }
                }
            };

            if (!GlobalSettings.Default.TimesStartedTotal.HasValue)
            {
                GlobalSettings.Default.TimesStartedTotal = 0;
            }
            GlobalSettings.Default.TimesStartedTotal++;
            if (!GlobalSettings.Default.TimesStartedLastReset.HasValue)
            {
                GlobalSettings.Default.TimesStartedLastReset = 0;
            }
            GlobalSettings.Default.TimesStartedLastReset++;
            if (!GlobalSettings.Default.TimesStartedLastGameUpdate.HasValue)
            {
                GlobalSettings.Default.TimesStartedLastGameUpdate = 0;
            }
            GlobalSettings.Default.TimesStartedLastGameUpdate++;
            GlobalSettings.Default.Save();

            eWindow.ShowDialog();

            return(true);
        }
Exemple #25
0
        public ActionResult WeeklyDownloads(string path)
        {
            string realPath;

            realPath = Server.MapPath("~/WeeklyLogbooks/" + path);
            // or realPath = "FullPath of the folder on server"

            if (System.IO.File.Exists(realPath))
            {
                //http://stackoverflow.com/questions/1176022/unknown-file-type-mime
                return(base.File(realPath, "application/octet-stream"));
            }
            else if (System.IO.Directory.Exists(realPath))
            {
                Uri url = Request.Url;
                //Every path needs to end with slash
                if (url.ToString().Last() != '/')
                {
                    Response.Redirect("/Weekly/" + path + "/");
                }

                List <DirModel> dirListModel = new List <DirModel>();

                IEnumerable <string> dirList = Directory.EnumerateDirectories(realPath);
                foreach (string dir in dirList)
                {
                    DirectoryInfo d = new DirectoryInfo(dir);

                    DirModel dirModel = new DirModel();

                    dirModel.DirName     = Path.GetFileName(dir);
                    dirModel.DirAccessed = d.LastAccessTime;

                    dirListModel.Add(dirModel);
                }


                List <FileModel> fileListModel = new List <FileModel>();

                IEnumerable <string> fileList = Directory.EnumerateFiles(realPath);
                foreach (string file in fileList)
                {
                    FileInfo f = new FileInfo(file);

                    FileModel fileModel = new FileModel();

                    if (f.Extension.ToLower() != "php" && f.Extension.ToLower() != "aspx" &&
                        f.Extension.ToLower() != "asp")
                    {
                        fileModel.FileName     = Path.GetFileName(file);
                        fileModel.FileAccessed = f.LastAccessTime;
                        fileModel.FileSizeText = (f.Length < 1024) ? f.Length.ToString() + " B" : f.Length / 1024 + " KB";

                        fileListModel.Add(fileModel);
                    }
                }

                ExplorerModel explorerModel = new ExplorerModel(dirListModel, fileListModel);

                return(View(explorerModel));
            }
            else
            {
                return(Content(path + " is not a valid file or directory."));
            }
        }
        public bool Load(string[] args)
        {
            // Fetch the game version and store, so it can be retrieved during crash if the toolbox makes it this far.
            Version gameVersion = SpaceEngineersConsts.GetSEVersion();
            bool    newVersion  = GlobalSettings.Default.SEVersion != gameVersion;

            GlobalSettings.Default.SEVersion = gameVersion;

            // Test the Space Engineers version to make sure users are using an version that is new enough for SEToolbox to run with!
            // This is usually because a user has not updated a manual install of a Dedicated Server, or their Steam did not update properly.
            if (GlobalSettings.Default.SEVersion < GlobalSettings.GetAppVersion(true))
            {
                MessageBox.Show(string.Format(Res.DialogOldSEVersionMessage, SpaceEngineersConsts.GetSEVersion(), GlobalSettings.Default.SEBinPath, GlobalSettings.GetAppVersion()), Res.DialogOldSEVersionTitle, MessageBoxButton.OK, MessageBoxImage.Exclamation);
                Application.Current.Shutdown();
                return(false);
            }

            // the /B argument indicates the SEToolboxUpdate had started SEToolbox after fetching updated game binaries.
            if (newVersion && args.Any(a => a.Equals("/B", StringComparison.OrdinalIgnoreCase) || a.Equals("-B", StringComparison.OrdinalIgnoreCase)))
            {
                // Reset the counter used to indicate if the game binaries have updated.
                GlobalSettings.Default.TimesStartedLastGameUpdate = null;
            }

            // Force pre-loading of any Space Engineers resources.
            SpaceEngineersCore.LoadDefinitions();

            // Load the Space Engineers assemblies, or dependant classes after this point.
            var explorerModel = new ExplorerModel();

            if (args.Any(a => a.ToUpper() == "/WR" || a.ToUpper() == "-WR"))
            {
                ResourceReportModel.GenerateOfflineReport(explorerModel, args);
                Application.Current.Shutdown();
                return(false);
            }

            var eViewModel = new ExplorerViewModel(explorerModel);
            var eWindow    = new WindowExplorer(eViewModel);

            //if (allowClose)
            //{
            eViewModel.CloseRequested += (sender, e) =>
            {
                SaveSettings(eWindow);
                Application.Current.Shutdown();
            };
            //}
            eWindow.Loaded += (sender, e) =>
            {
                Splasher.CloseSplash();
                if (GlobalSettings.Default.WindowLeft.HasValue)
                {
                    eWindow.Left = GlobalSettings.Default.WindowLeft.Value;
                }
                if (GlobalSettings.Default.WindowTop.HasValue)
                {
                    eWindow.Top = GlobalSettings.Default.WindowTop.Value;
                }
                if (GlobalSettings.Default.WindowWidth.HasValue)
                {
                    eWindow.Width = GlobalSettings.Default.WindowWidth.Value;
                }
                if (GlobalSettings.Default.WindowHeight.HasValue)
                {
                    eWindow.Height = GlobalSettings.Default.WindowHeight.Value;
                }
                if (GlobalSettings.Default.WindowState.HasValue)
                {
                    eWindow.WindowState = GlobalSettings.Default.WindowState.Value;
                }
            };

            if (!GlobalSettings.Default.TimesStartedTotal.HasValue)
            {
                GlobalSettings.Default.TimesStartedTotal = 0;
            }
            GlobalSettings.Default.TimesStartedTotal++;
            if (!GlobalSettings.Default.TimesStartedLastReset.HasValue)
            {
                GlobalSettings.Default.TimesStartedLastReset = 0;
            }
            GlobalSettings.Default.TimesStartedLastReset++;
            if (!GlobalSettings.Default.TimesStartedLastGameUpdate.HasValue)
            {
                GlobalSettings.Default.TimesStartedLastGameUpdate = 0;
            }
            GlobalSettings.Default.TimesStartedLastGameUpdate++;
            GlobalSettings.Default.Save();

            eWindow.ShowDialog();

            return(true);
        }