コード例 #1
0
        private static Dictionary <string, string> LoadDefaultAbbreviations()
        {
            if (null == default_abbreviations)
            {
                Logging.Info("+Loading default abbreviations.");

                Dictionary <string, string> abbreviations = new Dictionary <string, string>();

                string citation_resources_subdirectory = CSLProcessor.CITATION_RESOURCES_SUBDIRECTORY;
                string filename = Path.GetFullPath(Path.Combine(citation_resources_subdirectory, @"default_abbreviations.txt.gz"));
                using (FileStream stream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    using (GZipStream compressed_stream = new GZipStream(stream, CompressionMode.Decompress))
                    {
                        LoadAbbreviationsFromStream(compressed_stream, abbreviations);
                    }
                }

                Logging.Info("-Loaded {0} default abbreviations.", abbreviations.Count);

                default_abbreviations = abbreviations;
            }

            return(default_abbreviations);
        }
コード例 #2
0
        private static void Export_Directories_AutoTags(WebLibraryDetail web_library_detail, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items)
        {
            WshShell shell = new WshShell();

            string tags_base_path = Path.GetFullPath(Path.Combine(base_path, @"autotags"));

            Directory.CreateDirectory(tags_base_path);

            foreach (var item in pdf_document_export_items.Values)
            {
                try
                {
                    foreach (string tag in web_library_detail.Xlibrary.AITagManager.AITags.GetTagsWithDocument(item.pdf_document.Fingerprint))
                    {
                        string tag_base_path = Path.GetFullPath(Path.Combine(tags_base_path, FileTools.MakeSafeFilename(tag)));
                        Directory.CreateDirectory(tag_base_path);
                        string filename = Path.GetFullPath(Path.Combine(tag_base_path, FileTools.MakeSafeFilename(item.pdf_document.TitleCombined) + ".lnk"));
                        CreateShortcut(shell, item.filename, filename);
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error creating shortcut for {0}", item.filename);
                }
            }
        }
コード例 #3
0
        public CSLProcessorOutputConsumer(string script_directory, string citations_javascript, BibliographyReadyDelegate brd, object user_argument)
        {
            WPFDoEvents.AssertThisCodeIsRunningInTheUIThread();

            this.citations_javascript = citations_javascript;
            this.brd           = brd;
            this.user_argument = user_argument;

            // Create the browser
            Logging.Info("Creating web browser for InCite CSL processing");
            web_browser = new GeckoWebBrowser();
            web_browser.CreateControl();

            // Add the name of the script to run
            script_directory = Path.GetFullPath(Path.Combine(script_directory, @"runengine.html"));
            script_directory = script_directory.Replace(@"\\", @"\");
            script_directory = script_directory.Replace(@"//", @"/");

            Uri uri = new Uri(script_directory);

            Logging.Info("CSLProcessorOutputConsumer is about to browse to {0}", uri);

            // This is the only way we can communicate from JavaScript to .NET!!
            web_browser.EnableConsoleMessageNotfication();
            web_browser.ConsoleMessage += web_browser_ConsoleMessage;

            // Kick off citeproc computation
            web_browser.Navigate(uri.ToString());
        }
コード例 #4
0
        private void GenericCustomiseChooser(string title, string filename)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter          = "Image files|*.jpeg;*.jpg;*.png;*.gif;*.bmp" + "|" + "All files|*.*";
            dialog.CheckFileExists = true;
            dialog.Multiselect     = false;
            dialog.Title           = title;
            //dialog.FileName = filename;
            if (true == dialog.ShowDialog())
            {
                // Copy the new file into place, if it is another file than the one we already have:
                filename = Path.GetFullPath(filename);
                string new_filename = Path.GetFullPath(dialog.FileName);
                if (0 != new_filename.CompareTo(filename))
                {
                    File.Delete(filename);
                    File.Copy(new_filename, filename);
                }
            }
            else
            {
                File.Delete(filename);
            }

            UpdateLibraryStatistics();
        }
コード例 #5
0
        private static void Export_Directories_Tags(Library library, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items)
        {
            WshShell shell = new WshShell();

            string tags_base_path = Path.GetFullPath(Path.Combine(base_path, @"tags"));

            Directory.CreateDirectory(tags_base_path);

            foreach (var item in pdf_document_export_items.Values)
            {
                try
                {
                    foreach (string tag in TagTools.ConvertTagBundleToTags(item.pdf_document.Tags))
                    {
                        string tag_base_path = Path.GetFullPath(Path.Combine(tags_base_path, FileTools.MakeSafeFilename(tag)));
                        Directory.CreateDirectory(tag_base_path);
                        string filename = Path.GetFullPath(Path.Combine(tag_base_path, FileTools.MakeSafeFilename(item.pdf_document.TitleCombined) + ".lnk"));
                        CreateShortcut(shell, item.filename, filename);
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error creating shortcut for " + item.filename);
                }
            }
        }
コード例 #6
0
        private static void Export_Directories_Authors(Library library, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items)
        {
            WshShell shell = new WshShell();

            string authors_base_path = Path.GetFullPath(Path.Combine(base_path, @"authors"));

            Directory.CreateDirectory(authors_base_path);

            foreach (var item in pdf_document_export_items.Values)
            {
                try
                {
                    List <NameTools.Name> names = NameTools.SplitAuthors(item.pdf_document.AuthorsCombined);
                    foreach (var name in names)
                    {
                        string author_base_path = Path.GetFullPath(Path.Combine(authors_base_path, name.LastName_Initials));
                        Directory.CreateDirectory(author_base_path);
                        string filename = Path.GetFullPath(Path.Combine(author_base_path, FileTools.MakeSafeFilename(item.pdf_document.TitleCombined) + ".lnk"));
                        CreateShortcut(shell, item.filename, filename);
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error creating shortcut for " + item.filename);
                }
            }
        }
コード例 #7
0
        public IntranetLibraryDB(string base_path)
        {
            this.base_path = base_path;
            library_path   = IntranetLibraryTools.GetLibraryMetadataPath(base_path);

            // Copy a library into place...
            if (!File.Exists(library_path))
            {
                Logging.Warn("Intranet Library metadata db does not exist so copying the template to {0}", library_path);
                string library_metadata_template_path = Path.GetFullPath(Path.Combine(ConfigurationManager.Instance.StartupDirectoryForQiqqa, @"DocumentLibrary/IntranetLibraryStuff/IntranetLibrary.Metadata.Template.s3db"));
                if (!File.Exists(library_metadata_template_path))
                {
                    throw new Exception($"Sync template file '{library_metadata_template_path}' does not exist!");
                }
                string basedir = Path.GetDirectoryName(library_path);
                if (!Directory.Exists(basedir))
                {
                    throw new Exception($"Sync target directory '{basedir}' for Qiqqa database '{library_path}' does not exist!");
                }
                try
                {
                    File.Copy(library_metadata_template_path, library_path);
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error 0x{2:08X}: Failed to write the sync template '{0}' to sync target directory '{1}'", library_metadata_template_path, basedir, ex.HResult);
                    throw;
                }
            }
        }
コード例 #8
0
 public static string NormalizePath(this string path)
 {
     //https://stackoverflow.com/questions/2281531/how-can-i-compare-directory-paths-in-c
     return(Path.GetFullPath(new Uri(path).LocalPath)
            .TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar)
            .ToUpperInvariant());
 }
コード例 #9
0
        internal static void Export(Library library, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items)
        {
            StringBuilder html = new StringBuilder();

            html.AppendFormat("<html>\n");
            html.AppendFormat("  <head>\n");
            html.AppendFormat("    <title>Qiqqa Library Export</title>\n");
            html.AppendFormat("  </head>\n");
            html.AppendFormat("<body>\n");
            html.AppendFormat(String.Format("<a href=\"{0}\"><image align=\"right\" src=\"Qiqqa.png\" border=\"0\"/></a>\n", WebsiteAccess.Url_QiqqaLibraryExportTrackReference));
            html.AppendFormat("<h1>Qiqqa Library Export</h1>\n");

            Export_HTML_Titles(html, library, base_path, pdf_document_export_items);
            Export_HTML_Authors(html, library, base_path, pdf_document_export_items);
            Export_HTML_Tags(html, library, base_path, pdf_document_export_items);
            Export_HTML_AutoTags(html, library, base_path, pdf_document_export_items);

            html.AppendFormat("</body>\n");
            html.AppendFormat("</html>\n");


            string      image_filename = Path.GetFullPath(Path.Combine(base_path, @"Qiqqa.png"));
            BitmapImage image          = Icons.GetAppIcon(Icons.Qiqqa);

            using (FileStream filestream = new FileStream(image_filename, FileMode.Create))
            {
                PngBitmapEncoder encoder = new PngBitmapEncoder();
                encoder.Frames.Add(BitmapFrame.Create(image));
                encoder.Save(filestream);
            }

            string filename = Path.GetFullPath(Path.Combine(base_path, @"Qiqqa.html"));

            File.WriteAllText(filename, html.ToString());
        }
コード例 #10
0
        /// <summary>
        /// Shows a simple modal list of release notes.
        /// </summary>
        public void ViewChanges(object dummy = null)
        {
            try
            {
                string release_notes;

                if (_latestClientVersionInformation != null)
                {
                    release_notes = _latestClientVersionInformation.ReleaseNotes;
                    if (string.IsNullOrEmpty(release_notes))
                    {
                        Logging.Warn("No release notes from server, nothing to do");
                        return;
                    }
                }
                else
                {
                    string ChangelogFilename = Path.GetFullPath(Path.Combine(ConfigurationManager.Instance.StartupDirectoryForQiqqa, @"CHANGELOG.md"));

                    release_notes = File.ReadAllText(ChangelogFilename, Encoding.UTF8);
                }
                release_notes = release_notes.Trim();

                //  switch to the gui thread
                WPFDoEvents.InvokeInUIThread(() => _showReleaseNotesDelegate(release_notes));
            }
            catch (Exception e)
            {
                Logging.Error(e, "Problem viewing changes for new client version");
            }
        }
コード例 #11
0
        public string ScrapeURLToFile(string url, bool force_download = false, Dictionary <string, string> additional_headers = null)
        {
            string cache_key = StreamMD5.FromText(url);
            string directory = Path.GetFullPath(Path.Combine(base_directory, cache_key.Substring(0, 2)));
            string filename  = Path.GetFullPath(Path.Combine(directory, cache_key));

            if (!File.Exists(filename) || force_download)
            {
                Utilities.Files.DirectoryTools.CreateDirectory(directory);

                // Crude throttle
                if (true)
                {
                    while (DateTime.UtcNow.Subtract(last_scrape_time).TotalMilliseconds < throttle_ms)
                    {
                        Thread.Sleep(50);
                    }
                    last_scrape_time = DateTime.UtcNow;
                }

                Logging.Info("Downloading from {0}", url);
                using (WebClient client = new WebClient())
                {
                    if (null != additional_headers)
                    {
                        foreach (var pair in additional_headers)
                        {
                            client.Headers.Add(pair.Key, pair.Value);
                        }
                    }
                    if (!String.IsNullOrEmpty(userAgent))
                    {
                        client.Headers.Add("User-agent", userAgent);
                    }

                    string temp_filename = filename + ".tmp";
                    try
                    {
                        client.DownloadFile(url, temp_filename);
                    }
                    catch (WebException ex)
                    {
                        File.WriteAllText(temp_filename, ex.ToString());
                    }

                    File.Delete(filename);
                    File.Move(temp_filename, filename);
                }

                string filename_manifest = Path.GetFullPath(Path.Combine(base_directory, @"manifest.txt"));
                string manifest_line     = String.Format("{0}\t{1}", cache_key, url);
                using (StreamWriter sw = File.AppendText(filename_manifest))
                {
                    sw.WriteLine(manifest_line);
                }
            }

            return(filename);
        }
コード例 #12
0
        internal static string GetRootStyleFilename(string style_xml_filename)
        {
            string parent_filename;
            string parent_url;

            if (IsDependentStyle(style_xml_filename, out parent_filename, out parent_url))
            {
                // Check that we have the dependent style - if we don't prompt to download it
                string full_parent_filename = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(style_xml_filename), parent_filename));
                if (!File.Exists(full_parent_filename))
                {
                    string message = String.Format(
                        "Can't find parent style for this dependent style" +
                        "\n\n" +
                        "Your style depends on a parent style named {0}, which needs to be saved in the same directory.\n\n" +
                        "It appears to be available from {1}.\n" +
                        "Shall we try to download it automatically?  If you choose NO, Qiqqa will open the website for you so you can download it manually.",
                        parent_filename, parent_url
                        );

                    if (MessageBoxes.AskQuestion(message))
                    {
                        try
                        {
                            using (MemoryStream ms = UrlDownloader.DownloadWithBlocking(parent_url))
                            {
                                File.WriteAllBytes(full_parent_filename, ms.ToArray());
                            }
                        }
                        catch (UnauthorizedAccessException ex)
                        {
                            Logging.Error(ex, "You don't seem to have permission to write the new style to the directory '{0}'.\nPlease copy the original style file '{1}' to a folder where you can write (perhaps alongside your Word document), and try again.", full_parent_filename, style_xml_filename);
                            MessageBoxes.Warn("You don't seem to have permission to write the new style to the directory '{0}'.\nPlease copy the original style file '{1}' to a folder where you can write (perhaps alongside your Word document), and try again.", full_parent_filename, style_xml_filename);
                        }
                    }
                    else
                    {
                        MainWindowServiceDispatcher.Instance.OpenUrlInBrowser(parent_url, true);
                    }
                }

                // Check again if the parent file exists, and if it does, recurse the dependency check
                if (File.Exists(full_parent_filename))
                {
                    return(GetRootStyleFilename(full_parent_filename));
                }
                else
                {
                    // We need the parent style, but haven't managed to download it, so return nothing...
                    return(null);
                }
            }
            else // Not a dependent style, so use this filename
            {
                return(style_xml_filename);
            }
        }
