-
-
Notifications
You must be signed in to change notification settings - Fork 6
Add OpenLiveWriterPost project and writer DLLs #470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0-windows</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <UseWindowsForms>true</UseWindowsForms> | ||
| <PlatformTarget>x86</PlatformTarget> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="System.Drawing.Common" Version="8.0.0" /> | ||
| <Reference Include="OpenLiveWriter.CoreServices"> | ||
| <HintPath>..\dlls\Writer\OpenLiveWriter.CoreServices.dll</HintPath> | ||
| </Reference> | ||
| <Reference Include="OpenLiveWriter.Extensibility"> | ||
| <HintPath>..\dlls\Writer\OpenLiveWriter.Extensibility.dll</HintPath> | ||
| </Reference> | ||
| <Reference Include="OpenLiveWriter.PostEditor"> | ||
| <HintPath>..\dlls\Writer\OpenLiveWriter.PostEditor.dll</HintPath> | ||
| </Reference> | ||
| <Reference Include="OpenLiveWriter.Interop"> | ||
| <HintPath>..\dlls\Writer\OpenLiveWriter.Interop.dll</HintPath> | ||
| <Private>true</Private> | ||
| </Reference> | ||
|
|
||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| using OpenLiveWriter.CoreServices; | ||
| using OpenLiveWriter.Extensibility.BlogClient; | ||
| using OpenLiveWriter.PostEditor; | ||
| using System.Reflection; | ||
|
|
||
| namespace OpenLiveWriterPost; | ||
|
|
||
| internal class OpenLiveWriterPostGenerator | ||
| { | ||
|
|
||
|
|
||
| public static void SavePost(BlogPost post, string filePath) | ||
| { | ||
| SavePostAsStructuredStorage(post, filePath); | ||
| } | ||
|
|
||
| private static void SavePostAsStructuredStorage(BlogPost post, string filePath) | ||
| { | ||
| ApplicationEnvironment.Initialize(Assembly.GetExecutingAssembly(), | ||
| Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"Windows Live\Writer")); | ||
|
|
||
| PostEditorFile.Initialize(); | ||
|
|
||
| string? directoryPath = Path.GetDirectoryName(filePath); | ||
| if (string.IsNullOrEmpty(directoryPath)) | ||
| { | ||
| directoryPath = Directory.GetCurrentDirectory(); | ||
| } | ||
|
|
||
| DirectoryInfo targetDirectory = new DirectoryInfo(directoryPath); | ||
| string[] existingDrafts = Directory.GetFiles(targetDirectory.FullName, "*.wpost"); | ||
|
|
||
| PostEditorFile pef = PostEditorFile.CreateNew(targetDirectory); | ||
| var bef = new BlogPostEditingContext(post.Id, post); | ||
| pef.SaveBlogPost(bef); | ||
|
|
||
| string createdDraftPath = FindCreatedDraftPath(targetDirectory.FullName, existingDrafts); | ||
| if (!string.Equals(createdDraftPath, filePath, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| if (File.Exists(filePath)) | ||
| { | ||
| File.Delete(filePath); | ||
| } | ||
|
|
||
| File.Move(createdDraftPath, filePath); | ||
| } | ||
| } | ||
|
|
||
| private static string FindCreatedDraftPath(string directoryPath, string[] existingDrafts) | ||
| { | ||
| string[] currentDrafts = Directory.GetFiles(directoryPath, "*.wpost"); | ||
|
|
||
| foreach (string currentDraft in currentDrafts) | ||
| { | ||
| bool existedBefore = false; | ||
| foreach (string existingDraft in existingDrafts) | ||
| { | ||
| if (string.Equals(currentDraft, existingDraft, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| existedBefore = true; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!existedBefore) | ||
| { | ||
| return currentDraft; | ||
| } | ||
| } | ||
|
|
||
| throw new IOException($"Unable to determine the draft file created in '{directoryPath}'."); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,76 @@ | ||||||||||||||||||||||||||||||||||||||||||||||
| using OpenLiveWriter.Extensibility.BlogClient; | ||||||||||||||||||||||||||||||||||||||||||||||
| using OpenLiveWriter.Extensibility.ImageEditing; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| namespace OpenLiveWriterPost; | ||||||||||||||||||||||||||||||||||||||||||||||
| public static class WritePost | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| public static void GeneratePostFromHtml(string name, string html) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| var draftsFolder1 = GetOpenLiveWriterDraftsFolder(); | ||||||||||||||||||||||||||||||||||||||||||||||
| var post1 = new BlogPost | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| Id = Guid.NewGuid().ToString("D"), | ||||||||||||||||||||||||||||||||||||||||||||||
| Title = name, | ||||||||||||||||||||||||||||||||||||||||||||||
| DatePublished = DateTime.Now.AddDays(10), | ||||||||||||||||||||||||||||||||||||||||||||||
| DatePublishedOverride = DateTime.Now.AddDays(10), | ||||||||||||||||||||||||||||||||||||||||||||||
| Contents = html, | ||||||||||||||||||||||||||||||||||||||||||||||
| //Categories = [ "Programming", "C#", "Blogging" ], | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
| // Save the post | ||||||||||||||||||||||||||||||||||||||||||||||
| var safeTitle = SanitizeFileName(post1.Title); | ||||||||||||||||||||||||||||||||||||||||||||||
| var fileName1 = $"{safeTitle}.wpost"; | ||||||||||||||||||||||||||||||||||||||||||||||
| var filePath1 = Path.Combine(draftsFolder1, fileName1); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| if(File.Exists(filePath1)) File.Delete(filePath1); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| Console.WriteLine("Creating hardcoded blog post..."); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| OpenLiveWriterPostGenerator.SavePost(post1, filePath1); | ||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+25
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid deleting the existing draft before confirming save succeeds. Line 25 deletes the existing Suggested fix- if(File.Exists(filePath1)) File.Delete(filePath1);
-
- Console.WriteLine("Creating hardcoded blog post...");
-
- OpenLiveWriterPostGenerator.SavePost(post1, filePath1);
+ var backupPath = filePath1 + ".bak";
+ if (File.Exists(filePath1))
+ File.Copy(filePath1, backupPath, overwrite: true);
+
+ Console.WriteLine("Creating hardcoded blog post...");
+
+ try
+ {
+ OpenLiveWriterPostGenerator.SavePost(post1, filePath1);
+ if (File.Exists(backupPath)) File.Delete(backupPath);
+ }
+ catch
+ {
+ if (File.Exists(backupPath))
+ File.Move(backupPath, filePath1, overwrite: true);
+ throw;
+ }📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| static string SanitizeFileName(string? name) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| var sanitizedName = (name ?? string.Empty).Trim(); | ||||||||||||||||||||||||||||||||||||||||||||||
| foreach (var invalidChar in Path.GetInvalidFileNameChars()) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| sanitizedName = sanitizedName.Replace(invalidChar, '_'); | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| return string.IsNullOrWhiteSpace(sanitizedName) ? "untitled" : sanitizedName; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| static string GetOpenLiveWriterDraftsFolder() | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| // OpenLive Writer drafts are typically stored in: | ||||||||||||||||||||||||||||||||||||||||||||||
| // %USERPROFILE%\Documents\My Weblog Posts\Drafts | ||||||||||||||||||||||||||||||||||||||||||||||
| // or | ||||||||||||||||||||||||||||||||||||||||||||||
| // %LOCALAPPDATA%\OpenLiveWriter\Drafts | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| var userProfile = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); | ||||||||||||||||||||||||||||||||||||||||||||||
| var documentsPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); | ||||||||||||||||||||||||||||||||||||||||||||||
| var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // Try different possible locations for OpenLive Writer drafts | ||||||||||||||||||||||||||||||||||||||||||||||
| var possiblePaths = new[] | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| Path.Combine(documentsPath, "My Weblog Posts", "Drafts"), | ||||||||||||||||||||||||||||||||||||||||||||||
| Path.Combine(localAppData, "OpenLiveWriter", "Drafts"), | ||||||||||||||||||||||||||||||||||||||||||||||
| Path.Combine(userProfile, "Documents", "My Weblog Posts", "Drafts"), | ||||||||||||||||||||||||||||||||||||||||||||||
| Path.Combine(localAppData, "Open Live Writer", "Drafts") | ||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| foreach (var path in possiblePaths) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| if (Directory.Exists(path)) | ||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||
| Console.WriteLine($"Using existing OpenLive Writer drafts folder: {path}"); | ||||||||||||||||||||||||||||||||||||||||||||||
| return path; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||
| // If none exist, create the default one | ||||||||||||||||||||||||||||||||||||||||||||||
| var defaultPath = Path.Combine(documentsPath, "My Weblog Posts", "Drafts"); | ||||||||||||||||||||||||||||||||||||||||||||||
| Console.WriteLine($"Creating OpenLive Writer drafts folder: {defaultPath}"); | ||||||||||||||||||||||||||||||||||||||||||||||
| Directory.CreateDirectory(defaultPath); | ||||||||||||||||||||||||||||||||||||||||||||||
| return defaultPath; | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <runtime> | ||
| <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-1.39.0.0" newVersion="1.39.0.0" /> | ||
| </dependentAssembly> | ||
| </assemblyBinding> | ||
| <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Google.Apis" publicKeyToken="4b01fa6e34db77ab" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-1.39.0.0" newVersion="1.39.0.0" /> | ||
| </dependentAssembly> | ||
| </assemblyBinding> | ||
| <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" /> | ||
| </dependentAssembly> | ||
| </assemblyBinding> | ||
| </runtime> | ||
| </configuration> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <runtime> | ||
| <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Google.Apis.Core" publicKeyToken="4b01fa6e34db77ab" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-1.39.0.0" newVersion="1.39.0.0" /> | ||
| </dependentAssembly> | ||
| </assemblyBinding> | ||
| <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Google.Apis" publicKeyToken="4b01fa6e34db77ab" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-1.39.0.0" newVersion="1.39.0.0" /> | ||
| </dependentAssembly> | ||
| </assemblyBinding> | ||
| <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | ||
| <dependentAssembly> | ||
| <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | ||
| <bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" /> | ||
| </dependentAssembly> | ||
| </assemblyBinding> | ||
| </runtime> | ||
| </configuration> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <configuration> | ||
| <startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup></configuration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: ignatandrei/RSCG_Examples
Length of output: 862
Platform configuration mismatch between solution and project files.
The solution (v2/Generator.sln) maps the
OpenLiveWriterPostproject toAny CPUconfiguration, while the project file specifies<PlatformTarget>x86</PlatformTarget>and the manifest declaresprocessorArchitecture="X86". This mismatch will cause build inconsistencies or runtime issues, particularly with the x86-specific OpenLiveWriter dependencies.Resolve by either:
x86, orPlatformTargettoAnyCPU(if compatible with x86-specific dependencies)🤖 Prompt for AI Agents