Red Gate forums :: View topic - Locate resources after Resources Compression and Encryption
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SmartAssembly 6
SmartAssembly 6 forum

Locate resources after Resources Compression and Encryption

Search in SmartAssembly 6 forum
Post new topic   Reply to topic
Jump to:  
Author Message
John Goldsmith



Joined: 17 Jul 2013
Posts: 2

PostPosted: Wed Jul 17, 2013 1:15 pm    Post subject: Locate resources after Resources Compression and Encryption Reply with quote

Hi,

I'm trying to locate resources following checking 'Resources Compression and Encryption' (in SmartAssembly Professional 6.8.0.121) and while I can reach them by directly naming them, I'm unable to using LINQ to collect a sub-set - something I was able to do prior to using the feature.

Below is an example snippet that demonstrates the problem. 'btnReadResources_Click' returns the expected results, but 'btnFindResources_Click' does not. Is there a good way around this problem, where I can filter the available encrypted resources based on part of the namespace?.

Best regards

John


Code:
private void btnReadResources_Click(object sender, RoutedEventArgs e)
{
    var assembly = Assembly.GetExecutingAssembly();
    txtAOutput.Text = "";
    txtBOutput.Text = "";
           
    txtAOutput.Text = txtAOutput.Text + "\n" + GetResText(assembly, "TestEmbeddedResources.MyResFolder.A.FldrA1.TxtA1.txt");
    txtAOutput.Text = txtAOutput.Text + "\n" + GetResText(assembly, "TestEmbeddedResources.MyResFolder.A.FldrA2.TxtA2.txt");
    txtAOutput.Text = txtAOutput.Text + "\n" + "[Done]";

    txtBOutput.Text = txtBOutput.Text + "\n" + GetResText(assembly, "TestEmbeddedResources.MyResFolder.B.FldrB1.TxtB1.txt");
    txtBOutput.Text = txtBOutput.Text + "\n" + GetResText(assembly, "TestEmbeddedResources.MyResFolder.B.FldrB2.TxtB2.txt");
    txtBOutput.Text = txtBOutput.Text + "\n" + GetResText(assembly, "TestEmbeddedResources.MyResFolder.B.FldrB3.TxtB3.txt");
    txtBOutput.Text = txtBOutput.Text + "\n" + "[Done]";
}

       

private void btnFindResources_Click(object sender, RoutedEventArgs e)
{
    var assembly = Assembly.GetExecutingAssembly();
    txtAOutput.Text = "";
    txtBOutput.Text = "";


    var stdResNames = assembly.GetManifestResourceNames()
                        .Where(name => name.StartsWith("TestEmbeddedResources.MyResFolder.A."));

    foreach (var stdResName in stdResNames)
    {
        AddResString(txtAOutput, GetResText(assembly, stdResName));
    }
    AddResString(txtAOutput, "[Done]");



    var proResNames = assembly.GetManifestResourceNames()
                        .Where(name => name.StartsWith("TestEmbeddedResources.MyResFolder.B."));

    foreach (var proResName in proResNames)
    {
        AddResString(txtBOutput, GetResText(assembly, proResName));
    }
    AddResString(txtBOutput, "[Done]");
}

private string GetResText(Assembly assembly, string resName)
{
    string result;
    using (var stream = assembly.GetManifestResourceStream(resName))
    using (var reader = new StreamReader(stream))
    {
            result = reader.ReadToEnd();
    }
    return result;
}

private void AddResString(TextBox txtBx, string strRes)
{
    txtBx.Text = txtBx.Text + "\n" + strRes;
}


Last edited by John Goldsmith on Wed Jul 17, 2013 3:46 pm; edited 1 time in total
Back to top
View user's profile Send private message
John Goldsmith



Joined: 17 Jul 2013
Posts: 2

PostPosted: Wed Jul 17, 2013 3:46 pm    Post subject: Reply with quote

Ok, so I'm going to answer my own question as I've now spotted that the docs for 'Resources Compression and Encryption' state that you can't use it with GetManifestResourceNames, which I am.

Interestingly, if you just loop through the array returned by GetManifestResourceNames then you end up with a single name (a GUID) of the compressed and encrypted resource. Well I suppose I understand the process better now Smile

I guess, on reflection (small pun intended), I'm really after encryption but not compression, or at least the means to 'lookup' encrypted resources by name.

Anyway, I hope that help anyone else looking at the feature.

Best regards

John
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group