• Welcome to PlanetSquires Forums.
 

José, if you're bored...

Started by Paul Squires, August 02, 2018, 09:19:19 PM

Previous topic - Next topic

Paul Squires

...and looking for some new stuff to add to WinFBX...

How about maybe adding WinAPI unicode ready wrappers to replace all of the FB file handling routines?

See, it's easy for me to blindly suggest things without having to code it myself!  LOL   :D  :D  :D

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

I already provide:

CTextSTream

The CTextStream class allows to read and write sequential text files (sometimes referred to as a text stream).
Works with ASCII and Unicode.
Works with Windows CRLF files and with Linux LF files.

CFindFile

Performs local file searches. CFindFile includes member functions that begin a search, locate a file, and return the title, name, or path of the file. Contrarily to DIR, it works with unicode.

CFileSys

The CFileSys class wraps the Microsoft File System Object and provides methods to work with files and folders, giving your application the ability to create, copy, alter, move, and delete files and folders, or to determine if and where particular files or folders exist. It also enables you to get information about files and folders, such as their names and the date they were created or last modified.

------------

To work with files in binary mode, what I could do is to write classes to work with the IStream interface. CFileStream will work with files and CMemStream with memory files.

The available methods would be:

Open
Close
Read
Write
Seek
SetSize
CopyTo
Commit
Revert
LockRegion
UnlockRegion
Stat
Clone

Additional Read and Write methods that accept different data types can be added.

What do you think?

Paul Squires

I love the idea :)  CFileStream should be enough because I doubt many people would have a overly great need for memory files (although for the sake of completeness it would be great to have them) :)

Having an easy to use replacement for FB's built-in file handling routines would certainly lesson those "gotcha" moments when a new/existing user realizes that the FB commands automatically convert your Unicode data to ansi. That has burned me since I started writing the editor and without you pointing it out, I probably would have struggled for a long time trying to fin the bug in my code.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

I am more than happy to test the routines because I will replace every FB file handling routine in WinFBE to use the new ones.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

#4
Well, here you have something to read and test: first version of CFileStream.

List of possible error codes:

