BlackBerry 10 Native SDK - Writing Text Files - blackberry-10

I am battling to write some data to a simple text file
Here is my code:
QFile file(app->applicationDirPath() + "/data/testfile.txt");
if (file.open(QIODevice::WriteOnly)) {
QTextStream stream(&file);
stream << "DATA HERE \n";
}
The app compiles and runs fine.
Just I cant find the file, or more likely: it is not being created
Where am I going wrong? :)
Thanks
Extra Info:
Run: on my device (BlackBerry Z10)
IDE: QNX IDE (Native SDK) / (Cascades)
Example code is located in: TestApp::TestApp(bb::cascades::Application *app)
: QObject(app)

Okay, I kinda stumbled upon the answer myself:
QFile file(QDir::currentPath() + "/shared/documents/yourfile.txt");
if (file.open(QIODevice::WriteOnly)) {
QTextStream stream(&file);
stream << "DATA HERE \n";
}
Turns out each application has access to its own working directory. So the file was being created, I just could not see it on the device:
making the path: "/shared/documents/" made the file in a place where I could see it in the file manager
(hope this helps anyone who has a similar problem in the future)
This is a useful link, which explains the directories & current path.

Related

VSCode showing weird errors in my Haxe Code

i just started learning Haxe today and i got a couple of problems with my VSCode.
There are 3 "Errors" in total, to be exact 2 errors and 1 info, but the info seems kind of wrong and i would like to know how to get rid of it aswell.
Before i go into more detail, some info that might be relevant:
I created my project using the "Haxe: Initialize Project" from the Haxe VSCode extension
I changed nothing in the build.hxml file
If i run my code via VSCode (Ctrl-Shift-B) i get an error
If i run it on a normal CMD with "haxe build.hxml" it works totally fine, no errors at all
The Code:
class Main {
static function main() {
trace("Hello, World!");
var t:String = Sys.stdin().readLine().toString();
trace(t);
}
}
The build.hxml file:
-cp src
-D analyzer-optimize
-main Main
--interp
The first error i get:
It seems that this error is not even in my own file, how can this be?
The Sys.stdin().readLine() seems to have something to do with it, since this error came the moment i added this line.
Uncaught exception Not implemented in haxe.io.input.readByte at haxe/io/Input.hx tasks [180. 1]
Screenshot from VSCode
The second error i get:
Once again it seems to have something to do with Sys.stdin().readline() this time this exact part of my code is red underlined and the error message is pointing at this exact line.
Called from here tasks [4, 18]
Screenshot from VSCode (Error)
Screenshot from VSCode (red underline)
The (kind of) error / Info i get:
This is the most weird one imho..
Its a blue "~" i get at the beginning of my trace("Hello, World!"); line.
Screenshot from the weird Blue Symbol
Screenshot from the VSCode "Problem" regarding this line
Thanks in advance!
I looked through the internet the whole day hoping to find something to get this things solved on my own, but since its my first time ever using Haxe and i was not able to find something even similar to this i hope some of you 5heads out there can help me with this. :)

VSCode Custom Extension: Seem not to work

