PlanetSquires Forums

Please login or register.

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

Author Topic: WinFBE 1.3.0 on GitHub (March 24, 2017)  (Read 2648 times)

ganlinlao

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 23
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #15 on: April 17, 2017, 01:10:53 AM »

thanks José Roca
When I install WinFBE in a directory containing Chinese characters, WinFBE cannot load file, if the code file is placed in a directory containing Chinese characters, the WinFBE can open code file, but cannot save edited code file, cannot compile code file

thanks
ganlinlao
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8099
  • Windows 10
    • PlanetSquires Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #16 on: April 17, 2017, 12:04:17 PM »

Thanks ganlinlao,

I made a change to the handling of the filename for the Localization file name/path and have uploaded the new exe to GitHub at https://github.com/PaulSquires/WinFBE

You just need to download the WinFBE32.exe and/or WinFBE64.exe and overwrite your existing files.

Not sure if this will correct the problem but please let me know.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

ganlinlao

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 23
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #17 on: April 18, 2017, 04:08:35 AM »

hi TechSupport
I downloaded the latest version of WinFBE from Github, but WinFBE could not load the file from the containing Chinese character directory. I found the reason for this is because the ExePath () function in the WinFBE.bas file could not return the directory name with Chinese characters correctly.

I tried to modify some of the code in WinFBE.bas and recompile it. WinFBE.exe can load a file with a Chinese character path。

 code in winFBE.bas:   
'  dim wszLocalizationFile as WString * MAX_PATH
'   wszLocalizationFile = Exepath + wstr("\Languages\") + gConfig.LocalizationFile
'   If LoadLocalizationFile(@wszLocalizationFile) = False Then
'      MessageBoxW( 0, WStr("Localization file could not be loaded. Aborting application.") + vbcrlf + _
'                   wszLocalizationFile, _
'                   WStr("Error"), MB_OK Or MB_ICONWARNING Or MB_DEFBUTTON1 Or MB_APPLMODAL )

   dim wszLocalizationFile as cwstr
   wszLocalizationFile &=afxgetCurDir()
   wszLocalizationFile &= cwstr("\Languages\")
   wszLocalizationFile &= gConfig.LocalizationFile
   If LoadLocalizationFile(Cast(wstring ptr,wszLocalizationFile)) = False Then
      MessageBoxW( 0, WStr("Localization file could not be loaded. Aborting application.") + vbcrlf + _
                   wszLocalizationFile, _
                   WStr("Error"), MB_OK Or MB_ICONWARNING Or MB_DEFBUTTON1 Or MB_APPLMODAL )
      Return 1
   End If

Thanks
ganlinlao
Logged

José Roca

  • FireFly3 Registered User
  • Master FireFly Member
  • *
  • Posts: 2776
    • José Roca Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #18 on: April 18, 2017, 07:44:32 AM »

Good catch, but better use AfxGetExePathName instead of AfxGetCurDir (this one may fail if the current directory is not the same that the path of the executable).

The instrinsic FB functions that deal with files and folders are not unicode aware. This is why I have provided replacements for them in my Afx framework. Wrapper functions in AfxWin.inc and AfxPath.inc, and methods in the classes CFileSys.inc and CFindFile.inc

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8099
  • Windows 10
    • PlanetSquires Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #19 on: April 18, 2017, 03:53:40 PM »

Hi ganlinlao, thanks so much for finding th source of the problem. I will make the change to the source code and upload it to GitHub. I never realized that EXEPATH() was the source of the problem.

Thanks!
Paul
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8099
  • Windows 10
    • PlanetSquires Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #20 on: April 18, 2017, 04:04:09 PM »

I am also going to change DIR() and CURDIR() functions to Afx versions,
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8099
  • Windows 10
    • PlanetSquires Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #21 on: April 18, 2017, 04:16:15 PM »

Changes made and new EXE's uploaded to GitHub.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

ganlinlao

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 23
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #22 on: April 20, 2017, 10:18:32 PM »

hi,TechSupport

WinFBE in dealing with Chinese characters, there will be some problems.

I also use notepad++ software to enter the same Chinese text and save it without this problem. Notepad++ is also dependent on Scilexer.dll
Logged

ganlinlao

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 23
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #23 on: April 20, 2017, 10:46:01 PM »

I switched to WinFBE in ANSI mode, new document, entered some English and Chinese. Enter the ENTER key at the end of the Chinese text to switch to a new line, and the program stops responding



thanks
ganlinlao
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8099
  • Windows 10
    • PlanetSquires Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #24 on: April 21, 2017, 10:49:48 AM »

Thanks ganlinlao, I have a pretty good idea where I think this problem is coming from in the code. Give me a little while to rework some of the code and I will post some new EXE's for you to try. I will post here when the new code is ready.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8099
  • Windows 10
    • PlanetSquires Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #25 on: April 21, 2017, 04:40:25 PM »

I have changed the code in clsDocument that loads and saves the code text to honor the Ansi/Utf8 setting of the editor. It now uses the FreeBasic Open function with the appropriate file encoding setting based ont he Ansi/Utf8 setting in the editor. Please test to see if this corrects the Chinese character issue. Thanks!
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

ganlinlao

  • FireFly3 User
  • Little Newbie FireFly
  • *
  • Posts: 23
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #26 on: April 23, 2017, 05:40:43 AM »

hi,TechSupport
    I downloaded the latest version of WinFBE from Github,But it does not better solve the problem of Chinese characters, you use  gConfig.UnicodeEncoding  parameter, meaning that I edit the code containing the Chinese characters, can only use the UTF8 mode, can not use the ANSI mode, which is unfair, and will bring other problems。
My advice on this question is:
Source code file format, perhaps one of the Ansi,unicode,utf8+bom,utf8, we can first detect the source code file's first three bytes,  can determine that it is Unicode, utf8+Bom text file, and use the FielEncodingType variable to save it.
When I save the file, save it according to the FileEncodingType value.
I tried to wrote a function for detecting file formats and added a fields FileEncodintType to the Clsdocument class
it is mycode:
    Declare Function CheckFileEncoding(Byval pwszName As Wstring ptr) As String
'#########################

   Function CheckFileEncoding(Byval pwszName As Wstring ptr) As String       
       Dim As Long f,k
       Dim As String headBuffer,st
       f=freefile
       If Open(*pwszName For  Input   As #f)=0 Then
          Do Until EOF(f)
               For k=1 To 3
           Input #f,st
          headbuffer=headbuffer & st
          Next
          loop
   Close #f
           Select Case headBuffer[0]
         Case 255,254               'Make sure this.FileEncodingType is Unicode
         function= "unicode"
         Case 139                      'Make sure this.FileEncodingType is utf8+BOM
         function= "utf8+Bom"
         Case else
         function= "ascii"
      End Select
      Else
      afxmsg(WStr("Error opening: ") & *pwszName,48)
    End If     
   End function

'#############################
 when  open File :
……
     this.FileEncodingType=CheckFileEncoding(pwszFile)
       Select Case this.FileEncodingType
       Case "unicode"
                    hResult=Open(*pwszFile For Input  Encoding "utf16"  As #f)
       Case "utf8+Bom"
               hResult=Open(*pwszFile For Input  Encoding "utf8"  As #f)
            Case Else
          hResult=Open(*pwszFile For Input  Encoding "ascii"  As #f)
       End Select       
       If hResult=0 then           
               Do Until Eof(f)
                  Line Input #f, st
                  sText = sText & st & vbCrLf
      Loop
      close #f
                    if len(sText) > 2 THEN  ' or will GPF                          
               If IsTextUnicode(StrPtr(sText), 2, Cast(LPINT, @nResult) ) Then
                                this.FileEncodingType="utf8"                 'sorry,I don't know how to use the Istextunicode () function, it seems to be here not to work                       
                               sText = AfxACode( Cast(WSTRING Ptr, StrPtr(sText)) )
                       End If 
                   End if      
               this.SetText( sText )
               this.DateFileTime = AfxGetFileLastWriteTime( *pwszFile )
            else
               print "Error opening: "; *pwszFile
            End If

when save File:


   ' Save text buffer to disk by directly accessing buffer rather
   ' saving it to an intermediary string variable first.
   Dim As ZString Ptr psz = Cast( ZString Ptr, SciExec(this.hWindow, SCI_GETCHARACTERPOINTER, 0, 0) )
   f = FreeFile
   Select Case this.FileEncodingType
   Case "unicode"
   'if gConfig.UnicodeEncoding THEN
      Open wFilename for output Encoding "unicode" As #f
    Case "utf8+bom"
       Open wFilename for output Encoding "utf8" As #f
   Case else   
      Open wFilename for output As #f
   End select
   if Err > 0 then
      ' error saving file
      print "Error saving file: "; wFilename
   else
      print #f, *psz
   end if   
   close #f
’######################
This seems to be able to correctly open the text containing the Chinese character file, whether the Unicode,utf8+bom,utf8,ansi file, edit the file, and then save, no problem. I use notepad++ to reopen the file, and can display it correctly.

thanks
ganlinlao
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8099
  • Windows 10
    • PlanetSquires Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #27 on: April 23, 2017, 10:24:57 AM »

Thanks ganlinlao, I appreciate the work you have done with this and the help you are giving. I will implement the changes and I will also download the Notepad++ source to take a look to see how they are handling different file formats. I hope to post new EXE's for you today. Thanks!
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8099
  • Windows 10
    • PlanetSquires Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #28 on: April 23, 2017, 12:18:22 PM »

There is a lot more to this than I realized.

- Opening the file, as expected I need to read the first few bytes to determine if a BOM exists. If it does, then:
-- If it is UTF16 unicode then I expect that I need to convert it to UTF8 in order to display in the editor.
-- If it is UTF8 BOM then no problem. Simply load the file and display it.
-- Problem is that UTF8 can also exist without a BOM so I need to research how to determine if the text is UTF8 or simply ASCII. From what I read this has do do with 7bit or 8bit usage of the bytes in the file to determine if variable number multiple bytes are needed to represent a character (UTF8).

Once I know the file encoding then saving the file afterwards should be easier. FB's built in file commands allow for the use of Encodings. Only thing to be aware of is that UTF16 and UTF8 both save using a BOM. If a file is opened as UTF8 without a BOM then I would need to ensure that it is also saved without a BOM.

Interesting stuff. I will do some searches on FB's forum to see if anyone has already written code to determine if file is UTF8 if BOM doesn't exist. The Notepad++ source code contains many functions for conversion to and from unicode and utf8 but it also adds the complexity of dealing with big endian and little endian file formats.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8099
  • Windows 10
    • PlanetSquires Software
Re: WinFBE 1.3.0 on GitHub (March 24, 2017)
« Reply #29 on: April 23, 2017, 12:46:38 PM »

Jose already has the AfxUcode and AfxAcode functions available so converting to and from unicode/utf8/ascii using codepages should be okay. I think the only thing I need now is a function to determine if a file being opened without a BOM is UTF8 and not just regular ASCII. I believe Notepad++ has code for this that I will look at.
 
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor
Pages: 1 [2] 3 4