예제 #1
0
        private async Task AddFileToRecentAsync(UserPreferences preferences, string file, bool notifyHomePage)
        {
            var        recentFile = preferences.File.RecentFiles.FirstOrDefault(f => f.Path == file);
            RecentFile newRecentFile;

            if (recentFile != null)
            {
                newRecentFile = new RecentFile(recentFile.Name, recentFile.Path, this.scheduler.Now.LocalDateTime);
                preferences.File.RecentFiles.Remove(recentFile);

                if (notifyHomePage)
                {
                    await this.HomePage.RemoveRecentFile.Execute(recentFile);
                }
            }
            else
            {
                var settings = await Locator.Current.GetService <ISettingsService>(file).GetSettingsAsync();

                newRecentFile = new RecentFile(settings.ListName, file, this.scheduler.Now.LocalDateTime);
            }

            preferences.File.RecentFiles.Add(newRecentFile);

            if (notifyHomePage)
            {
                await this.HomePage.AddRecentFile.Execute(newRecentFile);
            }
        }
예제 #2
0
    public void Save()
    {
        RecentFile file = RecentFiles.instance.selectedFile;

        file.ChangeName("Painting");
        file.stage = (stage + ideaQuality) / 2;
    }
예제 #3
0
        public void AddFile(RecentFile fileToAdd)
        {
            if (fileToAdd is null)
            {
                return;
            }

            //if it already exists, remove it (will be added on top later)
            for (var i = 0; i < RecentFiles.Count; i++)
            {
                if (string.Equals(RecentFiles[i].Path, fileToAdd.Path, StringComparison.OrdinalIgnoreCase))
                {
                    RecentFiles.RemoveAt(i);
                    break;
                }
            }

            //add to top
            RecentFiles.Insert(0, fileToAdd);

            EnsureMaxiumItemCount();

            Save();

            Updated?.Invoke(this, EventArgs.Empty);
        }
예제 #4
0
        public static async Task <RecentFile> RegisterFile(IStorageFile storageFile, bool overrideEntry = false)
        {
            RecentFile file = new RecentFile(storageFile: storageFile, printErrors: true);
            await file.Check();

            if (file.IsValid)
            {
                if (file.IsFullPathSupported)
                {
                    if (overrideEntry)
                    {
                        RecentFiles.RemoveAll(rf => rf.FullPath == file.FullPath);
                    }
                    if (!RecentFiles.Any(rf => rf.FullPath == file.FullPath))
                    {
                        RecentFiles.Add(file);
                        Save();
                    }
                }
                return(file);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        public void CreateEditorForms()
        {
            NLevelEditorEngine.Instance.LevelChanged += new EventHandler(Editor_LevelChanged);
            NEditorCommandManager cmdMgr = NLevelEditorEngine.Instance.CommandMgr;

            cmdMgr.UndoStackChanged += new EventHandler(this.UndoStackChangedEvent);
            cmdMgr.RedoStackChanged += new EventHandler(this.RedoStackChangedEvent);

            m_layerDlg = new LayerManagerDlg();

            m_GlobalSettingForm = new GlobalSettingForm();

            //加载最近用过的文件
            m_RecentFile = new RecentFile();
            m_RecentFile.Load();
            for (int i = 0; i < m_RecentFile.FileCount; ++i)
            {
                NResourceLoc loc = m_RecentFile.GetFile(i);
                if (loc.IsValid())
                {
                    ToolStripItem item = MTU.DropDown.Items.Add(loc.ToString());
                    if (item != null)
                    {
                        item.Click += this.OnLoadRecentFile;
                    }
                }
            }

            //读取各种设置
            ReadSettings();
        }
예제 #6
0
        public void RecentFile_ctor()
        {
            RecentFile recentFile = new RecentFile("c:\\temp\\ModelFile.json");

            Assert.AreEqual("c:\\temp\\ModelFile.json", recentFile.FilePath);
            Assert.AreEqual("ModelFile.json", recentFile.DisplayName);
        }
예제 #7
0
        public void PinnedTest()
        {
            var recentFile = new RecentFile("Doc1");

            AssertHelper.IsRaisePropertyChangedEvent(recentFile, x => x.IsPinned, () => recentFile.IsPinned = true);
            Assert.IsTrue(recentFile.IsPinned);
        }
예제 #8
0
        public static async Task OpenFile(Frame frame, FileActivatedEventArgs e)
        {
            RecentFile file = await FileStorage.RegisterFile(e);

            // Log._Test(info);
            await OpenFile(frame, file);
        }
예제 #9
0
        public void ConstructorTest()
        {
            var recentFile = new RecentFile("Doc1");

            Assert.AreEqual("Doc1", recentFile.Path);
            Assert.IsFalse(recentFile.IsPinned);
        }
예제 #10
0
        public static async Task OpenFile(Frame frame, RecentFile info)
        {
            try
            {
                if (info != null)
                {
                    await info.Check();
                }

                if (info != null && info.IsValid)
                {
                    if (info.Language.FileType == FileType.TEXT)
                    {
                        frame.Navigate(typeof(MarkdownEditPage), info.GUID);
                    }
                    else if (info.Language.FileType == FileType.INK)
                    {
                        frame.Navigate(typeof(InkEditPage), info.GUID);
                    }
                    else
                    {
                        Log.FatalError("Unknown file type.");
                    }
                }
                else
                {
                    Log.FatalError("The file is not valid.");
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #11
0
        private async Task NewFile(NewFileItem item)
        {
            try
            {
                FileSavePicker savePicker = new FileSavePicker();
                savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

                // Dropdown of file types the user can save the file as
                if (item != null)
                {
                    item.Language.AddLanguageSupport(savePicker);
                }
                else
                {
                    LanguageSupport.AddLanguageSupport(savePicker);
                }

                // Default file name if the user does not type one in or select a file to replace
                savePicker.SuggestedFileName = "New Document";

                StorageFile storageFile = await savePicker.PickSaveFileAsync();

                if (storageFile != null)
                {
                    await FileIO.WriteTextAsync(storageFile, string.Empty);

                    RecentFile file = await FileStorage.RegisterFile(storageFile : storageFile, overrideEntry : true);
                    await OpenFile(Frame, file);
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
        }
예제 #12
0
        private Button CreateOpenRecentFileButton(RecentFile recentFile)
        {
            var button = new FlatButton
            {
                Image           = recentFile.Thumbnail, //.ResizeTo(200, 150),
                Width           = 200,
                Height          = 170,
                Tag             = recentFile.FilePath,
                FlatStyle       = FlatStyle.Flat,
                Text            = Path.GetFileName(recentFile.FilePath),
                ImageAlign      = ContentAlignment.TopCenter,
                TextAlign       = ContentAlignment.BottomCenter,
                HasPressedState = false,
                FocusBackColor  = Color.Thistle,
                NormalBackColor = Color.FromArgb(245, 239, 245),
                BackColor       = Color.FromArgb(245, 239, 245),
                FocusBorderSize = 1,
                Padding         = new Padding(3, 3, 3, 3)
            };

            if (button.Text.Length > 27)
            {
                var toolTip = new ToolTip();
                toolTip.SetToolTip(button, button.Text);
                button.Text = button.Text.Substring(0, 20) + @"..." + button.Text.Substring(button.Text.LastIndexOf('.'));
            }
            button.Click += OpenRecentFileButtonClick;
            return(button);
        }
예제 #13
0
        public void AddFile(string filename, RecentFileType type)
        {
            // check not in list already - if so remove and add to end
            int  idx    = 0;
            bool remove = false;

            foreach (RecentFile file in files)
            {
                if (file.Filename.CompareTo(filename) == 0)
                {
                    remove = true;
                    break;
                }
                idx++;
            }
            if (remove)
            {
                files.RemoveAt(idx);
            }

            RecentFile _file = new RecentFile();

            _file.Filename = filename;
            _file.Type     = type;

            files.Add(_file);
        }
예제 #14
0
        protected async void SaveAsButton_Click(object sender, RoutedEventArgs e)
        {
            FileSavePicker savePicker = new FileSavePicker();

            savePicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

            // Dropdown of file types the user can save the file as
            if (CurrentFile.Language != null)
            {
                CurrentFile.Language.AddLanguageSupport(savePicker);
            }
            else
            {
                LanguageSupport.AddLanguageSupport(savePicker);
            }

            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "New Document";

            StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                CurrentFile = await FileStorage.RegisterFile(storageFile : file);
                await SaveFile();
            }
        }
예제 #15
0
 private void SaveImageFtp(RecentFile recentfile)
 {
     this.SaveImageLocal(recentfile.GetDownloadFilePath());
     Ftp.UploadFile(recentfile.FtpUserName,
                    recentfile.FtpPassword,
                    recentfile.GetFtpUrlFilePath(),
                    recentfile.GetDownloadFilePath());
 }
예제 #16
0
        public void GetSchemaTest()
        {
            var recentFile = new RecentFile("Doc1");

            IXmlSerializable serializable = recentFile;

            Assert.IsNull(serializable.GetSchema());
        }
예제 #17
0
        public void WriteXmlTest_Precondition()
        {
            var recentFile = new RecentFile("Doc1");

            IXmlSerializable serializable = recentFile;

            serializable.WriteXml(null);
        }
예제 #18
0
        protected async sealed override Task LoadState(LoadStateEventArgs e)
        {
            await base.LoadState(e);

            BeforeLoadFile(e);

            CurrentFile = FileStorage.GetById(e.NavigationParameter as string);
            await LoadFile();
        }
예제 #19
0
        public RecentFileProxy(RecentFile recentFile,
                               Action <RecentFile> openAction,
                               Action <RecentFile> removeAction)
        {
            _recentFile = recentFile;

            OpenCommand   = new Command(() => openAction(recentFile));
            RemoveCommand = new Command(() => removeAction(recentFile));
        }
예제 #20
0
        private void OnstartUpWorkerDoWork(object sender, DoWorkEventArgs e)
        {
            //System.Threading.Thread.Sleep(4000);
            System.Diagnostics.Debug.Assert(null == startUpData);
            List <RecentFile> recentFiles = RecentFile.Deserialize();

            startUpData = new StartUpData(recentFiles);
            TextEditorControl.Instance.TextCore.Data = startUpData;
        }
예제 #21
0
 private void listView_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
 {
     if (e.IsSelected)
     {
         _recent = e.Item.Tag as RecentFile;
     }
     else
     {
         _recent = null;
     }
 }
예제 #22
0
        private void AddToListView(RecentFile item)
        {
            var modifiedDate = DateTimeExtensions.FromUnixEpoch(item.modifiedTime);
            var size         = item.size / 1024;
            var listViewItem = listView.Items.Add(item.title);

            listViewItem.ImageIndex = _fileIcon;
            listViewItem.SubItems.Add(modifiedDate.ToShortDateString());
            listViewItem.SubItems.Add(item.version.ToString());
            listViewItem.SubItems.Add(String.Format("{0} KB", size.ToString()));
            listViewItem.Tag = item;
        }
예제 #23
0
        /// <summary>
        /// Gets the text.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <returns>The text</returns>
        private static string GetText(RecentFile file)
        {
            if (file.OperationType == "/assets/images/view.png")
            {
                return(String.Format("{0}|{1}|{2}", "VIEW", file.Name, file.SourceFilePath));
            }
            else if (file.OperationType == "/assets/images/extract.png")
            {
                return(String.Format("{0}|{1}|{2}|{3}", "EXTRACT", file.Name, file.SourceFilePath, file.DestinationFilePath));
            }

            return("");
        }
예제 #24
0
    public void Save()
    {
        RecentFile file = RecentFiles.instance.selectedFile;

        if (file == null)
        {
            return;
        }
        file.Delete();
        file.qualityValue = qualityValue;
        file.text.text    = "Idea";
        Delete();
    }
예제 #25
0
 private bool RecentFileExists()
 {
     foreach (RecentFile f in RecentFiles)
     {
         if (File.Exists(f.Path))
         {
             RecentFileName = f.Name.Trim();
             recentFile = f;
             return true;
         }
     }
     return false;
 }
예제 #26
0
    public RecentFiles(Properties properties)
    {
        nFiles = 0;
        if (properties.getProperty("RecentFiles") != null)
        {
            try
            {
                nFiles = int.Parse(properties.getProperty("RecentFiles"));
            }
            catch (Exception e)
            {
                // If any problem reading or parsing the number of recent files, do not use that field
            }
        }
        recentFiles = new RecentFile[MAX_FILES];
        int nCorrectFiles = nFiles;

        for (int i = 0; i < nFiles; i++)
        {
            string   pathKey = "RecentFile." + i + ".FilePath";
            string   path    = properties.getProperty(pathKey);
            FileInfo file    = new FileInfo(path);
            if (file.Exists)
            {
                string dateKey = "RecentFile." + i + ".DateOpened";
                string date    = properties.getProperty(dateKey);

                RecentFile recentFile = new RecentFile(path, date);
                recentFiles[i] = recentFile;
            }
            else
            {
                recentFiles[i] = null;
                nCorrectFiles--;
            }
        }

        RecentFile[] temp = new RecentFile[MAX_FILES];
        for (int i = 0, j = 0; i < nFiles; i++)
        {
            if (recentFiles[i] != null)
            {
                temp[j] = recentFiles[i];
                j++;
            }
        }
        nFiles      = nCorrectFiles;
        recentFiles = temp;

        orderFilesByDate();
    }
예제 #27
0
        private void OpenImageFtp(RecentFile imagepath)
        {
            var downloadfilepath = imagepath.GetDownloadFilePath();
            var test             = Path.Combine(imagepath.FtpHostName, imagepath.FileDirectory, imagepath.FileName);
            var url = imagepath.GetFtpUrlFilePath();

            Ftp.DownloadFile(
                imagepath.FtpUserName,
                imagepath.FtpPassword,
                url,
                downloadfilepath);

            this.OpenImageLocal(downloadfilepath);
        }
예제 #28
0
        private IDocument OpenCore(string fileName, FileType fileType = null)
        {
            // Check if document is already opened
            IDocument document = Documents.SingleOrDefault(d => d.FileName == fileName);

            if (document == null)
            {
                IDocumentType documentType;
                if (fileType != null)
                {
                    documentType = GetDocumentType(fileType);
                }
                else
                {
                    documentType = documentTypes.FirstOrDefault(dt => dt.FileExtension == Path.GetExtension(fileName));
                    if (documentType == null)
                    {
                        Trace.TraceError(string.Format(CultureInfo.InvariantCulture,
                                                       "The extension of the file '{0}' is not supported.", fileName));
                        messageService.ShowError(shellService.ShellView, string.Format(CultureInfo.CurrentCulture, Resources.FileExtensionNotSupported, fileName));
                        return(null);
                    }
                }

                try
                {
                    document = documentType.Open(fileName);
                }
                catch (Exception e)
                {
                    Trace.TraceError(e.ToString());
                    messageService.ShowError(shellService.ShellView, string.Format(CultureInfo.CurrentCulture, Resources.CannotOpenFile, fileName));
                    if (e is FileNotFoundException)
                    {
                        RecentFile recentFile = recentFileList.RecentFiles.FirstOrDefault(x => x.Path == fileName);
                        if (recentFile != null)
                        {
                            recentFileList.Remove(recentFile);
                        }
                    }
                    return(null);
                }

                fileService.AddDocument(document);
                recentFileList.AddFile(document.FileName);
            }
            ActiveDocument = document;
            return(document);
        }
예제 #29
0
        private void SaveImage(RecentFile recentfile)
        {
            if (recentfile.Type == RecentFileType.Local)
            {
                this.SaveImageLocal(recentfile.GetFilePath());
            }

            if (recentfile.Type == RecentFileType.Ftp)
            {
                this.SaveImageFtp(recentfile);
            }

            this.IsUnsaved = false;
            this.FirePropertyChangedEvent(null);
        }
예제 #30
0
 public static void LoadRecentFiles()
 {
     if (!File.Exists(recentFilesPath))
     {
         return;
     }
     RecentFiles.Clear();
     string[] data = File.ReadAllLines(recentFilesPath);
     for (int i = 0; i < data.Length - 1; i += 2)
     {
         RecentFile f = new RecentFile();
         f.path      = data[i];
         f.timestamp = long.Parse(data[i + 1]);
         RecentFiles.Add(f);
     }
 }
        public void RemoveFile_FileNotNull_ShouldCallSerialize()
        {
            // Arrange
            var mockedSerializer = new Mock <IRecentFilesSerializer>();

            mockedSerializer.Setup(_ => _.Deserialize()).Returns(() => new List <RecentFile>());

            var helper       = GetHelper(serializerToUse: mockedSerializer.Object, fileSystemToUse: fileSystemWithTestData);
            var fileToRemove = new RecentFile(fileSystemWithTestData.AllFiles.Last(), DateTime.UtcNow);

            // Act
            helper.RemoveFile(fileToRemove);

            // Assert
            mockedSerializer.Verify(_ => _.Serialize(It.IsAny <List <RecentFile> >()), Times.Once);
        }
예제 #32
0
 public void Add(RecentFile file)
 {
     if (file == null) throw new ArgumentNullException(nameof(file));
     
     _files.AddOrUpdate(file);
 }
예제 #33
0
        void UpdateMenuItems()
        {
            if (_RecentFiles == null) return;
            if (_RecentFiles.Count == 0) return;

            int iMenuItem = FileMenu.Items.IndexOf(this);
            
            //RecentFiles contains the correct and current recent files.
            //_RecentFiles holds the menu entries.
            //Change size of _RecentFiles if necessary.
            if (_RecentFiles.Count < RecentFiles.Count)
            {
                for (int i = RecentFiles.Count - _RecentFiles.Count; i > 0; i--)
                    _RecentFiles.Add(null);
            }
            else if (_RecentFiles.Count > RecentFiles.Count)
            {
                List<RecentFile> RemovedItems = new List<RecentFile>();
                
                //find all menu items that are not in recent file list.
                foreach (RecentFile r in _RecentFiles)
                    if (!RecentFiles.Contains(r.Filepath))
                    {
                        FileMenu.Items.Remove(r.MenuItem);
                        RemovedItems.Add(r);
                    }

                foreach (RecentFile r in RemovedItems)
                    _RecentFiles.Remove(r);

            }

            for(int i=0;i<_RecentFiles.Count;i++)            
            {
                //this is a new entry initialize it!
                if (_RecentFiles[i] == null)
                {                    
                    _RecentFiles[i] = new RecentFile(i, RecentFiles[i]);
                    _RecentFiles[i].MenuItem = new MenuItem { Header = ShortenPathname(RecentFiles[i], MaxPathLength) };
                    // add a tooltip if path was shortened
                    if (RecentFiles[i].Length > MaxPathLength + Path.GetExtension(RecentFiles[i]).Length )
                    {
                        _RecentFiles[i].MenuItem.ToolTip = RecentFiles[i];
                    }
                    _RecentFiles[i].Filepath = RecentFiles[i];
                    _RecentFiles[i].MenuItem.Click += MenuItem_Click;
                    FileMenu.Items.Insert(iMenuItem + i + 1, _RecentFiles[i].MenuItem);
                }
                else //update entry
                {
                    _RecentFiles[i].MenuItem.Header = ShortenPathname(RecentFiles[i], MaxPathLength);
                    _RecentFiles[i].Filepath = RecentFiles[i];
                }                              
            }            
        }
예제 #34
0
        /// <summary>
        /// Returns true if file was loaded
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public static bool Load()
        {
            // check for settings file
            bool settingsFileExists = File.Exists(FilePath);

                // Parse the settings file
            if (settingsFileExists)
            {
                XmlDocument doc = new XmlDocument();

                try
                {
                    // load settings into document
                    doc.Load(FilePath);

                    // loop rootnode's nodes, and depending on what node we find
                    // do a different action.
                    foreach (XmlNode node in doc.DocumentElement.ChildNodes)
                    {
                        switch (node.Name)
                        {
                            case XML_NODE_MAINMENUFILE:
                                {
                                    pathMainmenu = node.InnerText;
                                    break;
                                }
                            case XML_NODE_MPSHAREDFILE:
                                {
                                    pathShared = node.InnerText;
                                    break;
                                }
                            case XML_NODE_SPSHAREDFILE:
                                {
                                    pathSPShared = node.InnerText;
                                    break;
                                }
                            case XML_NODE_BITMAPSFILE:
                                {
                                    pathBitmaps = node.InnerText;
                                    break;
                                }

                            case XML_NODE_MAPSFOLDER:
                                {
                                    pathMapsFolder = node.InnerText;
                                    break;
                                }
                            case XML_NODE_CLEANMAPSFOLDER:
                                {
                                    pathCleanMaps = node.InnerText;
                                    break;
                                }
                            case XML_NODE_PLUGINSFOLDER:
                                {
                                    pathPluginsFolder = node.InnerText;
                                    break;
                                }
                            case XML_NODE_BITMAPSFOLDER:
                                {
                                    pathBitmapsFolder = node.InnerText;
                                    break;
                                }
                            case XML_NODE_EXTRACTSFOLDER:
                                {
                                    pathExtractsFolder = node.InnerText;
                                    break;
                                }
                            case XML_NODE_PATCHFOLDER:
                                {
                                    pathPatchFolder = node.InnerText;
                                    break;
                                }

                            case XML_NODE_USEDEFMAPS:
                                {
                                    useDefaultMaps = bool.Parse(node.InnerText);
                                    break;
                                }
                            case XML_NODE_USEREGISTRY:
                                {
                                    useRegistryEntries = bool.Parse(node.InnerText);
                                    break;
                                }
                            case XML_NODE_CHECKUPDATE:
                                {
                                    checkUpdate = (updateFrequency)Enum.Parse(typeof(updateFrequency), node.InnerText);
                                    break;
                                }
                            case XML_NODE_LASTUPDATECHECK:
                                {
                                    lastCheck = DateTime.Parse(node.InnerText);
                                    break;
                                }

                            case XML_NODE_RECENTMAPSLIST:
                                {
                                    foreach (XmlNode recentMapNode in node)
                                    {
                                        RecentFile rf = new RecentFile();
                                        rf.Path = recentMapNode.InnerText;
                                        RecentOpenedMaps.Add(rf);
                                    }
                                    break;
                                }
                            case XML_NODE_QUICKACCESSTAGSLIST:
                                {
                                    foreach (XmlNode quickAccessNode in node)
                                    {
                                        QuickAccessTagType quickAcess = new QuickAccessTagType();
                                        quickAcess.TagType = quickAccessNode.Attributes[XML_ATTR_TAGTYPENAME].InnerText;
                                        foreach (XmlNode tagPathNode in quickAccessNode)
                                        {
                                            //switch (tagPathNode.Name)
                                            //{
                                            //    case XML_NODE_QUICKACCESSTAGPATH:
                                            //        {
                                            quickAcess.TagPaths.Add(tagPathNode.InnerText);
                                            //            break;
                                            //        }

                                            //}
                                        }
                                        QuickAccessTagTypes.Add(quickAcess);
                                    }
                                    break;
                                }
                            case XML_NODE_USERPLUGINMASKS:
                                {
                                    foreach (XmlNode pluginMaskNode in node)
                                    {
                                        CustomPluginMask mask = new CustomPluginMask();
                                        mask.Name = pluginMaskNode.Attributes[XML_ATTR_PLUGINMASKNAME].InnerText;

                                        foreach (XmlNode maskNode in pluginMaskNode)
                                        {
                                            //switch (maskNode.Name)
                                            //{
                                            //    case XML_NODE_PLUGINMASK_VISIBLETAGTYPE:
                                            //        {
                                            mask.VisibleTagTypes.Add(
                                                maskNode.Attributes[XML_ATTR_TAGTYPENAME].InnerText);
                                            //            break;
                                            //        }

                                            //}
                                        }

                                        CustomPluginMasks.Add(mask);
                                    }
                                    break;
                                }
                        }
                    }
                }
                catch
                {
                    settingsFileExists = false;
                }
            }

            // If useRegistryEntires is set to false & the settings file exists, then the
            // user doesn't wish to use the registry, so we are good to exit
            if (settingsFileExists && !useRegistryEntries)
                return true;

            // If enabled, load the settings from the registry
            if (useRegistryEntries)
            {
                // Used for accessing the registry
                RegistryAccess Reg;

                try
                {
                    // UseSettingsFile contains a list of Entity directories that wish to use the settings file instead of
                    // the registry. Check if our path is in the list for using the settings file.
                    Reg = new RegistryAccess(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2 + @"Entity\UseSettingsFile\");

                    // If Entry exists in list, use settings file if it exists
                    if (Reg.getValue(Globals.Global.StartupPath) != null)
                        return settingsFileExists;

                    // Try to open the settings for Halo 2, if it doesn't exist, Reg.isOpen == false
                    Reg = new RegistryAccess(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2Paths);
                    if (Reg.isOpen)
                    {
                        string tempS = string.Empty;
                        #region General Halo2 paths in registry
                        tempS = Reg.getValue(RegistryAccess.RegNames.MainMenuFile);
                        if (tempS != null) Prefs.pathMainmenu = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.SharedFile);
                        if (tempS != null) Prefs.pathShared = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.SinglePlayerSharedFile);
                        if (tempS != null) Prefs.pathSPShared = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.BitmapsFile);
                        if (tempS != null) Prefs.pathBitmaps = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.MapsPath);
                        if (tempS != null) Prefs.pathMapsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.FontsPath);
                        if (tempS != null) Prefs.pathFontsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.BitmapsPath);
                        if (tempS != null) Prefs.pathBitmapsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.ExtractsPath);
                        if (tempS != null) Prefs.pathExtractsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.PluginsPath);
                        if (tempS != null) Prefs.pathPluginsFolder = tempS;
                        tempS = Reg.getValue(RegistryAccess.RegNames.CleanMapsPath);
                        if (tempS != null) Prefs.pathCleanMaps = tempS;
                        #endregion
                        #region Entity specific paths & settings
                        Reg = new RegistryAccess(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2 + @"Entity\");
                        tempS = Reg.getValue("PatchFolder");
                        if (tempS != null) Prefs.pathPatchFolder = tempS;
                        tempS = Reg.getValue("UseDefaultMaps");
                        if (tempS != null) Prefs.useDefaultMaps = bool.Parse(tempS);
                        Prefs.useRegistryEntries = true;
                        #region Automatic Update
                        tempS = Reg.getValue("lastCheck");
                        if (tempS != null)
                            try
                            {
                                Prefs.lastCheck = DateTime.Parse(tempS);
                            }
                            catch
                            {
                                Prefs.lastCheck = DateTime.MinValue;
                            }
                        tempS = Reg.getValue("checkUpdate");
                        try
                        {
                            Prefs.updateFrequency updateFreq = (Prefs.updateFrequency)Enum.Parse(typeof(Prefs.updateFrequency), tempS);
                            Prefs.checkUpdate = updateFreq;
                        }
                        catch
                        {
                            Prefs.checkUpdate = Prefs.updateFrequency.Daily;
                        }
                        #endregion;

                        // Check for recent files in the registry
                        Reg = new RegistryAccess(Registry.CurrentUser, RegistryAccess.RegPaths.Halo2RecentFiles);
                        if (Reg.isOpen)
                        {
                            for (int count = Prefs.MaxRecentFiles - 1; count >= 0; count--)
                            {
                                tempS = Reg.getValue(count.ToString());
                                if (tempS != null)
                                {
                                    RecentFile rf = new RecentFile();
                                    rf.Path = tempS;
                                    RecentOpenedMaps.Insert(0, rf);
                                }
                            }
                        }

                        #endregion
                        #region Load Quick Access Tags
                        if (Prefs.useRegistryEntries)
                        {
                            try
                            {
                                RegistryAccess ra = new RegistryAccess(Microsoft.Win32.Registry.CurrentUser, RegistryAccess.RegPaths.Halo2 + @"Entity\ME\Tags\");
                                string[] tags = ra.getKeys();
                                foreach (string tagType in tags)
                                {
                                    QuickAccessTagType qatt = new QuickAccessTagType();
                                    qatt.TagType = tagType;
                                    ra.setKey(Microsoft.Win32.Registry.CurrentUser, RegistryAccess.RegPaths.Halo2 + @"Entity\ME\Tags\" + tagType + @"\");
                                    foreach (string tagName in ra.getNames())
                                    {
                                        if (ra.getValue(tagName).ToLower() == "true")
                                            qatt.TagPaths.Add(tagName);
                                    }
                                    if (qatt.TagPaths.Count > 0)
                                        QuickAccessTagTypes.Add(qatt);
                                }
                            }
                            catch
                            {
                                // Ignore errors regarding to Quick keys
                            }
                        }
                        #endregion
                        Reg.CloseReg();
                        return true;
                    }
                }
                catch (Exception e)
                {
                    Global.ShowErrorMsg("Prefs Load Exception", e);
                    return settingsFileExists;
                }

            }

            return false;
        }
예제 #35
0
            public void newRecentFile(String filename, String path)
            {
                RecentFile file = new RecentFile(filename, path);
                if (m_recentFiles.Contains(file))
                {
                    int index = m_recentFiles.IndexOf(file);
                    m_recentFiles.Remove(file);
                }
                m_recentFiles.Insert(0, file);

                OnPropertyChanged("Recent");

                save(defaultfile);
            }
        private void DoReload()
        {
            Boss editor = ObjectModel.Create("DirectoryEditorPlugin");
            var finder = editor.Get<IFindDirectoryEditor>();

            foreach (RecentFile file in m_files)
            {
                file.DisplayText.release();
            }

            // Get all the recent files.
            int index = 0;
            NSArray array = NSDocumentController.sharedDocumentController().recentDocumentURLs();
            m_files = (from a in array
                let p = a.To<NSURL>().path().ToString()
                    where File.Exists(p) && !p.Contains("/-Tmp-/")
                select new RecentFile(p, finder, ++index)).ToArray();

            // Use a reversed path for the name for any entries with duplicate names.
            Array.Sort(m_files, (lhs, rhs) => lhs.DisplayName.CompareTo(rhs.DisplayName));
            for (int i = 0; i < m_files.Length - 1; ++i)
            {
                string name = m_files[i].DisplayName;
                if (m_files[i + 1].DisplayName == name)
                {
                    for (int j = i; j < m_files.Length && m_files[j].DisplayName == name; ++j)
                    {
                        RecentFile f = m_files[j];
                        m_files[j] = new RecentFile(f, f.Path.ReversePath());
                        f.DisplayText.release();
                    }
                }
            }

            // Sort them and refresh the view.
            DoSort();
            m_table.reloadData();
        }
            public RecentFile(RecentFile file, string displayName)
                : this()
            {
                Path = file.Path;
                FileName = file.FileName;
                DisplayName = displayName;
                Index = file.Index;

                NSDictionary attrs = file.DisplayText.fontAttributesInRange(new NSRange(0, 1));
                DisplayText = NSAttributedString.Create(displayName, attrs);
                DisplayText.retain();
            }
예제 #38
0
        public void Remove(RecentFile file)
        {
            _files.Remove(file);

        }
예제 #39
0
        public void AddFile(string filename, RecentFileType type)
        {
            // check not in list already - if so remove and add to end
            int idx = 0;
            bool remove = false;
            foreach (RecentFile file in files)
            {
                if (file.Filename.CompareTo(filename) == 0)
                {
                    remove = true;
                    break;
                }
                idx++;
            }
            if (remove)
                files.RemoveAt(idx);

            RecentFile _file = new RecentFile();
            _file.Filename = filename;
            _file.Type = type;

            files.Add(_file);
        }
예제 #40
0
 private Button CreateOpenRecentFileButton(RecentFile recentFile)
 {
     var button = new FlatButton
     {
         Image = recentFile.Thumbnail, //.ResizeTo(200, 150),
         Width = 200,
         Height = 170,
         Tag = recentFile.FilePath,
         FlatStyle = FlatStyle.Flat,
         Text = Path.GetFileName(recentFile.FilePath),
         ImageAlign = ContentAlignment.TopCenter,
         TextAlign = ContentAlignment.BottomCenter,
         HasPressedState = false,
         FocusBackColor = Color.Thistle,
         NormalBackColor = Color.FromArgb(245, 239, 245),
         BackColor = Color.FromArgb(245, 239, 245),
         FocusBorderSize = 1,
         Padding = new Padding(3, 3, 3, 3)
     };
     if (button.Text.Length > 27)
     {
         var toolTip = new ToolTip();
         toolTip.SetToolTip(button, button.Text);
         button.Text = button.Text.Substring(0, 20) + @"..." + button.Text.Substring(button.Text.LastIndexOf('.'));
     }
     button.Click += OpenRecentFileButtonClick;
     return button;
 }
 public RecentFileDeleteMessage(RecentFile recentFileData)
 {
     Data = recentFileData;
 }