' Storage HRESULT's (error codes)
'#define STG_E_INVALIDFUNCTION _HRESULT_TYPEDEF_(&h80030001)
'#define STG_E_FILENOTFOUND _HRESULT_TYPEDEF_(&h80030002)
'#define STG_E_PATHNOTFOUND _HRESULT_TYPEDEF_(&h80030003)
'#define STG_E_TOOMANYOPENFILES _HRESULT_TYPEDEF_(&h80030004)
'#define STG_E_ACCESSDENIED _HRESULT_TYPEDEF_(&h80030005)
'#define STG_E_INVALIDHANDLE _HRESULT_TYPEDEF_(&h80030006)
'#define STG_E_INSUFFICIENTMEMORY _HRESULT_TYPEDEF_(&h80030008)
'#define STG_E_INVALIDPOINTER _HRESULT_TYPEDEF_(&h80030009)
'#define STG_E_NOMOREFILES _HRESULT_TYPEDEF_(&h80030012)
'#define STG_E_DISKISWRITEPROTECTED _HRESULT_TYPEDEF_(&h80030013)
'#define STG_E_SEEKERROR _HRESULT_TYPEDEF_(&h80030019)
'#define STG_E_WRITEFAULT _HRESULT_TYPEDEF_(&h8003001D)
'#define STG_E_READFAULT _HRESULT_TYPEDEF_(&h8003001E)
'#define STG_E_SHAREVIOLATION _HRESULT_TYPEDEF_(&h80030020)
'#define STG_E_LOCKVIOLATION _HRESULT_TYPEDEF_(&h80030021)
'#define STG_E_FILEALREADYEXISTS _HRESULT_TYPEDEF_(&h80030050)
'#define STG_E_INVALIDPARAMETER _HRESULT_TYPEDEF_(&h80030057)
'#define STG_E_MEDIUMFULL _HRESULT_TYPEDEF_(&h80030070)
'#define STG_E_PROPSETMISMATCHED _HRESULT_TYPEDEF_(&h800300F0)
'#define STG_E_ABNORMALAPIEXIT _HRESULT_TYPEDEF_(&h800300FA)
'#define STG_E_INVALIDHEADER _HRESULT_TYPEDEF_(&h800300FB)
'#define STG_E_INVALIDNAME _HRESULT_TYPEDEF_(&h800300FC)
'#define STG_E_UNKNOWN _HRESULT_TYPEDEF_(&h800300FD)
'#define STG_E_UNIMPLEMENTEDFUNCTION _HRESULT_TYPEDEF_(&h800300FE)
'#define STG_E_INVALIDFLAG _HRESULT_TYPEDEF_(&h800300FF)
'#define STG_E_INUSE _HRESULT_TYPEDEF_(&h80030100)
'#define STG_E_NOTCURRENT _HRESULT_TYPEDEF_(&h80030101)
'#define STG_E_REVERTED _HRESULT_TYPEDEF_(&h80030102)
'#define STG_E_CANTSAVE _HRESULT_TYPEDEF_(&h80030103)
'#define STG_E_OLDFORMAT _HRESULT_TYPEDEF_(&h80030104)
'#define STG_E_OLDDLL _HRESULT_TYPEDEF_(&h80030105)
'#define STG_E_SHAREREQUIRED _HRESULT_TYPEDEF_(&h80030106)
'#define STG_E_NOTFILEBASEDSTORAGE _HRESULT_TYPEDEF_(&h80030107)
'#define STG_E_EXTANTMARSHALLINGS _HRESULT_TYPEDEF_(&h80030108)
'#define STG_E_DOCFILECORRUPT _HRESULT_TYPEDEF_(&h80030109)
'#define STG_E_BADBASEADDRESS _HRESULT_TYPEDEF_(&h80030110)
'#define STG_E_DOCFILETOOLARGE _HRESULT_TYPEDEF_(&h80030111)
'#define STG_E_NOTSIMPLEFORMAT _HRESULT_TYPEDEF_(&h80030112)
'#define STG_E_INCOMPLETE _HRESULT_TYPEDEF_(&h80030201)
'#define STG_E_TERMINATED _HRESULT_TYPEDEF_(&h80030202)
'#define STG_S_CONVERTED _HRESULT_TYPEDEF_(&h00030200)
'#define STG_S_BLOCK _HRESULT_TYPEDEF_(&h00030201)
'#define STG_S_RETRYNOW _HRESULT_TYPEDEF_(&h00030202)
'#define STG_S_MONITORING _HRESULT_TYPEDEF_(&h00030203)
'#define STG_S_MULTIPLEOPENS _HRESULT_TYPEDEF_(&h00030204)
'#define STG_S_CONSOLIDATIONFAILED _HRESULT_TYPEDEF_(&h00030205)
'#define STG_S_CANNOTCONSOLIDATE _HRESULT_TYPEDEF_(&h00030206)
'#define STG_E_STATUS_COPY_PROTECTION_FAILURE _HRESULT_TYPEDEF_(&h80030305)
'#define STG_E_CSS_AUTHENTICATION_FAILURE _HRESULT_TYPEDEF_(&h80030306)
'#define STG_E_CSS_KEY_NOT_PRESENT _HRESULT_TYPEDEF_(&h80030307)
'#define STG_E_CSS_KEY_NOT_ESTABLISHED _HRESULT_TYPEDEF_(&h80030308)
'#define STG_E_CSS_SCRAMBLED_SECTOR _HRESULT_TYPEDEF_(&h80030309)
'#define STG_E_CSS_REGION_MISMATCH _HRESULT_TYPEDEF_(&h8003030A)
'#define STG_E_RESETS_EXHAUSTED _HRESULT_TYPEDEF_(&h8003030B)

