Skip to content
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

RenameItem doesn't seem to work #116

Closed
Ferroreson opened this issue Feb 26, 2024 · 3 comments
Closed

RenameItem doesn't seem to work #116

Ferroreson opened this issue Feb 26, 2024 · 3 comments

Comments

@Ferroreson
Copy link

I'm attempting to rename a CFStorage within a CFStorage. The root CFStorage is called "Relays". Within Relays is one CFStorage that I'm attempting to rename.

I pass in the Compound File as an array of bytes to ReadFileBytes, then call the RenameSettingFileEntry, then call GetRDBFileData() and write the byte array to a file. The "RenameItem" function runs without error but doesn't rename the CFStorage. Thanks for your help!

    private string DeviceRootPath = "Relays";
    private MemoryStream rdbMemoryStream;
    private CompoundFile rdbCompoundFile;

    private void ReadFileBytes(byte[] fileData)
    {
        rdbMemoryStream = new MemoryStream(fileData);  
        if (rdbCompoundFile != null)
        {
            rdbCompoundFile.Close();
            rdbCompoundFile = null;
        }
        rdbCompoundFile = new CompoundFile(rdbMemoryStream, CFSUpdateMode.ReadOnly, CFSConfiguration.Default);
    }
    public void RenameSettingFileEntry(string OldName, string NewName)
    {
        var DeviceRootEntry = (CFStorage)rdbCompoundFile.GetAllNamedEntries(DeviceRootPath).First();
        DeviceRootEntry.RenameItem(OldName, NewName);
    }
    public byte[] GetRDBFileData()
    {
        MemoryStream s = new MemoryStream();
        rdbCompoundFile.Save(s);

        return s.ToArray();
    }
@Ferroreson
Copy link
Author

Bug isn't with OpenMCDF.

@ironfede
Copy link
Owner

This should work.
You can change a storage from its parent storage.

CompoundFile cf = new CompoundFile();
cf.RootStorage.AddStorage("AStorage")
    .AddStream("AStream")
    .SetData(Helpers.GetBuffer(100));

cf.SaveAs("Hello$File");
cf.Close();

CompoundFile cf1 = new CompoundFile("Hello$File", CFSUpdateMode.Update, CFSConfiguration.Default);
try
{
    cf1.RootStorage.RenameItem("AStorage", "NewStorage");
    cf1.Commit();
    cf1.Close();
}
catch (Exception ex)
{
   Assert.Fail(ex.Message);
}

Kind Regards,
Federico

@Ferroreson
Copy link
Author

Ferroreson commented Feb 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants