PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 12

Author Topic: Josť, if you're bored...  (Read 5151 times)

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Josť, if you're bored...
« on: August 02, 2018, 09:19:19 PM »

...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

Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #1 on: August 03, 2018, 12:52:14 PM »

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

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #2 on: August 03, 2018, 01:03:37 PM »

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.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #3 on: August 03, 2018, 01:09:14 PM »

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.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #4 on: August 03, 2018, 11:46:50 PM »

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)
« Last Edit: August 04, 2018, 01:27:32 PM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #5 on: August 04, 2018, 12:52:40 AM »

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.
« Last Edit: August 04, 2018, 01:01:53 PM by Josť Roca »
Logged

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #6 on: August 04, 2018, 01:34:49 AM »

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?

« Last Edit: August 04, 2018, 01:01:20 PM by Josť Roca »
Logged

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #7 on: August 04, 2018, 08:41:00 AM »

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.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #8 on: August 04, 2018, 01:30:05 PM »

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

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #9 on: August 04, 2018, 01:37:36 PM »

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

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #10 on: August 04, 2018, 11:51:33 PM »

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!
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #11 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?
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master Member
  • *****
  • Posts: 8635
  • Windows 10
    • PlanetSquires Software
Re: Josť, if you're bored...
« Reply #12 on: August 05, 2018, 12:16:17 AM »


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.
:)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Josť Roca

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #13 on: August 05, 2018, 12:50:42 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

  • Moderator
  • Master Member
  • *****
  • Posts: 3109
    • Jos
Re: Josť, if you're bored...
« Reply #14 on: August 05, 2018, 01:04:51 AM »


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:

Code: [Select]
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:

Code: [Select]
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.
« Last Edit: August 05, 2018, 02:06:49 AM by Josť Roca »
Logged
Pages: [1] 2 3 ... 12