José Roca

#5
Next, I will add a constructor and a LET operator that accepts an IStream pointer, a CAST operator to return the IStream pointer and methods to attach or detach the IStream object from the class. They will be useful to easily manipulate streams returned by some COM methods. If a method returns an stream object, we can attach it to an instance of CFileStream, use the available methods with it and release it when we call Close or the class is destroyed. We don't need to call Close unless we want to reuse an instance of the class to attach another stream object to it.

José Roca

#6
BTW I'm thinking in using GitHub docs for the documentation because it has become very big and HelpNDoc has become very slow. How do you generate the .pdf files?


Paul Squires

I will use the code and give you my opinions today! Awesome, thanks.
PDF files were created using Microsoft Word documents printed to a PDF driver. Simple, but the resulting PDFs are a little bigger than they should be.
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

I have added the additional constuctor that accepts an stream object, the LET and CAST operators, and the Attach/Detach functions. You aren't going to need them, but I have a good use for COM programming.

José Roca

A memory stream class will reuse most of the code for the file stream, but I'm still doubting about using CreateStreamOnHGlobal or SHCreateMemStream to create it. SHCreateMemStream is more efficient, but it is no thread safe and also does not support cloning in Windows versions below 8.

Paul Squires

I'm reading and understanding your new class. I am not able to provide my thoughts yet... I will give an opinion as soon as I can.

Once I understand the class, I want to see how the traditional FB commands correlate to the class. Basically, if an FB user wanted to easily transition to the class, what roadblocks and questions would they raise.

For example,

f = freefile
Open "TextA1.txt" For Input As #1
Do Until Eof(#f)
   Line Input #f, st
Loop
Close #f

Also, it will be nice if the class can somewhat automatically detect (or be an option) if the file ansi, utf8, utf16. I don't know, yet, if this could even be applied to the class as I haven't fully studied your approach to the class.

Looks awesome so far!
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

If using CTextStream and passing CWSTR to the functions that take CBSTR, is there any issues with the conversion?
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Quote from: Paul Squires on August 04, 2018, 11:51:33 PM

For example,

f = freefile
Open "TextA1.txt" For Input As #1
Do Until Eof(#f)
   Line Input #f, st
Loop
Close #f


Lol, silly me... I must have been tired when I wrote that post. The new class is for binary files... the CTextStream class is for sequential text files.
:)
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

José Roca

Quote from: Paul Squires on August 05, 2018, 12:11:15 AM
If using CTextStream and passing CWSTR to the functions that take CBSTR, is there any issues with the conversion?


No, you can pass any kind of string data type or literals, ansi or unicode. Using CBSTR is a bit faster because it does not need to be converted.

José Roca

#14
Quote from: Paul Squires on August 05, 2018, 12:16:17 AM
Quote from: Paul Squires on August 04, 2018, 11:51:33 PM

For example,

f = freefile
Open "TextA1.txt" For Input As #1
Do Until Eof(#f)
   Line Input #f, st
Loop
Close #f


Lol, silly me... I must have been tired when I wrote that post. The new class is for binary files... the CTextStream class is for sequential text files.
:)

Anyway, it would be:


DIM pTxtStm AS CTextStream
pTxtStm.OpenForInputA(TextA1.txt")

DIM cwsText AS CWSTR   ' or CBSTR
DO UNTIL pTxtStm.EOS
   cwsText = pTxtStm.ReadLine
   PRINT cwsText
LOOP
pTxtStm.Close


EOS means End of Stream.


If the file is ansi, you can also use the FB's STRING data type:


DIM s AS STRING
DO UNTIL pTxtStm.EOS
   s = pTxtStm.ReadLine
   PRINT s
LOOP


If it is Unicode, use OpenForInputW. The other available modes are OpenForOutputA/W and OpenForAppendA/W.

It also works with Linux files.