コード例 #1
0
            /**
             *@brief constructor. This creates a new assets folder in the working directory this folder will serve as the workspace.
             * This also sets up the folder watcher to watch for folder changes so directory structure is updated even when focus is not on the editor.
             * The same goes for the file watcher.
             */
            public Workspace()
            {
                file_queue_ = new List <FileQueueData>();
                Application.Current.MainWindow.GotKeyboardFocus  += OnMainWindowFocus;
                Application.Current.MainWindow.LostKeyboardFocus += OnMainWindowFocusLost;
                DirectoryInfo info = new DirectoryInfo(Project.directory_path + "\\assets");

                items         = new DirectoryList();
                root          = new DirectoryItem(info.FullName, info.Name, null);
                root.editable = false;

                items.Add(root);

                folder_watcher_      = new FileSystemWatcher();
                folder_watcher_.Path = Project.directory_path + "\\assets";
                folder_watcher_.IncludeSubdirectories = true;
                folder_watcher_.EnableRaisingEvents   = true;
                folder_watcher_.NotifyFilter          = NotifyFilters.DirectoryName;
                folder_watcher_.Renamed += OnFolderWatcherRenamed;
                folder_watcher_.Created += OnFolderWatcherCreated;
                folder_watcher_.Deleted += OnFolderWatcherDeleted;

                file_watcher_      = new FileSystemWatcher();
                file_watcher_.Path = Project.directory_path + "\\assets";
                file_watcher_.IncludeSubdirectories = true;
                file_watcher_.EnableRaisingEvents   = false;
                file_watcher_.Filter       = "*.*";
                file_watcher_.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName;
                file_watcher_.Renamed     += OnFileWatcherRenamed;
                file_watcher_.Changed     += FileWatcherChanged;
                file_watcher_.Deleted     += FileWatcherDeleted;
                file_watcher_.Created     += FileWatcherCreated;
            }
コード例 #2
0
            /**
             *@brief constructor. This sets up the directory item by filling in the name, path, parent and sub_dirs fields.
             *@param[in] folder_path (string) absolute or relative path to the folder to represent
             *@param[in] folder_name (string) name of the folder to represent
             *@param[in] parent_dir (sulphur.editor.DirectoryItem) parent directory from the directory to represent
             */
            public DirectoryItem(string folder_path, string folder_name, DirectoryItem parent_dir)
            {
                DirectoryInfo info = new DirectoryInfo(folder_path);

                if (info.Exists == false)
                {
                    return;
                }
                path     = info.FullName;
                name     = info.Name;
                parent   = parent_dir;
                editable = true;
                items    = new DirectoryList();
                DirectoryInfo[] sub_dirs = info.GetDirectories();

                relative_path = parent_dir == null?path.Remove(0, Project.directory_path.Length) :
                                    parent_dir.relative_path + path.Remove(0, parent_dir.path.Length);

                if (relative_path.StartsWith("\\") == true)
                {
                    relative_path = relative_path.Remove(0, 1);
                }

                foreach (DirectoryInfo dir in sub_dirs)
                {
                    DirectoryItem item = new DirectoryItem(dir.FullName, dir.Name, this);
                    items.Add(item);
                }
            }
コード例 #3
0
        public SteamLibrary(string fullPath, bool isMain = false)
        {
            FullPath = fullPath;
            IsMain   = isMain;

            DirectoryList.Add("SteamApps", new DirectoryInfo(Path.Combine(FullPath, "SteamApps")));
            DirectoryList.Add("SteamBackups", new DirectoryInfo(Path.Combine(FullPath, "SteamBackups")));
            DirectoryList.Add("Common", new DirectoryInfo(Path.Combine(DirectoryList["SteamApps"].FullName, "common")));
            DirectoryList.Add("Download", new DirectoryInfo(Path.Combine(DirectoryList["SteamApps"].FullName, "downloading")));
            DirectoryList.Add("Workshop", new DirectoryInfo(Path.Combine(DirectoryList["SteamApps"].FullName, "workshop")));
        }
コード例 #4
0
ファイル: MultiFileSearch.cs プロジェクト: dlime12/DocBot
        /*
         * Returns all the found .docx files within a directory
         */
        public void GetFileDirectories(string files)
        {
            // Separate Directory and file name (without extension name)
            string fileDir  = Path.GetDirectoryName(files);
            string fileName = Path.GetFileNameWithoutExtension(files);

            FileList.Add(fileName); // Append to modified file list
                                    // Check if that file has a date at the end

            // New file directory and old one
            string full_fileDir = fileDir + "\\" + Path.GetFileName(files);

            DirectoryList.Add(full_fileDir); // Append to directory list
        }
