The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ring programming language version 1.8 book - Part 85 of 202
1. CHAPTER
SEVENTYONE
DISTRIBUTING RING APPLICATIONS
In this chapter we will learn about distributing Ring applications.
The next method is old and was used in Ring 1.5 and previous versions!
Starting from Ring 1.6 we have a nice tool called Ring2EXE
Using Ring2EXE we can distribute applications quickly for Windows, Linux and macOS
Check the Ring2EXE chapter for more information!
71.1 Distributing Applications for Microsoft Windows
Step 1:
Copy c:ringbin folder to be for example c:myapp
Step 2:
Rename c:myappring.exe to c:myappmyapp.exe
Step 3:
Create a file c:myappring.ring
And write
Load "myapp.ring"
When you run myapp.exe the file ring.ring will be executed automatically
So your file myapp.ring will be called and executed
Or just rename myapp.ring to ring.ring
It’s a fast way to distribute applications.
71.2 Protecting the Source Code
Step 1:
Execute the next command
ring myapp.ring -go
811
2. Ring Documentation, Release 1.8
This will generate one object file (myapp.ringo) from the project files (*.ring)
Step 2:
Rename myapp.ringo to ring.ringo
When you run the executable file (ring.exe) or (myapp.exe) the file ring.ringo will be executed.
71.3 Creating Windows Installer
There are many tools that you can use to distribute your application.
Check : nullsoft scriptable install system
URL : http://nsis.sourceforge.net/Main_Page
71.4 Using C/C++ Compiler and Linker
Another method to distribute applications is to use a C/C++ compiler.
Ring can be embedded in C/C++ projects, We can create executable files using a C/C++ compiler by embedding the
Ring language in our project.
Check the “Embedding Ring Language in C/C++ Programs” chapter.
Using this way we will avoid using ring.ring or ring.ringo files.
71.5 Distributing Applications and Games for Mobile
Ring can be embedded in a Qt projects or LibSDL projects to build Mobile applications and Games.
You can build the Qt project or the LibSDL project and get the Android package directly (*.apk)
Check Ring distributions for Mobile development using Qt or LibSDL.
71.3. Creating Windows Installer 812
3. CHAPTER
SEVENTYTWO
DISTRIBUTING RING APPLICATIONS USING RING2EXE
In this chapter we will learn about distributing Ring applications.
Starting from Ring 1.6 we have a nice tool called Ring2EXE (Written in Ring itself)
Using Ring2EXE we can distribute applications quickly for Windows, Linux, macOS and Mobile devices
72.1 Using Ring2EXE
ring2exe filename.ring [Options]
This will set filename.ring as input to the program
The next files will be generated
filename.ringo (The Ring Object File - by Ring Compiler)
filename.c (The C Source code file
Contains the ringo file content
Will be generated by this program)
filename_buildvc.bat (Will be executed to build filename.c using Visual C/C++)
filename_buildgcc.bat (Will be executed to build filename.c using GNU C/C++)
filename_buildclang.bat (Will be executed to build filename.c using CLang C/C++)
filename.obj (Will be generated by the Visual C/C++ compiler)
filename.exe (Will ge generated by the Visual C/C++ Linker)
filename (Executable File - On Linux & MacOS X platforms)
72.2 How Ring2EXE works?
At first the Ring compiler will be used to generate the Ring object file (*.ringo)
If we have a C compiler (optional), This object file will be embedded inside a C source code file
Then using the C compiler and the Ring library (Contains the Ring Virtual Machine) the executable file
will be generated!
If we don’t have a C compiler, the Ring executable will be copied and renamed to your application name
And your Ring object file (*.ringo) will become ring.ringo to be executed at startup of the executable file.
So it’s better and easy to have a C compiler on your machine to be used by Ring2EXE.
813
4. Ring Documentation, Release 1.8
72.3 Example
We have test.ring contains the next code
see "Hello, World!" + nl
To build th executable file for Windows, Linux or macOS
ring2exe test.ring
To run the program (Windows)
test
To run the program (Linux and macOS)
./test
72.4 Options
-keep : Don't delete Temp. Files
-static : Build Standalone Executable File
(Don't use ring.dll/ring.so/ring.dylib)
-gui : Build GUI Application (Hide the Console Window)
-dist : Prepare application for distribution
-allruntime : Include all libraries in distribution
-mobileqt : Prepare Qt Project to distribute Ring Application for Mobile
-noqt : Remove RingQt from distribution
-noallegro : Remove RingAllegro from distribution
-noopenssl : Remove RingOpenSSL from distribution
-nolibcurl : Remove RingLibCurl from distribution
-nomysql : Remove RingMySQL from distribution
-noodbc : Remove RingODBC from distribution
-nosqlite : Remove RingSQLite from distribution
-noopengl : Remove RingOpenGL from distribution
-nofreeglut : Remove RingFreeGLUT from distribution
-nolibzip : Remove RingLibZip from distribution
-noconsolecolors : Remove RingConsoleColors from distribution
-nomurmuhash : Remove RingMurmurHash from distribution
-nocruntime : Remove C Runtime from distribution
-qt : Add RingQt to distribution
-allegro : Add RingAllegro to distribution
-openssl : Add RingOpenSSL to distribution
-libcurl : Add RingLibCurl to distribution
-mysql : Add RingMySQL to distribution
-odbc : Add RingODBC to distribution
-sqlite : Add RingSQLite to distribution
-opengl : Add RingOpenGL to distribution
-freeglut : Add RingFreeGLUT to distribution
-libzip : Add RingLibZip to distribution
-libuv : Add RingLibuv to distribution
-consolecolors : Add RingConsoleColors to distribution
-murmurhash : Add RingMurmurHash to distribution
-cruntime : Add C Runtime to distribution
72.3. Example 814
5. Ring Documentation, Release 1.8
72.5 Building standalone console application
Using the “-static” option we can build executable console application
So we don’t have to use ring.dll, ring.so or ring.dylib
This avoid only the need to Ring dynamic link library
If you are using another libraries, You will need to include it with your application.
ring2exe test.ring -static
72.6 Distributing RingAllegro Applications
We have test2.ring contains the next code
# Just a simple program to test Ring2EXE Tool!
# Using RingAllegro
load "gameengine.ring" # Give Control to the Game Engine
func main # Called by the Game Engine
oGame = New Game # Create the Game Object
{
title = "My First Game"
}
To build the executable file and prepare for distributing the Game
We use “-dist” option and “-allruntime” to include all libraries
ring2exe test2.ring -dist -allruntime
After executing the previous command
On Windows we will have : target/windows folder
On Linux we will have : target/linux folder
On macOS we will have : target/macos folder
The previous command will add all of the Ring runtime libraries to our distribution
But we may need only RingAllegro, So it’s better to use the next command
ring2exe test2.ring -dist -allegro -cruntime
This will produce smaller size distribution and will avoid the runtime files that we don’t need!
Also we could use the “-gui” option to hide the console window
So it’s better to use the next command
ring2exe test2.ring -dist -gui -allegro -cruntime
72.5. Building standalone console application 815
6. Ring Documentation, Release 1.8
72.7 Distributing RingQt Applications
We have test3.ring contains the next code
# Just a simple program to test Ring2EXE Tool!
# Using RingQt
load "guilib.ring"
new qApp {
new qWidget() {
setwindowtitle("Hello, World!")
resize(400,400)
show()
}
exec()
}
To build the executable file and prepare for distributing the GUI application
We use “-dist” option and “-allruntime” to include all libraries
ring2exe test3.ring -dist -allruntime
After executing the previous command
On Windows we will have : target/windows folder
On Linux we will have : target/linux folder
On macOS we will have : target/macos folder
The previous command will add all of the Ring runtime libraries to our distribution
But we may need only RingQt, So it’s better to use the next command
ring2exe test3.ring -dist -qt -cruntime
This will produce smaller size distribution and will avoid the runtime files that we don’t need!
Also we could use the “-gui” option to hide the console window
So it’s better to use the next command
ring2exe test3.ring -dist -gui -qt -cruntime
72.8 Distributing Applications for Mobile using RingQt
To prepare a Qt project for your RingQt application (test3.ring) use the “-mobileqt” option
Example :
ring2exe test3.ring -dist -mobileqt
After executing the previous command, We will have the Qt project in target/mobile/qtproject folder
The main project file will be project.pro which we can open using the Qt Creator IDE.
Also we will have the resource file : project.qrc
Another important file is our C++ main file : main.cpp
72.7. Distributing RingQt Applications 816
7. Ring Documentation, Release 1.8
72.9 Building the Cards Game for Mobile using RingQt
For a better example, consider building an Android package for the Cards game that comes with the
Ring language in this folder : ring/application/cards
The Cards game folder contains three files
cards.ring : The Game source code
cards.jpg : The image file used by the game
project.qrc : Resource file to be used with the Qt project
The resource file contains the next content
<RCC>
<qresource>
<file>cards.ringo</file>
<file>cards.jpg</file>
</qresource>
</RCC>
We have two files in the resource file
The first file is cards.ringo (The Ring Object File) and the second file is cards.jpg (The image file)
As a start, Ring2EXE will generate this resource file in target/mobile/qtproject/project.qrc
But this file will contains only cards.ringo (That Ring2EXE will generate by calling Ring compiler)
We need to update this resource file to add the image file : cards.jpg
After this update, we copy the resource file to the main application folder
So when we use Ring2EXE again, Our updated resource file will be used!
Now to build the cards game for Mobile
1. Run the next command
ring2exe cards.ring -dist -mobileqt
2. Open target/mobile/qtproject/project.pro using Qt creator
3. Build and Run using Qt Creator
How the Cards game will find the image file ?
RingQt comes with a simple function : AppFile() that we can use to determine the files that we may
access on Desktop or Mobile platforms
The next code from cards.ring
mypic = new QPixmap(AppFile("cards.jpg"))
So all what you need is using AppFile() function around your image files!
72.10 Building the Weight History Application for Mobile using
RingQt
Another example to distribute your application for Mobile Devices using Ring2EXE and Qt
72.9. Building the Cards Game for Mobile using RingQt 817
8. Ring Documentation, Release 1.8
consider building an Android package for the Weight History application that comes with the
Ring language in this folder : ring/application/weighthistory
The Weight History application folder contains four files
weighthistory.ring : The application source code
weighthistory.db : The SQLite database
project.qrc : The resource file for the Qt project
main.cpp : The main C++ source file for the Qt project
To build the Weight History application for Mobile
1. Run the next command
ring2exe weighthistory.ring -dist -mobileqt
2. Open target/mobile/qtproject/project.pro using Qt creator
3. Build and Run using Qt Creator
The resource file (project.qrc) contains two files
<RCC>
<qresource>
<file>weighthistory.ringo</file>
<file>weighthistory.db</file>
</qresource>
</RCC>
The first file is weighthistory.ringo (Ring Object File - Generated by Ring2EXE by calling Ring compiler)
The database file : weighthistory.db
The main.cpp contains the next little update, To copy the database file from resources to a writable location
on the mobile device
QString path3 ;
path3 = path+"/weighthistory.db";
QFile::copy(":/weighthistory.db",path3);
You will need to do this with database files only!
When we use Ring2EXE, the tool will check for project.qrc and main.cpp, if they exist then your updated
files will be used in target/mobile/qtproject instead of the default version generated by Ring2EXE
So Use Ring2EXE to generate these files, Then copy them to your application folder when you update them.
72.11 Building the Form Designer for Mobile using RingQt
To build the Form Designer application (ring/applications/formdesigner) for Mobile
1. Run the next command
ring2exe formdesigner.ring -dist -mobileqt
2. Open target/mobile/qtproject/project.pro using Qt creator
3. Build and Run using Qt Creator
72.11. Building the Form Designer for Mobile using RingQt 818
9. Ring Documentation, Release 1.8
in the folder ring/application/formdesigner You will find the resource file : project.qrc
It will be used automatically by Ring2EXE
<RCC>
<qresource>
<file>formdesigner.ringo</file>
<file>image/allevents.png</file>
<file>image/checkbox.png</file>
<file>image/close.png</file>
<file>image/combobox.bmp</file>
<file>image/datepicker.bmp</file>
<file>image/dial.png</file>
<file>image/formdesigner.png</file>
<file>image/frame.png</file>
<file>image/grid.bmp</file>
<file>image/hyperlink.png</file>
<file>image/image.png</file>
<file>image/label.png</file>
<file>image/layout.png</file>
<file>image/lcdnumber.png</file>
<file>image/listview.png</file>
<file>image/lock.png</file>
<file>image/new.png</file>
<file>image/open.png</file>
<file>image/progressbar.png</file>
<file>image/project.png</file>
<file>image/pushbutton.png</file>
<file>image/radiobutton.png</file>
<file>image/save.png</file>
<file>image/saveas.png</file>
<file>image/select.png</file>
<file>image/slider.png</file>
<file>image/spinner.bmp</file>
<file>image/statusbar.png</file>
<file>image/tab.png</file>
<file>image/textarea.png</file>
<file>image/textfield.png</file>
<file>image/timer.png</file>
<file>image/toolbar.png</file>
<file>image/tree.bmp</file>
<file>image/videowidget.png</file>
<file>image/webview.png</file>
</qresource>
</RCC>
As we did in the Cards game, The Form Designer will use the AppFile() function to determine the name of the Image
files.
The next code from ring/applications/formdesigner/mainwindow/formdesignerview.ring
func CreateToolBar
aBtns = [
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/new.png"))
setclickevent(Method(:NewAction))
settooltip("New File")
} ,
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/open.png"))
72.11. Building the Form Designer for Mobile using RingQt 819
10. Ring Documentation, Release 1.8
setclickevent(Method(:OpenAction))
settooltip("Open File")
} ,
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/save.png"))
setclickevent(Method(:SaveAction))
settooltip("Save")
} ,
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/saveas.png"))
setclickevent(Method(:SaveAsAction))
settooltip("Save As")
} ,
new qtoolbutton(win) {
setbtnimage(self,AppFile("image/close.png"))
setclickevent(Method(:ExitAction))
settooltip("Exit")
}
]
tool1 = win.addtoolbar("files") {
for x in aBtns { addwidget(x) addseparator() }
}
From this example, We know that we can use sub folders for images.
72.12 Creating the Qt resource file using Folder2qrc
When we have large RingQt project that contains a lot of images and files, We need to add these files to the resource
file ( *.qrc ) when distributing applications for Mobile devices.
Instead of adding these files one by one, Ring 1.6 comes with a simple tool that save our time, It’s called Folder2qrc.
Example:
folder2qrc formdesigner.ring
We determine the main source file while we are in the application folder, and Folder2qrc will check all of the files in
the current folder and sub folders, Then add them to the resource file after the mainfile.ringo (In our example this will
be formdesigner.ringo)
The output file will be : project.qrc
You can open it and remove the files that you don’t need in the resources!
72.13 Important Information about Ring2EXE
• Using Ring2EXE to prepare distribution will delete all of the files in the old distribution
for example, if you have target/windows folder then used
ring2exe test3.ring -dist -allruntime
The files in target/windows will be deleted before adding the files again
This is important when you prepare a distribution for Mobile devices
72.12. Creating the Qt resource file using Folder2qrc 820