Options

Locate resources after Resources Compression and Encryption

John GoldsmithJohn Goldsmith Posts: 3
edited July 17, 2013 10:46AM in SmartAssembly
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

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;
}

Comments

  • Options
    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 :)

    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
Sign In or Register to comment.