コード例 #5
0
 private void UpdateDirectoryFiles()
 {
     string[] files = System.IO.Directory.GetFiles(this.CurrentDirectory);
     DirectoryList.Clear();
     foreach (string fullFile in files)
     {
         string[] split = fullFile.Split('\\');
         string   file  = split[split.Length - 1];
         string   ext   = Path.GetExtension(file);
         if (ext.ToLower() == ".dll")
         {
             DirectoryList.Add(new FileItem(file, this.CurrentDirectory + "\\" + file));
         }
     }
 }
コード例 #6
0
        /*
         * Called from main function for every existing file
         * which reads the given .docx files
         * and replaces the contents as required.
         */
        public void ReadDocx(string files)
        {
            // Separate Directory and file name (without extension name)
            string fileDir             = Path.GetDirectoryName(files);
            string fileName            = Path.GetFileNameWithoutExtension(files);
            string verify_full_fileDir = fileDir + "\\" + Path.GetFileName(files);

            List <bool> bodyMatch   = new List <bool>();
            List <bool> headerMatch = new List <bool>();
            List <bool> footerMatch = new List <bool>();

            List <string> tempList = new List <string>();

            foreach (DirectoryModel row in SelectedDocs)
            {
                // If we should modify the document
                if (row.ApplyChanges)
                {
                    tempList.Add(row.DirectoryNames);
                }
            }

            // If current file is in list of to be modified documents
            if (tempList.Any(verify_full_fileDir.Contains))
            {
                byte[] byteArray = File.ReadAllBytes(files);
                using (MemoryStream stream = new MemoryStream())
                {
                    stream.Write(byteArray, 0, (int)byteArray.Length);
                    using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(stream, true))
                    {
                        DocumentProtection dp =
                            wordDoc.MainDocumentPart.DocumentSettingsPart.Settings.GetFirstChild <DocumentProtection>();
                        if (dp != null && dp.Enforcement == DocumentFormat.OpenXml.OnOffValue.FromBoolean(true))
                        {
                            dp.Remove(); // Doc is protected
                        }

                        foreach (var change in Changes)
                        {
                            if (HelperFunctions.AssertNotEmptyText(change.OldText, change.NewText))
                            {
                                bodyMatch.Add(ReplaceText(wordDoc, change.OldText, change.NewText));
                            }
                        }

                        foreach (var headerChange in HeaderChanges)
                        {
                            if (HelperFunctions.AssertNotEmptyText(headerChange.OldText, headerChange.NewText))
                            {
                                headerMatch.Add(ReplaceHeader(wordDoc, headerChange.OldText, headerChange.NewText));
                            }
                        }


                        foreach (var footerChange in FooterChanges)
                        {
                            if (HelperFunctions.AssertNotEmptyText(footerChange.OldText, footerChange.NewText))
                            {
                                footerMatch.Add(ReplaceFooter(wordDoc, footerChange.OldText, footerChange.NewText));
                            }
                        }

                        if (Metadata.Count > 0)
                        {
                            UpdateMetadata(wordDoc);
                        }
                    }

                    bool hasBodyMatch   = bodyMatch.Any(x => x);
                    bool hasHeaderMatch = headerMatch.Any(x => x);
                    bool hasFooterMatch = footerMatch.Any(x => x);

                    if (hasBodyMatch || hasHeaderMatch || hasFooterMatch)
                    {
                        // List of files that are processed.
                        FileList.Add(fileName);

                        // Check if that file has a date at the end
                        string regexTest = @"_[0-9]{2}-[0-9]{2}-[0-9]{4}"; //check for _DD-MM-YYYY
                                                                           // If the file name contains date, it will take it out and replace for a new one, if not does nothing
                        fileName  = Regex.Replace(fileName, regexTest, "");
                        fileName += "_" + CurrentDate + ".docx";           // Add new date with file etensions

                        // New file directory and old one
                        string new_fileDir  = fileDir + "\\" + fileName;
                        string full_fileDir = fileDir + "\\" + Path.GetFileName(files);
                        // Replace the old by the new
                        string newPath = files.Replace(full_fileDir, new_fileDir);
                        DirectoryList.Add(full_fileDir); // Append to directory list
                        File.WriteAllBytes(newPath, stream.ToArray());

                        Logger = new LogFile(full_fileDir, Changes, hasBodyMatch, hasHeaderMatch, hasFooterMatch, HeaderChanges, FooterChanges);
                        Logger.CreateLogFile();

                        HasChangedAnything.Add(true);
                    }

                    else
                    {
                        HasChangedAnything.Add(false);
                    }
                }
            }
        }