I'm currently trying to write an VS Code extension and it's a bit frustrating. I did everything as said here:
https://code.visualstudio.com/docs/extensions/example-hello-world
But after using yo code and entering all necessary information, I opened the respective folder VS Code hit F5 and VS Code says I should configure my launch.json (this should be done by yo code, shouldn't it?). However, when I press the debug start button, a extension-host window opens as described in that tutorial. BUT: When I try to execute the extension the command palette won't find it.
I tried several command names such as "hello world" "helloworld" or variants of the name of the extension that I gave in yo code. I also noticed the
"commands": [{
"command":"extension.sayHello",
"title":"Hello World"
}]
section of the package.json, but somehow I don't manage it to put it all together in order to get a simple, working vs code extension. In tutorial videos on youtube everyone can simply hit F5 after launching VS Code, what I cannot. Pretty weird somehow.
Any help is appreciated!
Thanks in advance.
EDIT: Additional information.
When I activated vs code to show all exceptions (even handled) vs code stops at the following point (see default:)
at internal/process/stdio.js (core module)
// ...
case 'PIPE':
case 'TCP':
var net = require('net');
stream = new net.Socket({
fd: fd,
readable: false,
writable: true
});
stream._type = 'pipe';
break;
default:
// VS CODE STOPS AT THE LINE FOLLOWING!
// Probably an error on in uv_guess_handle()
throw new Error('Implement me. Unknown stream file type!');
}
// Ignore stream errors.stream.on('error', function() {});
} catch (error) {
stream = createDevNull();
}
//...
Hopefully it helps :(
I solved my problem by reading the tutorial with more attention. The tutorial tells you to activate the command palette by Hitting F1 not CTRL P. This solved my Problem.
I did not change anything in the code; rather it seems to be important to hit F1 instad of [CTRL] + [P] despite it actually brings up the same input. I'm still wondering why to differenciate between CTRL + P and F1 if both bring up the same control. :/
Hope it helps other beginners, too.
cheers!
I had the same issue (though didn't debug to see if it failed on the same line) and I resolved it by restarting VSCode.

Http live streaming to iphone

I'm trying to play an http live stream to iphone, it looks like i have looked every example, mistakes and everything that i could found on the internet and apple docs about http live stream, and i think i'm in a dead end now.. I'm using MPMoviePlayer as in most of examples. Also i have to add the i can see the stream if i open the url from vlc player.
I succeeded in playing the apple BipBop stream on my iPhone that is here but can't play my stream. I figured that my url shows not in the m3u8 file so i found this terminal command, and successfully used it.
/Applications/VLC.app/Contents/MacOS/VLC --intf=rc rtp://#239.35.86.11:10000
'--sout=#transcode{fps=25,vcodec=h264,venc=x264{aud,profile=baseline,level=30, keyint=30,bframes=0,ref=1,nocabac},acodec=mp3,ab=56,audio-sync,deinterlace}:standard{mux=ts,dst=-,access=file}' | mediastreamsegmenter -b http://192.168.1.16/~Jonas/streaming/ -f
/users/jonas/sites/streaming/ -D
Now i have a playlist m3u8 file locally on my machine. As i understand with the command i download stream divide it into smaller ts files and generate m3u8 file that is like a reference to those ts files. So i've tried to load this, but still no luck. For some reasons i can't even open the m3u8 file in vlc or itunes, it throws me errors. So i guess it is something wrong with the playlist file?
Maybe some of you can see what am i doing wrong here or have some suggestions how to find my problem? I would really appreciate it.
It looks like your iOS code is just fine and that it is your server-side code that is causing issues, primarily with regards to generating the m3u8 playlist and possibly with how you're hosting the ts files that it references.
Unfortunately my example code is a bit noisy as I wrote it a year ago (it is in python) and it does a bit more than you're asking for (it live-transcodes a video into the correct m3u8/ts stuff) but it is tested and functional.
You can take a look at the code here: https://github.com/DFTi/ScribbeoServer/blob/python/transcode.py
I will paste some of the relevant methods here for your convenience; I hope it helps you:
def start_transcoding(self, videoPath):
if DISABLE_LIVE_TRANSCODE:
print "Live transcoding is currently disabled! There is a problem with your configuration."
return
print "Initiating transcode for asset at path: "+videoPath
videoPath = unquote(videoPath)
video_md5 = md5.new(videoPath).hexdigest()
if self.sessions.has_key(video_md5): # Session already exists?
return self.m3u8_bitrates_for(video_md5)
transcodingSession = TranscodeSession(self, videoPath)
if transcodingSession.can_be_decoded():
self.sessions[transcodingSession.md5] = transcodingSession
return self.m3u8_bitrates_for(transcodingSession.md5)
else:
return "Cannot decode this file."
def m3u8_segments_for(self, md5_hash, video_bitrate):
segment = string.Template("#EXTINF:$length,\n$md5hash-$bitrate-$segment.ts\n")
partCount = math.floor(self.sessions[md5_hash].duration / 10)
m3u8_segment_file = "#EXTM3U\n#EXT-X-TARGETDURATION:10\n"
for i in range(0, int(partCount)):
m3u8_segment_file += segment.substitute(length=10, md5hash=md5_hash, bitrate=video_bitrate, segment=i)
last_segment_length = math.ceil((self.sessions[md5_hash].duration - (partCount * 10)))
m3u8_segment_file += segment.substitute(length=last_segment_length, md5hash=md5_hash, bitrate=video_bitrate, segment=i)
m3u8_segment_file += "#EXT-X-ENDLIST"
return m3u8_segment_file
def m3u8_bitrates_for(self, md5_hash):
m3u8_fudge = string.Template(
"#EXTM3U\n"
# "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=384000\n"
# "$hash-384-segments.m3u8\n"
# "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=512000\n"
# "$hash-512-segments.m3u8\n"
"#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=768000\n"
"$hash-768-segments.m3u8\n"
# "#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=1024000\n"
# "$hash-1024-segments.m3u8\n"
)
return m3u8_fudge.substitute(hash=md5_hash)
def segment_path(self, md5_hash, the_bitrate, segment_number):
# A segment was requested.
path = self.sessions[md5_hash].transcode(segment_number, the_bitrate)
if path:
return path
else:
raise "Segment path not found"
That project is all open source now and can be found here: https://github.com/DFTi/ScribbeoServer/tree/python
Binaries can be found here: http://scribbeo.com/server
Good luck!

How do I detect if XenApp Client is installed on user machine?

We are upgrading from Citrix Metaframe to XenApp, and I need to know if there's a way to programmatically detect if the XenApp Web Plugin v11.0 is already installed on a client machine when it contacts our webserver for login -- this was previously done for the Metaframe Web Client by attempting to instantiate the ICA client in an ASP script, which used the results to determine whether to offer the client as a download/install.
The current code for this detection is:
Set icaObj = CreateObject("Citrix.ICAClient")
The above code does not find the XenApp plugin.
I continued my research after posting this question and I finally found the answer. Only 3 views on this question since I posted it, but despite the disinterest I believe I should answer my question, "Just in Case" someone else has this problem.
I was mistaken in my statement in question that the code I posted didn't find the XenApp plugin. In fact, it does. It returns a valid object in the presence of both Metaframe and XenAppWeb. I posted this question on Citrix's own forums, and no answers there either.
What I did to find the answer was to create a VS2008 project to which I added a COM reference to the Citrix ICA library -- both of them, installed separately one at a time. I found that both had a COM library named WFICALib, and searched through both of them to see if there was something that might distinguish them. What I found was a property, ClientVersion, which was 9.0.xxx for Metaframe, and 11.0.xxxx for XenAppWeb.
BINGO!
From this I cut the following code to return the version as a function in VBScript:
Function GetVer()
Dim icaObj, Ver
On Error Resume Next
Set icaObj = CreateObject("Citrix.ICAClient")
if err.number = 0 then
if IsObject(icaObj) then
GetVer = icaObj.ClientVersion
else
GetVer = 0
end if
set icaObj = nothing
else
GetVer = 0
end if
End Function
ADDENDUM:
Since posting this answer, I have discovered that this script in the newer versions of Internet Explorer (e.g. IE9) is not reliably detecting the plugin -- sometimes it worked, and other times not! What I did to fix the problem was to switch the script to JScript instead of JavaScript, and the new version looks like this:
<script type="text/jscript">
function GetCitrixVersion() {
try {
var icaObj = new ActiveXObject("Citrix.ICAClient");
return icaObj.ClientVersion;
}
catch (e) {
return 0;
}
}
</script>
Note the script type is text/jscript, not text/javascript.

How to delete a file while the application is running

I have developed a C# application, in the application the users choose a photo for each record. However the user should also be able to change the pre-selected photo with a newer one. When the user changes the photo the application first deletes the old photo from the application directory then copies the new photo, but when it does that the application gives an exception because the file is used by the application so it cannot be deleted while the application is running. Does any one have a clue how to sort this out? I appreciate your help
This is the exception
The process cannot access the file
'D:\My
Projects\Hawkar'sProject\Software\Application\bin\Debug\Photos\John
Smith.png' because it is being used by
another process.
//defining a string where contains the file source path
string fileSource = Open.FileName;
//defining a string where it contains the file name
string fileName = personNameTextBox.Text + ".png" ;
//defining a string which specifies the directory of the destination file
string fileDest = dir + #"\Photos\" + fileName;
if (File.Exists(fileDest))
{
File.Delete(fileDest);
//this is a picturebox for showing the images
pbxPersonal.Image = Image.FromFile(dir + #"\Photos\" + "No Image.gif");
File.Copy(fileSource, fileDest);
}
else
{
File.Copy(fileSource, fileDest);
}
imageIDTextBox.Text = fileDest;
First of all, you code is not good.
The new image is only copied if there is currently no image (else).
But if there is an old image, you only delete this image, but never copy the newer one (if).
The code should better look like this:
if (File.Exists(fileDest))
{
File.Delete(fileDest);
}
File.Copy(fileSource, fileDest);
imageIDTextBox.Text = fileDest;
This code should work, but if you are getting an exception that the file is already in use, you should check "where" you use the file. Perhaps you are reading the file at program start. Check all parts of your program you are accessing these user files if there are some handles open.
Thanks a lot for your help and sorry for the mistake in the code I just saw it, my original code is just like as you have written but I don't know maybe when I posted accidentally I've put like this. when the application runs there is a picturebox which the image of each record is shown, that is why the application is giving an exception when I want to change the picture because it has been used once by the picturebox , however I've also tried to load another picture to the picture box before deleting the original one but still the same. I've modified the above could if you want to examine it