Skip to content

Commit

Permalink
- fixed a bug in Fix Documents, was copying the wrong fixed file
Browse files Browse the repository at this point in the history
  • Loading branch information
desjarlais committed Oct 13, 2023
1 parent 9ad1ba9 commit 50702b0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
14 changes: 11 additions & 3 deletions Office File Explorer/Helpers/Office.cs
Original file line number Diff line number Diff line change
Expand Up @@ -472,15 +472,23 @@ public static bool RemoveCustomXmlParts(Package pkg, string path, string app)
}
}

// step 3. delete the cd for presentation.xml
// step 3. delete the cd for notesmasters
IEnumerable<CustomerData> cdNmSpList = presDoc.PresentationPart.NotesMasterPart.NotesMaster.CommonSlideData.ShapeTree.NonVisualGroupShapeProperties.Descendants<CustomerData>();
foreach (CustomerData cd in cdNmSpList)
{
cd.Remove();
isFixed = true;
}

// step 4. delete the cd for presentation.xml
IEnumerable<CustomerData> cdListPresPart = presDoc.PresentationPart.Presentation.Descendants<CustomerData>().ToList();
foreach (CustomerData cd in cdListPresPart)
{
cd.Remove();
isFixed = true;
}

// step 4. remove the custom xml parts
// step 5. remove the custom xml parts
if (presDoc.PresentationPart.CustomXmlParts is not null)
{
foreach (CustomXmlPart cxp in presDoc.PresentationPart.CustomXmlParts)
Expand All @@ -492,7 +500,7 @@ public static bool RemoveCustomXmlParts(Package pkg, string path, string app)
}
}

// step 5. make sure the customxml files were deleted
// step 6. make sure the customxml files were deleted
bool containsCustomXml = false;

// todo / workaround: still looking into some files where the above customxmlpart deletepart does not work
Expand Down
10 changes: 10 additions & 0 deletions Office File Explorer/Helpers/WordFixes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,11 @@ public static bool FixTextboxes(string filePath)

foreach (Drawing d in drwList)
{
if (d.Anchor is null)
{
continue;
}

// first get the list of id's
foreach (OpenXmlElement oxe in d.Anchor.ChildElements)
{
Expand All @@ -1594,6 +1599,11 @@ public static bool FixTextboxes(string filePath)
restartDrawingLoop:
foreach (Drawing d in drwList)
{
if (d.Anchor is null)
{
continue;
}

foreach (OpenXmlElement oxe in d.Anchor.ChildElements)
{
if (oxe.LocalName == "docPr")
Expand Down
3 changes: 1 addition & 2 deletions Office File Explorer/WinForms/FrmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2368,11 +2368,10 @@ private void toolStripButtonFixDoc_Click(object sender, EventArgs e)
}

// if any corruptions were found, copy the file to a new location and display the fixes and new file path
rtbDisplay.Clear();
if (corruptionFound)
{
string modifiedPath = AddTextToFileName(toolStripStatusLabelFilePath.Text, " (Fixed)");
File.Copy(toolStripStatusLabelFilePath.Text, modifiedPath, true);
File.Copy(tempFilePackageViewer, modifiedPath, true);
rtbDisplay.Text = sbFixes.ToString();
rtbDisplay.AppendText("\r\n\r\nModified File Location = " + modifiedPath);
}
Expand Down

0 comments on commit 50702b0

Please sign in to comment.