Can JSFL be used to set a Global Include script? - animate-cc

We are converting several thousand .FLA files from SWF (Flash CS6) to HTML5 Canvas (Animate CC format). I have already written a JSFL script that automates the process:
Converts Compiled Clips to HTML5-friendly objects
Converts document to HTML5 Canvas format
Associates a new Publish Profile and HTML template with the document
Changes the publish filenames
So, the hard part is done! But I want to optimize it a bit more.
The current HTML template has some shared utility functions. The utility functions add 5-10kb to the file size of each animation, which themselves are probably in the 20-50kb range.
I would rather include these utility functions by setting a Global Include script, going to the top-left of the Actions panel, selecting Include, and adding a script with the + key. (When I'm done, it will show the URI underneath Global Script)
This produces the output I want, and it's perfect! The only downside is, I have to do this manually -- I'd like a way to associate the .JS file as a Global Include when running my JSFL conversion script.
Does anyone know of a JSAPI method to retrieve or set a Global Include script in HTML5 Canvas documents?
I haven't been able to find any documentation on such a function in JSFL/JSAPI. It doesn't seem like setting the scripts leaves a trace in the History pane, so I'm at a loss here.

Related

Which procedure in Moqui transforms XML Screen into script?

I would like to see what is happening behind the scenes when the engine transforms XML file with screen definition into Groovy (I suppose) script. So that I can see the definition turning into more readable script, hopefully.
Where shall I place the breakpoint while debugging?
Also, in Tools (/apps/tools/Service) if you click on 'Service detail' you get a nicely rendered view of the generated groovy for any of your services called from screens (or otherwise called). 'Services' are a very intuitive unit for debugging in moqui.
XML Screens are not transformed into scripts like XML Actions are. XML Screens and Forms are transformed by FreeMarker macros into the desired output text (html, xsl-fo, csv, etc). These macros are defined in the DefaultScreenMacros.html.ftl file for html output, and similarly named files (in the runtime/template/screen-macro directory) for other types of output.

How to build with a custom eglfs cursor atlas?

I'm trying to change the eglfs mouse cursor graphics for my embedded linux QT application (QT5.5). I have the new cursor atlas PNG and the new JSON descriptor file, but the documentation is rather vague:
".. a custom cursor atlas can be provided by setting the QT_QPA_EGLFS_CURSOR environment variable to the name of a JSON file. The file can also be embedded into the application via Qt's resource system."
I'd prefer to keep everything within the resource system if possible but I can't work out how to do it.. do I need a specific qrc file containing the path to the JSON file? I assume that the PNG file would also need to be added as a resource so that it gets built into the application?
If adding it via the resource system is a bad idea where's the correct place to set the QT_QPA_EGLFS_CURSOR environment variable? I'm currently specifying the platform on the command line via "-platform eglfs"; will this be ok or will I need to set the platform to eglfs in the build?
After much trial, error and digging around I have found the solution that I was looking for within the resource system.
Create a new resource file called "cursor.qrc", the contents of which needs to be two lines:
path/to/your/custom-cursor-atlas.png
cursor.json
The first line (path to your cursor atlas) must be relative to your resource directory.
You then need to put the JSON file (contents as described in the documentation) in the root of your resource directory. It must be called "cursor.json", and its image location line must must match the location in your new resource file and be of the format:
"image": ":/path/to/your/custom-cursor-atlas.png",
This will then include your cursor atlas in resources, and Qt will find it when your application starts.
Run time solution example:
export XDG_RUNTIME_DIR=~
export QT_QPA_EGLFS_CURSOR=~/cursor.json
In the cursor.json:
"image": "cursor.png",
Put your custom cursor.png atlas into your home dir (~) then run the Qt app from there.

How to install Yii imagesgallerymanager extension

I am trying to create a image gallery and I found the following extension:
http://www.yiiframework.com/extension/imagesgallerymanager/
I chose this extenion because it is the best evaluated. My problem is that I don't understand how to install it. I am new using Yii, so I'm lost.
The instrunctions are these:
Checkout source code to your project, for example to ext.galleryManager.
Install and configure image component(https://bitbucket.org/z_bodya/yii-image).
Add tables for gallery into database (there is sql scheme and migration samples in migrations folder in extension)
Import gallery models to project, by adding "ext.galleryManager.models.*" to import in config/main.php
Add GalleryController to application or module controllerMap.
Configure and save gallery model
Render widget for gallery
Please, someone could to explain how to install and configure image component to me? I don't understand where I have to put the code. The instruction about how to do it, says something like this:
application main config components
'image'=>array(
'class'=>'application.extensions.image.CImageComponent',
// GD or ImageMagick
'driver'=>'GD',
// ImageMagick setup path
'params'=>array('directory'=>'D:/Program Files/ImageMagick-6.4.8-Q16'),
),
调用方法():
$image = Yii::app()->image->load('images/test.jpg');
$image->resize(400, 100)->rotate(-45)->quality(75)->sharpen(20);
$image->save(); // or $image->save('images/small.jpg');
第二种:
Yii::import('application.extensions.image.Image');
$image = new Image('images/test.jpg');
$image->resize(400, 100)->rotate(-45)->quality(75)->sharpen(20);
$image->render();
Should I to paste the previous code in ../config/main.php? Sorry but I am a bit confussed
Thank you very much.
I would recommend you to git clone the yii-demo-blog from z_bodya (a yii developer). There are already implementations of his yii extensions (image-attachment, image-gallery, tinymce+elfinder), using this command:
git clone https://bitbucket.org/z_bodya/yii-demo-blog.git
then follow the instruction on that page https://bitbucket.org/z_bodya/yii-demo-blog.
Then study the workflow of his galleryManager at https://bitbucket.org/z_bodya/gallerymanager
Also read books on Yii, I recommend:
Web Application Development with Yii and PHP
Author: Jeffrey Winesett
http://www.amazon.com/dp/1849518726?tag=gii20f-20
Yii Application Development Cookbook
Author: Alexander Makarov
http://www.amazon.com/dp/B00BKZHDGS?tag=gii20f-20
It looks correct. Can you please make sure that entry 'images' is within the 'components' array? Your config file (main.php) should look like this:
//other options
'components' => array(
'image' => array(
'class'=>'application.extensions.image.CImageComponent',
// GD or ImageMagick
'driver'=>'GD',
// ImageMagick setup path
'params'=>array('directory'=>'D:/Program Files/ImageMagick-6.4.8-Q16'),
),
//.. other components
)
You call $image->render() to show the actual image. It should be in the controller or view file.
You call Yii::import() before you use the class. This is done so that Yii knows where to find your class.
Before you start
Here are some initial points, you should go through, to learn, if this extension is for you:
If you're not sure, if yii-gallery-manager extension is for you and want to play a little bit with this, before incorporating it into your application, then follow to "Demo application" section at the end of this text.
Gallery Manager is only a set of widgets, models, behaviors and controllers, which provides gallery management functionality to your own models and modules. It is not a ready, out-of-the box solution in form of entire module for managing galleries. Plus, it is also gallery manager only. It is meant for backend and does not provide you with anything special for frontend. You must write your own code for presenting particular gallery basing on data provided by yii-gallery-manager extension.
Because galleries are attached to one of your models and are kept in separate tables, using Gallery Manager widget causes changes to be immediately on-line. In other word, user editing any model doesn't have to save it or can even cancel editing it, but changes made by him/her in Gallery Manager are immediately sent (via AJAX), immediately stored in database and are public at once. You should probably pass this information to users of your application. And even consider some implementation, that will make post invisible, if user is editing it and changing galleries.
Gallery Manager extension is backed-up by quite powerful yii-image extension (actually a Yii port of famous Kohana image manipulation class) and offers you automated generation of previews for each uploaded image, including many cool graphical effects and image transformations.
Extension uses Twitter Bootstrap styles. If you're using it in your application as well, you'll have gallery manager matching styles of your entire application. If you don't use Bootstrap, you don't need to install it (yii-gallery-manager requires only bootstrap.css file as it uses styles from it), but you'll probably have gallery manager in different styling than rest of your application.
If you're convinced to use this extension, then continue reading. If resign, you can scroll to the end of this text, where I put some alternatives.
Preparation stage
To install and use this extension in your application you need:
yii-gallery-manager extension itself,
yii-image extension,
Twitter Bootstrap's styles.
Main repository (at BitBucket) for both extensions are not clonable due to some bug. You should use files added to Download section in extension page at yiiframework.com or alternatively (for main extension only) mirror code repository at GitHub.
Decompress their contents into extensions folder in your application and optionally, change their folders' names.
As for Twitter Bootstrap, you only need it's styles (bootstrap.css) which are used by extension. You don't need entire library.
After unpacking yii_image extension, you need to add it's configuration to your application's configuration array (in protected/config/main.php, if you didn't change this).
It should be:
'image'=>array
(
'class'=>'application.extensions.image.CImageComponent',
'driver'=>'GD'
)
if you want to use default PHP's GD library for image processing, or:
'image'=>array
(
'class'=>'application.extensions.image.CImageComponent',
'driver'=>'ImageMagick',
'params'=>array('directory'=>'D:/Program Files/ImageMagick-6.4.8-Q16')
)
if you want to use ImageMagick library.
Double check, if path/alias (application.extensions.image here) are correct and valid. Most operations in yii-gallery-manager extension are made via POST/AJAX and debugging them is a little bit harder. Wrong path/alias to yii-image extension is first source of problems with Gallery Manager not uploading images correctly.
Adding yii-gallery-manager to your application
I decided to use behavior-based approach, because using behaviors is more flexible.
Here are steps, that I took to add yii-gallery-manager to my application:
Download (and unpack to extensions folder) yii-gallery-manager and yii-image extension, if you haven't done this yet.
Go to migrations folder in yii-gallery-manager and either import schema.mysql.sql to your SQL database or use contents of schema.migration file as base for your new migration (yiic create [name]) and save it. Consider changes discussed later (Using migrations section). Finally, run the migration (yiic migrate).
Add ext.yiiimage.*, ext.gallerymanager.* and ext.gallerymanager.models.* to import section of your application's configuration array. Adjust path to these extensions accordingly to where you put them.
Add image extension to components section of your configuration array (see above).
Consider updating yii-gallery-manager and yii-image extension with files found in demo application (see below) as they seems to be a bit newer.
Copy GalleryController.php from yii-gallery-manager extension's folder to location of your controllers (usually protected/controllers) or keep it in original place and add this to main configuration of your application:
'controllerMap'=>array
(
'gallery'=>'ext.gallerymanager.GalleryController'
),
Adding behavior and views
Now, your application should be ready to use this extension. All, that is left is to add behavior to your model:
public function behaviors()
{
return array
(
'galleryBehavior'=>array
(
'class'=>'GalleryBehavior',
'idAttribute'=>'gallery_id',
'versions'=>array
(
'small'=>array
(
'centeredpreview'=>array(98, 98)
),
'medium'=>array
(
'resize'=>array(800, NULL)
)
),
'name'=>TRUE,
'description'=>TRUE
)
);
}
Where name and description decides whether you want to save these kind of data along with each of your gallery to database and idAttribute refers to field in your model, which will store foreign key to gallery. For information about versions, refer to next chapter.
Finally, modify your views. Extension comes with ready widget for managing image galleries:
<?php if($model->galleryBehavior->getGallery() === NULL): ?>
<p>Before add photos to product gallery, you need to save the product first.</p>
<?php else: ?>
<?php $this->widget('GalleryManager', array
(
'gallery' => $model->galleryBehavior->getGallery(),
)); ?>
<?php endif; ?>
As for presenting image galleries in front end, you're completely on your own. This is backend's gallery manager, not full solution, right. So, as for frontend, it offers you nothing more, than a pure array of data, with which you can do whatever you need or want:
<?php $photos = $content->galleryBehavior->getGalleryPhotos(); ?>
Tuning up
Files, folders and paths
By default, yii-gallery-manager uploads all gallery-related images to gallery folder in web-root of your application. This setting is stored as galleryDir property of GalleryPhoto. I don't know, what reasons caused extension's author to store path to galleries directly in each photo model, instead of Gallery model or even inside GalleryManager widget. But, it is like it is.
And, due to construction of this extension (based on widgets and behavior attached to your own model, operating on POST/AJAX only) there is no way to modify this setting dynamically, in your application. If you need to change directory for your gallery images, you need to simply alter public $galleryDir = 'gallery'; line in GalleryPhoto model.
Auto-generated versions (previews)
Using versions key in galleryBehavior array you can declare, how many (and in what dimensions) previews will be auto-generated for each uploaded image. It is an array like this:
'versions'=>array
(
'small'=>array
(
'centeredpreview'=>array(98, 98)
),
'medium'=>array
(
'resize'=>array(800, NULL)
)
)
Each element in master array represents one preview generated automatically for each image upload. For each preview you can set as many operations, as you want. Each operation (subarray key -- for example centeredpreview) refers to selected image operation -- a method found in Image class in yii-image_ extension. Subarray value is an array of arguments passed to this method (operation parameters).
Examples for resizing preview:
'resize'=>array(500, 500) will resize image to fixed 500 x 500 pixels dimensions, ignoring its original aspect ratio,
'resize'=>array(800, NULL) will resize image to have longer edge set to 800 pixels and shorter edge relatively to original image ratio,
'centeredpreview'=>array(450, 450) will resize image as in second example and then crop it (cut off 450 x 450 pixels in center of image).
Resizing images is most popular operation made for auto-generated previews, but Image class provides you with a lot of graphical effects and image transformations. You can emboss, sharpen, negate image, flip it and rotate it etc.
If this is only possible, try to set fixed value here and do not change it later. Extension provides you with a nifty tool for updating all versions (previews) of images later -- you need to call $model->galleryBehavior->changeConfig(); on each model, which versions / previews are about to change. But, this isn't recommended way, as this will modify many files on-the-fly and can even bloat your server (if you have really big number of galleries there).
Keep in mind, that versions array is kept (serialized) in database for each of your gallery. Therefore, you have to call $model->galleryBehavior->changeConfig(); for each of gallery already stored in database, after changing versions settings.
Widget preview
Using the same methods, a preview for Gallery Manager widget is generated. It's line 147 of GalleryPhoto model, inside setImage method:
Yii::app()->image->load($path)->resize(300, null)->save(Yii::getPathOfAlias('webroot') . '/' .$this->galleryDir . '/_' . $this->getFileName('') . '.' . $this->galleryExt);
It generates too big preview (300 px longer edge, while actual widget uses 140 px at max) and produces over all not so cool effect, with a large piece of white empty space below each image preview. If found out that, changing this line to:
Yii::app()->image->load($path)->centeredpreview(140, 140)->crop(140, 120)->save(Yii::getPathOfAlias('webroot') . '/' .$this->galleryDir . '/_' . $this->getFileName('') . '.' . $this->galleryExt);
And changing following lines in assets/galleryManager.css:
line 126, .GalleryEditor .caption p selector, add white-space: nowrap; line,
line 33, .GalleryEditor .photo selector, change line-height: 1; to line-height: 0.7;,
line 144, .GalleryEditor .image-preview selector, change height: 88px; to height: 120px;,
will produce a much better effect. But, this is my private opinion. Note, that you should add first change in any conditions, even if you don't change anything else, as it seems, extension's author forgot about this line. Without it, long photo descriptions spans into many lines, ugly messing around in edit and delete buttons' background.
Another thing, that was missed by extension's author is adding this style to the end of ``:
.sorter
{
overflow: auto;
height: 400px;
}
Without this assets/galleryManager.css, images area in your gallery won't be vertically scrollable and you will have no access to other photos, if you upload many images to particular gallery. Remember to remove assets after applying these changes, to actually see them on-line.
Using migrations
If you're using migrations to update database, then note, that schema.migration file found in migrations folder in yii-gallery-manager extension folder has some problems, that should be / must be corrected.
First thign is, that you should add $this->dropForeignKey('fk_gallery_photo_gallery1', 'gallery_photo'); to your down() method to clean everything, what was created by up() method; add it before dropping extension's tables:
public function down()
{
/**
* Drop yii-gallery-manager extension tables.
*/
$this->dropForeignKey('fk_gallery_photo_gallery1', 'gallery_photo');
$this->dropTable('gallery_photo');
$this->dropTable('gallery');
}
And, if you're using behavior, you should modify all your tables / models, that will be using galleries, and add new column, that will hold gallery ID per particular model. Name this column the same way as you name idAttribute parameter in behavior configuration. By default, it should be named gallery_id. I suggest to alter this name only, if it conflicts with something in your model or application:
$this->addColumn('contents', 'gallery_id', "integer DEFAULT NULL COMMENT 'Foregin key to Gallery -- gallery for this content' AFTER `content_id`");
Debugging
You can use modified piece of code from GalleryController::actionAjaxUpload() to do pretty nice debugging. Put this code somewhere (in some view?) and execute:
<?php
$model = new GalleryPhoto();
$model->gallery_id = 123;
$model->file_name = 'test1';
$model->setImage('test2');
?>
It helped me discover problems with database (incorrect table names) in first place and it brought me answer, why the heck images are not uploaded? After three hours of searching, I found out, that Yii isn't able to find CImageComponent. I wasn't able to discover this earlier, because all upload-related events occurs in post-only, ajax-mode mood, which is quite hard to debug.
Demo application
There's a nice looking and (nearly) ready to use demo application found at BitBucket (this time repository is cloneable): https://bitbucket.org/z_bodya/yii-demo-blog. It contains Gallery Manager and other extensions made by this author.
When you get it running, don't be surprised, that you see no sign of gallery manager at first. To see it in action, you should edit any post (or create new one), because gallery manager widget has been included only in this view (and in post view in frontend, once particular view contains some gallery).
This is very simple demo, and need some sort of work to port it to working application. But, for sure this is a good starting point for dealing with all troubles you may have with this extension. And a nice thing from author, that he wanted to spare his time not only on writing extension itself, but also for providing working demo application. Big thumb up from my side! :>
Note, that cloned code does not contain assets folder and protected/runtime folder. You should create these two in point 2.5 (before changing folder permissions) of instruction mentioned in BitBucket repository.
Therefore, steps for installing demo application are this:
Clone repository (git clone git#bitbucket.org:z_bodya/yii-demo-blog.git).
Install composer dependencies (run php composer.phar install or composer install inside protected folder).
Create missing folders (mkdir assets, mkdir protected/runtime).
Change folder permissions (chmod -R 777 assets protected/runtime gallery uploads images in most situations).
Run application in your browser, login using demo/demo, go to control panel and edit (or create and save first) any post found there.
Read [this article](Installing Composer to PHP on Windows.txt) if you don't have Composer on your Windows and need to install it.
Note, that demo applications includes gallery's cover image functionality, requested by some user and implemented as a part of separate branch. It is not included in master branch and since branches at BitBucket are not accessible right now, you can only get this feature by hand-copying changed code.
Sources and information
Here is a list of pages, you may wish to visit to read more about yii-gallery-manager:
extension page at yiiframework.com,
main code repository at BitBucket,
mirror code repository at GitHub,
demo application at BitBucket.
Main repository at BitBucket is not accessible (the moment of writing it) and does not provide a code to clone. You should use GitHub mirror instead or download .tar.gz file from extension page at yiiframework.com.
There's also a forum discussion on this extension, but last post (unanswered) is over two years old now. So, this forum is pretty useless.
Some alternatives
If, for any reason, yii-gallery-manager is not an option for you, you can consider these alternatives:
https://code.google.com/p/yii-gallery-extension/
https://github.com/Crisu83/yii-imagemanager
https://github.com/drumaddict/angular-yii
in your composer.json file add
"require": {
...
"z_bodya/yii-gallery-manager": "dev-default"
},
then run
composer update

Adding custom code generator

When I work with certain types of files, such as: Java file, HTML file or Jasmine Test file I can generate some useful code snippets using Code > Generate option, for example:
if I am working with Java file Code > Generate allows me to insert getter, setter, constructor etc
if I am working with HTML file Code > Generate allows me to insert an XML tag
if I am working with Jasmine Text file Code > Generate allows me to insert a scaffolding of a test suit or a singe test case
I was wondering if (and how) I can add my own 'generator'. I know I can use Live Templates, but I like the fact that Code > Generate gives me a quick list of all available generators.
Yes, you can do it by writing an IntelliJ plugin and extending this class:
com.intellij.openapi.actionSystem.Action
If you create an intelliJ plugin project (just google intellij plugin developmentfor information on how to get started), hit alt-enter somewhere in your project source tree and select Action, you will get a dialog which allows you to configure where your action should appear.
You want to place it in relation to another action which already exists, for example right below it. In your case - have a look at the menu group named GenerateGroup (Generate).
Once your action is defined in this manner in your plugin.xml, build and run your plugin in the sandbox.
Now, when your action is triggered, the AnActionEvent will be fired which contains references to all the necessary information you need (current project, file, position of cursor within file, psi tree, etc).
Try to get this working so far and come back with any specific questions.
Good luck!

Unraveling the confusion about Embedded Resources

EDIT: Read answer number 1 from Tim Schmelter and then use this question for examples of how to embed resources and access them at runtime.
The subject of embedded resources comes up a lot, especially with people asking how to access the embedded files at runtime. Things get more confusing because Visual Studio gives you 2 different ways of embedding a resource, and different ways of accessing those resources at runtime. The problem is that depending on which method you used to embed the resource, the method you’re trying to use to access the file at runtime might not work. This post is an attempt to clear up all the confusion that I see out there, but I also have a question that nobody can seem to answer factually: Why is the size of my compiled program TWICE the size of the embedded resource (sometimes)? For example if I embed a 20MB file into my project, why does my program compile to 40MB? I haves asked this question in the past and nobody was able to reproduce my results. I found that the reason they were not able to reproduce was because they were embedding the file in a different way. See here:
Method 1:
Double-click on My Project to open the property pages and go to the Resources Tab. Now click Add Resource > Add Existing File. Browse to the file you want to embed. For this example I’m using an executable. You will now see your file on the Resources Tab:
You will also see that a folder named Resources was created under your project and the embedded file has been placed in this folder:
EDIT: THIS NEXT STEP WAS THE PROBLEM. TURNS OUT THAT WHEN YOU ADD A FILE VIA THE RESOURCES TAB YOU SHOULD NOT SET THE BUILD ACTION TO EMBEDDED RESOURCE. Counter intuitive to say the least!
Now with the file selected, look down at the properties window for the file and change the build action to Embedded Resource: (this step should ONLY be performed when you add a file via method 2).
Now compile your program. You will see that the size of your compiled program is at least double the size of your embedded resource. This does not happen with method 2. See here:
Method 2:
Right-click on your project name and choose Add > Existing Item. Browse to your file, and this time you will notice that while it was indeed placed under your project, there was no Resources folder created:
Now once again select the file and change the Build Action to Embedded Resource and compile. This time the size of the compiled program will be as you expected - about the size of the embedded file and not double the size as with method 1.
Which method you use to embed your file will determine which method you can use to access the file at runtime. For method 1 this is very simple, all you have to do is:
My.Computer.FileSystem.WriteAllBytes(Path, My.Resources.ResourceName, Append)
Where Path is the location and name for the file you want to save on the harddrive, ResourceName is the name of the embedded resource that you see in the project window (minus any extension), and Append is whether or not you want to create a new file or overwrite an existing file. So for example, using test.exe from the above images, I could save that file to the C drive like this:
My.Computer.FileSystem.WriteAllBytes(“C:\test.exe”, My.Resources.test, False)
Couldn’t be easier.
Method 2 however doesn’t appear to give you access to My.Resources so it gets a little more complicated. You have to create a Stream to hold the resource, put the stream into a byte array, then write the bytes out to the file system. The simplest way I have found to do this is like this:
Using s As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Project.ResourceName)
Dim bytes(s.Length) As Byte
s.Read(bytes, 0, bytes.Length)
File.WriteAllBytes(OutputFile, bytes)
End Using
With this method ResourceName must contain the file extension AND project name so using our example from above we can just do:
Using s As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(WindowsApplication1.test.exe)
Dim bytes(s.Length) As Byte
s.Read(bytes, 0, bytes.Length)
File.WriteAllBytes(“C:\test.exe”, bytes)
End Using
Text-based files are a little different:
Dim output As String
Using sr As StreamReader = New StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream(WindowsApplication1.test.txt))
output = sr.ReadToEnd()
End Using
Using sw As StreamWriter = New StreamWriter(“C:\test.txt”)
sw.Write(output)
End Using
Having struggled with this in the past I hope this will help someone. And if you think you can explain factually why method 1 of embedding a resource bloats my compiled program to double its size, I would really appreciate it.
I assume that Method 1 is adding the files twice.
http://www.vbdotnetforums.com/vb-net-general-discussion/42670-visual-basic-net-2008-get-resource-file-io-stream.html#post121923
At least that is the conclusion of the thread above.
Quote:
You went to the Resources page of the project properties and added the files there, right? You then went into the Solution Explorer and change the Build Action of the files to Embedded Resource, right? That's why you were doubling the file size: you were adding each file twice.
There are two different ways to add resources: on the Resources page of the project properties and in the Solution Explorer. You do NOT do both. If you want to use GetManifestResourcestream then you do NOT use the Resources page. You add the files to the project in the Solution Explorer manually, then you set the Build Action to Embedded Resource.
In future, do one or the other, not both.
Add a file to the Resources page of the project properties and then access it via My.Resources. This will automatically add the file to the project in the Solution Explorer but the Build Action will be None and it should be left that way.
Add the file to the project in the Solution Explorer by using Add New Item or Add Existing Item. Set the Build Action of the file to Embedded Resource and then access the resource using GetManifestResourceStream.
Just an update for anyone who wants to use this code. The code actually writes one additional byte to the file due to zero-based declaration of the byte array.
To get an exact copy of the original file change the code to:
Using s As Stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(WindowsApplication1.test.exe)
Dim bytes(s.Length-1) As Byte
s.Read(bytes, 0, bytes.Length)
File.WriteAllBytes(“C:\test.exe”, bytes)
End Using