예제 #1
0
        /// <summary>
        /// Formats string and replaces placeholders with actual values
        /// </summary>
        /// <param name="Format"></param>
        /// <returns></returns>
        public string FormatLine(string Format)
        {
            Dictionary <string, string> replacementTable = new Dictionary <string, string>
            {
                { "i", (Index + 1).ToString() },
                { "l", FeedUrl?.ToString() },
                { "n", Configuration.Instance.GetReadState(UnreadItems > 0) },
                { "U", UnreadItems.ToString() },
                { "T", TotalItems.ToString() },
                { "u", (UnreadItems.ToString() + "/" + TotalItems.ToString()).PadLeft(8) },
                { "t", Title },
                { "V", Configuration.MAJOR_VERSION },
                { "v", Configuration.VERSION },
                { "g", (Tags != null ? string.Join(" ", Tags) : "") }
            };

            var line = Formatter.FormatLine(Format, replacementTable);

            if (this.IsProcessing)
            {
                return(Configuration.Instance.LoadingPrefix + line + Configuration.Instance.LoadingSuffix);
            }
            else
            {
                return(line);
            }
        }
예제 #2
0
        /// <summary>
        /// Formats string for display by replacing placeholder strings with actual values.
        /// </summary>
        /// <param name="Format">The <see cref="string"/></param>
        /// <returns>The <see cref="string"/></returns>
        public string FormatLine(string Format)
        {
            Dictionary <string, string> replacementTable = new
                                                           Dictionary <string, string>
            {
                { "i", (Index + 1).ToString() },
                { "n", Configuration.Instance.GetReadState(this.IsNew) },
                { "D", Configuration.Instance.GetDownloadState(this.IsDownloaded) },
                { "x", Configuration.Instance.GetDeletedState(this.Deleted) }, //only shown when article is marked as deleted, afterwards filtered out
                { "d", PublishDate.ToString(dateFormat) },
                { "u", LastUpdated.ToString(dateFormat) },
                { "t", Title },
                { "s", Summary },
                { "l", FeedUrl.ToString() },
                { "V", Configuration.MAJOR_VERSION },
                { "v", Configuration.VERSION }
            };
            var line = Formatter.FormatLine(Format, replacementTable);

            if (this.IsProcessing)
            {
                return(Configuration.Instance.LoadingPrefix + line +
                       Configuration.Instance.LoadingSuffix);
            }
            else
            {
                return(line);
            }
        }
예제 #3
0
        private string FormatFileName(string format)
        {
            var fullPath = format
                           .Replace("%i", Index.ToString().PadLeft(3))
                           .Replace("%n", Configuration.Instance.GetReadState(this.IsNew))
                           .Replace("%d", PublishDate.ToString(dateFormat))
                           .Replace("%t", Title)
                           .Replace("%l", FeedUrl.ToString());

            var    pathEndsAt = fullPath.LastIndexOf('\\');
            string result;

            if (pathEndsAt > 0)
            {
                var pathOnly     = fullPath.Substring(0, pathEndsAt).SanitizePath();
                var fileNameOnly = fullPath.Substring(pathEndsAt,
                                                      fullPath.Length - pathEndsAt).SanitizeFileName();

                //Limit full path length to 260 chars to avoid System.IO.PathTooLongException
                if (System.IO.Path.GetFullPath(pathOnly).Length + fileNameOnly.Length
                    > 260)
                {
                    int    dotPosition = fileNameOnly.LastIndexOf(".", StringComparison.InvariantCulture);
                    string fileName    = fileNameOnly.Substring(0, dotPosition);
                    string extension   = fileNameOnly.Substring(dotPosition,
                                                                fileNameOnly.Length - dotPosition);
                    fileNameOnly = fileName.Substring(0,
                                                      fileName.Length - System.IO.Path.GetFullPath(pathOnly).Length -
                                                      extension.Length) + extension;
                }
                result = pathOnly + "\\" + fileNameOnly;
            }
            else
            {
                result = fullPath.SanitizeFileName();
            }

            if (!Path.IsPathRooted(result))
            {
                result = System.IO.Path.GetFullPath(result);
            }

            return(result);
        }