コード例 #13
0
        private string Filename_GangList(int word_id)
        {
            string filename = String.Format(
                @"{2}/{1}/{0}.dat",
                word_id / GANG_SIZE,
                word_id / GANG_SIZE / 100,
                word_id / GANG_SIZE / 1000
                );

            return(Path.GetFullPath(Path.Combine(LIBRARY_INDEX_BASE_PATH, filename)));
        }
コード例 #14
0
        public SQLiteUpgrade_LibraryDB(string base_path)
        {
            this.base_path = base_path;
            library_path   = Path.GetFullPath(Path.Combine(base_path, @"Qiqqa.library"));

            // Copy a library into place...
            if (!File.Exists(library_path))
            {
                Logging.Warn("Library db does not exist so copying the template to {0}", library_path);
                string library_template_path = Path.GetFullPath(Path.Combine(StartupDirectoryForQiqqa, @"DocumentLibrary/Library.Template.s3db"));
                File.Copy(library_template_path, library_path);
            }
        }
コード例 #15
0
        public IntranetLibraryDB(string base_path)
        {
            this.base_path = base_path;
            library_path   = IntranetLibraryTools.GetLibraryMetadataPath(base_path);

            // Copy a library into place...
            if (!File.Exists(library_path))
            {
                Logging.Warn("Intranet Library metadata db does not exist so copying the template to {0}", library_path);
                string library_metadata_template_path = Path.GetFullPath(Path.Combine(ConfigurationManager.Instance.StartupDirectoryForQiqqa, @"DocumentLibrary/IntranetLibraryStuff/IntranetLibrary.Metadata.Template.s3db"));
                File.Copy(library_metadata_template_path, library_path);
            }
        }
