I'm using the IdFTP (Indy 10) component to download some files (zip and txt) from a remote location. Before getting each file I set the TransferType to binary.
IdFTP.TransferType := ftBinary;
IdFTP.Get(ASource, ADest, AOverwrite);
I expect that both text and binary files can be downloaded using the binary mode. However it looks like text files contents is messed up while zip files are downloaded correctly. If I set the TransferType to ASCII for text files it works as expected. How can I detect which TransferType to set for a given file? Is there a common denominator or auto setting?
I don't see how the Binary flag can mess up transferred files. Binary type means the server transfers the files without any processing, as is.
The only thing that an FTP server should use the ASCII flag for, is to correctly handle the end of line in text files, usually (1) either only Line Feed in Unix or (2)Carriage Return + Line Feed in Windows. But nowadays most text editors handle both in either system.
So the safest is use only ASCII flag for very well known text files, probably only files with a .txt extension, and use Binary flag for all the others.
When in doubt, rule it out (!) - try transferring the files from the server using the Windows commandline FTP program, and see if text files still come out wrong. The program will transfer binary (command BIN) or text (command ASCII). If you transfer files with this and they still arrive differently to your expectation, then something is being done at the server end*. If they arrive fine, then either you (or Indy) are doing something. :-)
*In what way are the text files messed up? If you're transferring unicode text files, you might be better off transferring them as BINary anyway. I must admit that, as #unknown (yahoo) said, in most cases you should probably stick to BIN mode.
I guess it would also depend on how you are viewing the text file, ANSI or WideChar as to whether the text is messed up or not.
Related
One message in my inbox has attachment with a zip file. Inside zipped file is file with extension ".pif".
After opening file in hex editor I see that file is PE. Apparently someone added some code inside.
Gmail detects virus inside attachment.
I created virtual machine with Windows XP. I tried to run virus but nothing happen.
I'm really curious how does this virus work.
Can I identify in which language virus was written?
Is there a way to decompile or disassembly code inside ".pif" file?
Is there a ways to determine what is the name and type of virus?
I have a delphi project that somehow has become corrupted. I upgraded to Advantage 11.1 components (using XE) and now I'm getting the following error message when opening the project:
acctTbl: Error 5018: The handle given was not recognized by
Advantage. Verify specified handle is open/active. The given handle
is not recognized as a valid Advantage Client Engine
Because the error occurs, the data module DFM is not built, so I can't "adjust" any settings.
acctTbl is the first table in the DFM, so the error might occur for the ones following, but I can't tell.
We are not using the server, just the "Local Server".
I have tried to go back to version 10 of the components, but still the error continues.
I have also tried removing all of the projects object code and only opening the PAS and DFM files (by reverting from SVN).
Any help is greatly appreciated.
You can open the .dfm in a text editor (like Notepad), and change the AdsConnection.Connected property to false, and change any AdsTable or ADSQuery component's Active flags to false as well. (I'd suggest closing the IDE first, to make sure it doesn't cache a reference.) This will at least let you open the project and make whatever changes are needed to compile with the new version of ADS.
If the file has been updated through many older versions of Delphi prior to XE, there's a chance you still have a binary format .dfm file (meaning you'll see all kinds of strange symbols in Notepad when you open the .dfm file). If that's the case, Delphi includes a conversion utility (convert.exe, found in your $(DELPHI)\Bin folder), and you can use the following steps to convert it to text format and then make the changes (there's no need to convert it back after - the default is to create text .dfm files when new forms are created, and Delphi uses them very well as text).
Make a backup copy of your datamodule's .DFM somewhere safe first!
After making the backup copy, open a command window in your project folder, and run
Convert.exe -1 YourDataModule.dfm
The command says to convert in place (-i), which means the existing binary .dfm is overwritten by the new text .dfm (and the reason I stressed making a backup copy first). If you don't want to overwrite, you can omit the -i switch, and it will create a YourDataModule.txt file in the folder instead; you can then manually rename YourDataModule.dfm to a different name, and then rename YourDataModule.txt to YourDataModule.dfm.
I'm using Microsoft Visual Studio Express 2012 for Web. It seems that every file which I open with it gets encoded into UTF-8. For most files which are going to be web-facing, that's fine. However, I have files in my projects that are specifically for build purposes (e.g., .bat files), which must be encoded in ANSI.
Are there any configuration settings in VS to either designate on a per file or a per extension basis the encoding? Or, if not specify the encoding, at least disable the auto-conversion to UTF-8?
Open the problematic file in Visual Studio and...
On the File menu, click Advanced Save Options.
In the Encoding dropdown, select Unicode (UTF-8 … or the encoding you require.
Click OK.
Also see:
how to change source file encoding in csharp project (visual studio / msbuild machine)?
An option to handle the encoding of all files of a given extension on a per open basis can be configured in the Options dialog. See MSDN page on Options, Text Editor, File Extension.
Navigate to Tools > Options > Text Editor > File Extension.
For the bat extension, I selected Source Code (Text) Editor with Encoding. The with Encoding part means that the user will be given options as to what encoding to use when opening the file. The default in this mode is Auto-detect, which preserves the ANSI encoding, if that is what the file already uses. Otherwise, one can explicitly designate it for the individual file.
Unfortunately, it doesn't seem to remember the setting last used when opening a file, and will thus prompt for an encoding setting every time a file is opened.
I had code conversion problems width VS studio 2012 as well. Namely, I had non ansi compliant characters in strings ind my .js files and unreadable was outputted to the browsers html page.
I figured out that accept script files (like .js) VS 2012 creates all files in UTF-8.
*The problem is with the suggestion bellow to change the defaults in the options dialog resulted in that the syntax highlighting and intelisense stopped working in all .js files.*
So my workaround solution know is that I convert my .js files with notepad++ to utf-8 without BOM.
In this way my "unusual" chars are appearing well in browsers and the intelisense is working fine as well.
I am currently converting a legacy system to a new platform and need to extract strings from the old systems resource files.
The old system was written in Delphi and the strings are kept in files called .dfm. I have no trouble locating the strings and for English and other European languages there is no problem. The trouble comes when I try to extract strings in Japanese. I have used Notepad++ and it seems to me that the program don´t recognice the correct encoding. I get Japanese symbols but they don´t seem to match what is in the GUI. Notepad++ shows signs in something called GB2312(Simplified Chinese). But it looks weird.
My question is, does anyone have any tips on programs/text editors that are good at operations like this?
Also I'm grateful for any tips that might help me along the way.
Assuming that your issue is simply that Notepad++ is incorrectly guessing the encoding you can solve the problem by manually setting the encoding in Notepad++, like this:
Notepad++ itself already handles encoding issues. To make it to desired encoding, like Unicode;
first, copy all the contents of the file,
choose Unicode without BOM in the menu,
last, replace all contents with copied contents
save the file
Your contents will then be in your desired encoding.
Strings are kept not [just] in DFMs in Delphi. Only forms and associated text are. So you would to review all the code as well.
As for DFMs - before Delphi 2009 DFMs didn't use Unicode so you must know what charset was used. That was one of big problems with localization and internationalization of Delphi applications.
All exes compiled can be decompiled (but with some hardship )
but delphi application forms are saved as dfms inside exe which can be seen easily (with reshacker) (soooo easily ) can i overcome these problems ,first i thought of copying dfm data to oncreate procedure so i can hide my form information .
tell me a good solution for this ,
i do not like to use compressors
and my application is bit large so i cant port resourese one by one to a dll. i need an effective solution.
.dfm files are not stored as txt when they're linked into the final PE file. They are converted to a tagged binary format that is placed into an RCDATA Windows resource. For the images, they are stored as the raw binary. While building your application, the .dfm files can be stored as text or binary (right click the form designer and there is a selection for choosing one or the other). This only affects the format of the .dfm file itself. It has zero affect on its format once it is linked into your final binary.
You can try to convert the images to constant arrays (there are many tools that will read a binary and write out an array decl in various language formats) and use it as an include file. Another thing is to encrypt the images using a one-way algorithm like RSA or PGP. This won't keep someone from decrypting the image, but it will keep someone from replacing it since they won't have the private key.
If this is about protecting your applications images you are already on the losing side:
https://stackoverflow.com/questions/455623/how-can-i-prevent-users-from-taking-screenshots-of-my-application-window
It is always possible to make screenshots of a running application.