コード例 #16
0
        private void LoadKnownWebLibraries(string filename, bool only_load_those_libraries_which_are_actually_present)
        {
            Logging.Info("+Loading known Web Libraries");
            try
            {
                if (File.Exists(filename))
                {
                    KnownWebLibrariesFile known_web_libraries_file = SerializeFile.ProtoLoad <KnownWebLibrariesFile>(filename);
                    if (null != known_web_libraries_file.web_library_details)
                    {
                        foreach (WebLibraryDetail new_web_library_detail in known_web_libraries_file.web_library_details)
                        {
                            Logging.Info("We have known details for library '{0}' ({1})", new_web_library_detail.Title, new_web_library_detail.Id);

                            if (!new_web_library_detail.IsPurged)
                            {
                                // Intranet libraries had their readonly flag set on the user's current premium status...
                                if (new_web_library_detail.IsIntranetLibrary ||
                                    new_web_library_detail.IsLocalGuestLibrary ||
                                    new_web_library_detail.IsWebLibrary ||
                                    new_web_library_detail.IsBundleLibrary)
                                {
                                    new_web_library_detail.IsReadOnly = false;
                                }

                                string libdir_path  = Library.GetLibraryBasePathForId(new_web_library_detail.Id);
                                string libfile_path = Path.GetFullPath(Path.Combine(libdir_path, @"Qiqqa.library"));

                                if (File.Exists(libfile_path) || !only_load_those_libraries_which_are_actually_present)
                                {
                                    UpdateKnownWebLibrary(new_web_library_detail);
                                }
                                else
                                {
                                    Logging.Info("Not loading library {0} with Id {1} as it does not exist on disk.", new_web_library_detail.Title, new_web_library_detail.Id);
                                }
                            }
                            else
                            {
                                Logging.Info("Not loading purged library {0} with id {1}", new_web_library_detail.Title, new_web_library_detail.Id);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem loading the known Web Libraries from config file {0}", filename);
            }
            Logging.Info("-Loading known Web Libraries");
        }
コード例 #17
0
        private static void MoveHomeLibraryToGuest()
        {
            try
            {
                string OLD_BASE_PATH = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Quantisle/Qiqqa"));
                if (Directory.Exists(OLD_BASE_PATH))
                {
                    string NEW_BASE_PATH = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Quantisle/Qiqqa/Guest"));

                    // Check that we have the Guest directory
                    if (!Directory.Exists(NEW_BASE_PATH))
                    {
                        Logging.Info("Guest directory does not exist, so creating it");
                        Directory.CreateDirectory(NEW_BASE_PATH);
                    }

                    // Move the documents if we have them
                    string old_documents_path = Path.GetFullPath(Path.Combine(OLD_BASE_PATH, @"documents"));
                    if (Directory.Exists(old_documents_path))
                    {
                        Logging.Info("Old style documents path exists, so moving it");
                        string new_documents_path = Path.GetFullPath(Path.Combine(NEW_BASE_PATH, @"documents"));
                        Directory.Move(old_documents_path, new_documents_path);
                    }

                    // Move the application files if we have them
                    string[] application_filenames = new string[]
                    {
                        "Qiqqa.configuration", "Qiqqa.most_recently_read", "Qiqqa.utilisation"
                    };

                    foreach (string application_filename in application_filenames)
                    {
                        string old_filename = OLD_BASE_PATH + application_filename;
                        if (File.Exists(old_filename))
                        {
                            Logging.Info("Old style filename exists, so moving it ({0})", old_filename);
                            string new_filename = Path.GetFullPath(Path.Combine(NEW_BASE_PATH, application_filename));
                            File.Move(old_filename, new_filename);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "Upgrade V003-to-V004 failure");
            }
        }
コード例 #18
0
        private void EnsureWarningFilesArePresent_TOUCH(string base_path, string filename)
        {
            string path = Path.GetFullPath(Path.Combine(base_path, filename));

            try
            {
                if (!File.Exists(path))
                {
                    File.WriteAllText(path, "");
                }
            }
            catch (Exception ex)
            {
                Logging.Warn(ex, "Problem writing Intranet Library mount point warnings (path: {0})", path);
            }
        }
コード例 #19
0
        /// <summary>
        /// This is an approximate response: it takes a *fast* shortcut to check if the given
        /// PDF has been OCR'd in the past.
        ///
        /// The emphasis here is on NOT triggering a new OCR action! Just taking a peek, *quickly*.
        ///
        /// The cost: one(1) I/O per check.
        /// </summary>
        public static bool HasOCRdata(string fingerprint)
        {
            // BasePath:
            string base_path = ConfigurationManager.Instance.ConfigurationRecord.System_OverrideDirectoryForOCRs;

            if (String.IsNullOrEmpty(base_path))
            {
                base_path = BASE_PATH_DEFAULT;
            }
            // string cached_count_filename = MakeFilename_PageCount(fingerprint);
            // return MakeFilenameWith2LevelIndirection("pagecount", "0", "txt");
            string indirection_characters = fingerprint.Substring(0, 2).ToUpper();
            string cached_count_filename  = Path.GetFullPath(Path.Combine(base_path, indirection_characters, String.Format("{0}.{1}.{2}.{3}", fingerprint, @"pagecount", @"0", @"txt")));

            return(File.Exists(cached_count_filename));
        }
コード例 #20
0
        private static Dictionary <string, PDFDocumentExportItem> Export_Docs(Library library, List <PDFDocument> pdf_documents, string base_path)
        {
            // Where the original docs go
            string doc_base_path_original = Path.GetFullPath(Path.Combine(base_path, @"docs_original"));

            Directory.CreateDirectory(doc_base_path_original);

            // Where the modified docs go
            string doc_base_path = Path.GetFullPath(Path.Combine(base_path, @"docs"));

            Directory.CreateDirectory(doc_base_path);

            Dictionary <string, PDFDocumentExportItem> pdf_document_export_items = new Dictionary <string, PDFDocumentExportItem>();

            foreach (PDFDocument pdf_document in pdf_documents)
            {
                try
                {
                    if (File.Exists(pdf_document.DocumentPath))
                    {
                        // The original docs
                        string filename_original = Path.GetFullPath(Path.Combine(doc_base_path_original, ExportingTools.MakeExportFilename(pdf_document)));
                        File.Copy(pdf_document.DocumentPath, filename_original, true);

                        // The modified docs
                        string filename = Path.GetFullPath(Path.Combine(doc_base_path, ExportingTools.MakeExportFilename(pdf_document)));
                        File.Copy(pdf_document.DocumentPath, filename, true);

                        // And the ledger entry
                        PDFDocumentExportItem item = new PDFDocumentExportItem();
                        item.pdf_document = pdf_document;
                        item.filename     = filename;
                        pdf_document_export_items[item.pdf_document.Fingerprint] = item;
                    }
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error copying file from {0}", pdf_document.DocumentPath);
                }
            }

            return(pdf_document_export_items);
        }
コード例 #21
0
 internal static string FindValidStyleFilename(string style_filename)
 {
     // If this filename no longer exists, check if we can find the same filename in the default directory
     if (File.Exists(style_filename))
     {
         return(style_filename);
     }
     else
     {
         string new_style_filename = Path.GetFullPath(Path.Combine(BASE_STYLE_DIRECTORY, Path.GetFileName(style_filename)));
         if (File.Exists(new_style_filename))
         {
             return(new_style_filename);
         }
         else
         {
             return(null);
         }
     }
 }
コード例 #22
0
        private static void MoveQiqqaLibraryFromRoamingToLocalProfile()
        {
            string folder_local_qiqqa   = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Quantisle/Qiqqa"));
            string folder_roaming_qiqqa = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Quantisle/Qiqqa"));

            string folder_local_quantisle = Path.GetFullPath(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Quantisle"));

            // First make sure that the Quantisle directory is available in the local profile directory
            if (!Directory.Exists(folder_local_quantisle))
            {
                Directory.CreateDirectory(folder_local_quantisle);
            }

            // Output some useful stats
            if (Directory.Exists(folder_roaming_qiqqa))
            {
                Logging.Info("Roaming Qiqqa directory exists");
            }
            if (Directory.Exists(folder_local_qiqqa))
            {
                Logging.Info("Local Qiqqa directory exists");
            }

            // If a roaming Qiqqa directory exists, move it to the local directory
            if (Directory.Exists(folder_roaming_qiqqa) && !Directory.Exists(folder_local_qiqqa))
            {
                Logging.Info("Moving Qiqqa directory from Roaming to Local");
                try
                {
                    Directory.Move(folder_roaming_qiqqa, folder_local_qiqqa);
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error moving Qiqqa directory from Roaming to Local");
                }
            }
            else
            {
                Logging.Info("NOT moving Qiqqa directory from Roaming to Local");
            }
        }
コード例 #23
0
        private static void Export_Directories_Titles(WebLibraryDetail web_library_detail, string base_path, Dictionary <string, PDFDocumentExportItem> pdf_document_export_items)
        {
            WshShell shell = new WshShell();

            string titles_base_path = Path.GetFullPath(Path.Combine(base_path, @"titles"));

            Directory.CreateDirectory(titles_base_path);

            foreach (var item in pdf_document_export_items.Values)
            {
                try
                {
                    string filename = Path.GetFullPath(Path.Combine(titles_base_path, FileTools.MakeSafeFilename(item.pdf_document.TitleCombined) + ".lnk"));
                    CreateShortcut(shell, item.filename, filename);
                }
                catch (Exception ex)
                {
                    Logging.Error(ex, "Error creating shortcut for " + item.filename);
                }
            }
        }
コード例 #24
0
        internal static void RunUpgrade(SplashScreenWindow splashscreen_window)
        {
            try
            {
                string OLD = Path.GetFullPath(Path.Combine(SQLiteUpgrade.BaseDirectoryForQiqqa, @"Temp"));
                string NEW = Path.GetFullPath(Path.Combine(SQLiteUpgrade.BaseDirectoryForQiqqa, @"ocr"));

                if (!Directory.Exists(NEW))
                {
                    Logging.Info("The NEW OCR directory does not exist.");
                    if (Directory.Exists(OLD))
                    {
                        Logging.Info("The OLD OCR directory does exist.  So moving it!");
                        Directory.Move(OLD, NEW);
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem upgrading OCR directory.");
            }
        }
コード例 #25
0
        internal static void RunUpgrade()
        {
            try
            {
                string OLD = Path.GetFullPath(Path.Combine(ConfigurationManager.Instance.BaseDirectoryForQiqqa, @"Temp"));
                string NEW = Path.GetFullPath(Path.Combine(ConfigurationManager.Instance.BaseDirectoryForQiqqa, @"ocr"));

                if (!Directory.Exists(NEW))
                {
                    Logging.Info("The NEW OCR directory does not exist.");
                    if (Directory.Exists(OLD))
                    {
                        Logging.Info("The OLD OCR directory does exist.  So moving it!");
                        Directory.Move(OLD, NEW);
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem upgrading OCR directory.");
            }
        }
コード例 #26
0
        private void RunItJoe()
        {
            string csl = ObjCSLEditor.Text;
            string prepared_citation_javascript = ObjJavaScriptEditor.Text;

            // Write to file for processor
            string style_file_filename = Path.GetFullPath(Path.Combine(TempFile.TempDirectoryForQiqqa, @"CSLEditor_CSL.csl"));

            File.WriteAllText(style_file_filename, csl);

            // Validate the CSL
            List <string> csl_parse_results = CSLVerifier.Verify(style_file_filename);

            if (0 < csl_parse_results.Count)
            {
                foreach (string line in csl_parse_results)
                {
                    LogMessage(line);
                }
            }

            CSLProcessor.GenerateCSLEditorCitations(style_file_filename, prepared_citation_javascript, OnBibliographyReady);
        }
コード例 #27
0
        internal static void DoCheck()
        {
            try
            {
                Logging.Info("Checking for Dropbox conflicts in {0} for machine {1}", ConfigurationManager.Instance.BaseDirectoryForQiqqa, Environment.MachineName);

                // Write our version
                string FULL_FILENAME = Path.GetFullPath(Path.Combine(ConfigurationManager.Instance.BaseDirectoryForQiqqa, PREAMBLE_FILENAME + @"." + Environment.MachineName + @".txt"));
                File.WriteAllText(FULL_FILENAME, WARNING);

                // Check for other's versions
                string[] matching_files = Directory.GetFiles(ConfigurationManager.Instance.BaseDirectoryForQiqqa, PREAMBLE_FILENAME + @"*", SearchOption.TopDirectoryOnly);
                if (1 < matching_files.Length)
                {
                    // We have a problem, Houston...

                    // Analytics it
                    FeatureTrackingManager.Instance.UseFeature(Features.Diagnostics_DropBox);

                    // Report it to user
                    NotificationManager.Instance.AddPendingNotification(
                        new NotificationManager.Notification(
                            WARNING,
                            "Danger using 3rd party cloud tools!",
                            NotificationManager.NotificationType.Warning,
                            Icons.No,
                            "I understand!",
                            IUnderstand
                            )
                        );
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, "There was a problem checking for Dropbox.");
            }
        }
コード例 #28
0
 private string MakeFilename(string file_type, object token, string extension)
 {
     return(Path.GetFullPath(Path.Combine(BasePath, String.Format("{0}.{1}.{2}.{3}", fingerprint, file_type, token, extension))));
 }
コード例 #29
0
        private string MkLegalSizedPath(string basename, string typeIdStr)
        {
            const int PATH_MAX = 240;  // must be less than 255 / 260 - see also https://kb.acronis.com/content/39790

            string root     = Path.GetDirectoryName(basename);
            string name     = Path.GetFileName(basename);
            string dataname = Path.GetFileNameWithoutExtension(DataFile);
            string ext      = SubStr(Path.GetExtension(DataFile), 1).Trim(); // produce the extension without leading dot

            if (ext.StartsWith("bib"))
            {
                ext = SubStr(ext, 3).Trim();
            }
            if (ext.Length > 0)
            {
                ext = "." + ext;
            }

            // UNC long filename/path support by forcing this to be a UNC path:
            string filenamebase = $"{dataname}.{name}{ext}{ExtensionWithDot}";

            // first make the full path without the approved/received, so that that bit doesn't make a difference
            // in the length check and subsequent decision to produce a shorthand filename path or not:

            // It's not always needed, but do the different shorthand conversions anyway and pick the longest fitting one:
            string short_tn = SanitizeFilename(CamelCaseShorthand(name));
            string short_dn = SanitizeFilename(SubStr(dataname, 0, 10) + CamelCaseShorthand(dataname));

            string hash       = StreamMD5.FromText(filenamebase).ToUpper();
            string short_hash = SubStr(hash, 0, Math.Max(6, 11 - short_tn.Length));

            // this variant will fit in the length criterium, guaranteed:
            string alt_filepath0 = Path.GetFullPath(Path.Combine(root, $"{short_dn}.{short_hash}_{short_tn}{ext}{typeIdStr}{ExtensionWithDot}"));
            string filepath      = alt_filepath0;

            // next, we construct the longer variants to check if they fit.
            //
            // DO NOTE that we create a path without typeIdStr part first, because we want both received and approved files to be based
            // on the *same* alt selection decision!

            string picked_alt_filepath = Path.GetFullPath(Path.Combine(root, $"{short_dn}.{short_hash}_{short_tn}{ext}.APPROVEDXYZ{ExtensionWithDot}"));

            name     = SanitizeFilename(name);
            dataname = SanitizeFilename(dataname);

            string alt_filepath1 = Path.GetFullPath(Path.Combine(root, $"{short_dn}_{short_hash}.{name}{ext}.APPROVEDXYZ{ExtensionWithDot}"));

            if (alt_filepath1.Length < PATH_MAX)
            {
                filepath            = Path.GetFullPath(Path.Combine(root, $"{short_dn}_{short_hash}.{name}{ext}{typeIdStr}{ExtensionWithDot}"));
                picked_alt_filepath = alt_filepath1;
            }

            // second alternative: only pick this one if it fits and produces a longer name:
            string alt_filepath2 = Path.GetFullPath(Path.Combine(root, $"{dataname}.{short_hash}_{short_tn}{ext}.APPROVEDXYZ{ExtensionWithDot}"));

            if (alt_filepath2.Length < PATH_MAX && alt_filepath2.Length > picked_alt_filepath.Length)
            {
                filepath            = Path.GetFullPath(Path.Combine(root, $"{dataname}.{short_hash}_{short_tn}{ext}{typeIdStr}{ExtensionWithDot}"));
                picked_alt_filepath = alt_filepath2;
            }
            else
            {
                // third alt: the 'optimally trimmed' test name used as part of the filename:
                int    trim_length   = PATH_MAX - alt_filepath0.Length + 10 - 1;
                string short_dn2     = SanitizeFilename(SubStr(dataname, 0, trim_length) + CamelCaseShorthand(dataname));
                string alt_filepath3 = Path.GetFullPath(Path.Combine(root, $"{short_dn2}.{short_hash}_{short_tn}{ext}{typeIdStr}{ExtensionWithDot}"));
                if (alt_filepath3.Length < PATH_MAX && alt_filepath3.Length > picked_alt_filepath.Length)
                {
                    filepath            = Path.GetFullPath(Path.Combine(root, $"{short_dn2}.{short_hash}_{short_tn}{ext}{typeIdStr}{ExtensionWithDot}"));
                    picked_alt_filepath = alt_filepath3;
                }
            }

            // fourth alt: the full, unadulterated path; if it fits in the length criterium, take it anyway
            string alt_filepath4 = Path.GetFullPath(Path.Combine(root, $"{dataname}.{name}{ext}.APPROVEDXYZ{ExtensionWithDot}"));

            if (alt_filepath4.Length < PATH_MAX)
            {
                // UNC long filename/path support by forcing this to be a UNC path:
                filepath            = Path.GetFullPath(Path.Combine(root, $"{dataname}.{name}{ext}{typeIdStr}{ExtensionWithDot}"));
                picked_alt_filepath = alt_filepath4;
            }

            return(filepath);
        }
コード例 #30
0
        private string MakeFilenameWith2LevelIndirection(string file_type, object token, string extension)
        {
            string indirection_characters = fingerprint.Substring(0, 2).ToUpper();

            return(Path.GetFullPath(Path.Combine(BasePath, indirection_characters, String.Format("{0}.{1}.{2}.{3}", fingerprint, file_type, token, extension))));
        }