I am trying to watch the folder of my "Camera" on my phone. This is an android phone and connected to my PC with WebDAV server which allows to map the phone as a driver; it works fine. (The mounted folder is the "Camera" in DCIM.) When I take a picture it should trigger a sub in my program. Half year ago it was working fine, now I've continued to develop my program and it's not working. (I've just reinstalled my PC, I guess this is the only thing I've changed.)
I read about a lot of trouble with filesystemwatcher over network drives.
I've already tried it with one another phone and PC too, but I had no luck.
It's working when I'm trying it with path "C:\"
The program can see the mapped drive/ folder, it doesn't stop at the checking code.
Also tried with copy and paste files to the given path instead of taking pictures...
Is there anything should I add or modify?
Here is my example code to illustrate...:
Imports System.IO
Public Class Form1
Public watchfolder As FileSystemWatcher
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim path As String
path = "Z:\"
watchfolder = New System.IO.FileSystemWatcher()
watchfolder.Path = path
If (Not System.IO.Directory.Exists(path)) Then MsgBox("Wrong path.")
watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.FileName
watchfolder.NotifyFilter = watchfolder.NotifyFilter Or IO.NotifyFilters.Attributes
AddHandler watchfolder.Changed, AddressOf logchange
AddHandler watchfolder.Created, AddressOf logchange
AddHandler watchfolder.Deleted, AddressOf logchange
AddHandler watchfolder.Error, AddressOf erroreventhandler 'I'm trying to read the error with this...
watchfolder.EnableRaisingEvents = True
End Sub
Private Sub logchange(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
MsgBox("This is the place where I'll call one sub in case of modification.")
End Sub
Sub erroreventhandler(sender As Object, e As ErrorEventArgs)
'this is to stop the program in case of error...
''it stops when I run the program on a mapped drive. (not on "C:\")
'''I could provide the error texts, I don't really familiar with them...
Stop
End Sub
End Class
Related
I am programming an android game with Godot 3.2.2. Of course I want to save the game data, therefore I created a new scene called SaveGame.tscn with SaveGame.gd. I exported the project to my windows pc and everything worked fine, all datas were saved. After that I also exported it to my android phone, but this time no data was saved. Instead it showed me that it could not find the save path. Maybe anybody of you can help me with this problem so that data is also saved on android.
SaveGame.gd:
extends Control
const FILE_NAME = "user://save_game_data_one.json"
var save_game_data
func _ready() -> void:
Signals.connect("load_data", self, "load")
Signals.connect("game_quit", self, "save")
save_game_data = {
"highscore": Globals.highscore,
"coins": Globals.coins,
"music_volume": Globals.music_volume,
"sound_volume": Globals.sound_volume,
"button_gameplay": Globals.button_gameplay,
"button_gameplay_side": Globals.button_gameplay_side,
}
func save():
update_data()
var file = File.new()
file.open(FILE_NAME, File.WRITE)
file.store_string(to_json(save_game_data))
file.close()
func load():
var file = File.new()
if file.file_exists(FILE_NAME):
file.open(FILE_NAME, File.READ)
var data = parse_json(file.get_as_text())
file.close()
if typeof(data) == TYPE_DICTIONARY:
save_game_data = data
else:
printerr("Corrupted data")
else:
self.show() <---- Here it shows me the hidden scene (white rectangle), this means it could not find FILE_NAME
export_data()
func export_data():
Globals.highscore = save_game_data["highscore"]
Globals.coins = save_game_data["coins"]
Globals.music_volume = save_game_data["music_volume"]
Globals.sound_volume = save_game_data["sound_volume"]
Globals.button_gameplay = save_game_data["button_gameplay"]
Globals.button_gameplay_side = save_game_data["button_gameplay_side"]
func update_data():
if Globals.score_round >= Globals.highscore:
save_game_data["highscore"] = Globals.score_round
save_game_data["coins"] += Globals.coins_round
I also would like to know the answer. I am trying to figure a way to have "persistent time" in my android game where "time passes" in game even when closed. Best solution I figure so far is getting the unix time on the games first start and check against it when reopening the app. My problem is finding a way to save that original unix time to call upon for checks.
I'm studying the android kernel as a beginner. I can read the messages thrown from the macro ERROR() inside the function main() at system/core/init/init.c using dmesg command through adb. I observed that after calling the function open_devnull_stdio() inside main(), dmesg no longer displays the messages thrown by ERROR().
To find the reason, I started digging into the declaration of open_devnull_stdio() inside system/core/init/util.c and I found this line I can't understand
static const char *name = "/dev/__null__";
Actually there was no file named __null__ inside /dev/ in the device, but there was a file named null and I was able to grab it using adb pull and it was a 0 byte (empty) file.
So why is a file name wrapped with double underscore (__) ?
Here is the link for the util.c
There is no special purpose of using double underscore before the start, after the end or both in C. From the point of view of C the file name is just a string, the operating system is free to interpret in whatever way it chooses. From the point of view of Linux, the same applies. Underscores in file names are just characters. They are not treated differently from the letters b and t.
If I guessed right and I'm reading the same file as you (it might be a good idea to link to the source code you're reading) then it should be pretty obvious what the code does on the lines after the one you mentioned. The next lines are:
if (mknod(name, S_IFCHR | 0600, (1 << 8) | 3) == 0) {
fd = open(name, O_RDWR);
unlink(name);
Which creates the null device which is then opened and immediately deleted again.
I suspect this is done so that programs can run without access to the root filesystem and still be able to open the equivalent of /dev/null.
I don't know the answer but I have an idea:
The following page shows an "strace" output where /dev/__null__ is used:
https://gist.github.com/tetsu-koba/1522515
Under Linux device files have a 33-bit (?) number which identifies the device. (At least under old Linux versions) you could delete some file in /dev and you could restore it or even create it in another directory (!) when you know the 33-bit number! (So you can delete the device /dev/sda2 and create the device (not file!) /home/myuser/sda2 instead.)
The trace in the link above shows the following three lines:
mknod("/dev/__null__", S_IFCHR|0600, makedev(1, 3)) = 0
open("/dev/__null__", O_RDWR|O_LARGEFILE) = 3
unlink("/dev/__null__") = 0
These lines will create the device file /dev/__null__ (with the 33-bit number identifying /dev/null). Then it opens that file and then it removes the file again.
Maybe this is done because the tool shall be able to run both on Linux installations where the device file "/dev/null" is present (in this case the file should not be overwritten) and on installations where that file is missing (in this case a replacement file must be created using the known 33-bit number).
As other people have pointed out this just tells it's the "null device", not a regular file called "null". null is supposed to act like an information sink, not like a normal file where you dump your data to. Hope this helps.
I'm having a confusing problem. I'm trying to make a Web cleint that uses WSDL.
I'm using C++ RAD Studio 10 Seattle, but the same problem occured in RAD Studio XE8(older version).
1.I create a Multi-Device Application, add one Edit component and one Button.
2.I create a WSDL Importer by changing the location of the WSDL file to : "http://www.w3schools.com/webservices/tempconvert.asmx?WSDL" and leave all other setting to default.
3.On ButtonClick event of the button I write two lines of code :
_di_TempConvertSoap Converter = GetTempConvertSoap(true,
"http://www.w3schools.com/webservices/tempconvert.asmx?WSDL");
Edit1->Text = Converter->CelsiusToFahrenheit("32");
So after these three steps I have one unit, which is the main Unit with the Form and with the button event. And one file "tempconvert.cpp" that the WSDL Importer has generated. It quite actually just translates the WSDL code to a C++ one and defines the method to communicate with the server. In my case I have two methods : FahrenheitToCelsius() and CelsiusToFahrenheit(), in the example I use CelsiusToFahrenheit().
I compile it to 32-bit Windows platform, run it and when I click the button, the result "89.6" appears in the text of the Edit component. So this is working as expected.
But when I change the target platform to "Android" and use my mobile phone "Samsung GT-I8262" with Android 4.1.2 and run the project, it just stops and exits. I debugged the problem and it stops at the first command in "tempconvert.cpp" in RegTypes() method.
// ************************************************************************
//
// This routine registers the interfaces and types exposed by the WebService.
// ************************************************************************ //
static void RegTypes()
{
/* TempConvertSoap */
InvRegistry()->RegisterInterface(__delphirtti(TempConvertSoap), L"http://www.w3schools.com/webservices/", L"utf-8");
InvRegistry()->RegisterDefaultSOAPAction(__delphirtti(TempConvertSoap), L"http://www.w3schools.com/webservices/%operationName%");
InvRegistry()->RegisterInvokeOptions(__delphirtti(TempConvertSoap), ioDocument);
/* TempConvertSoap.FahrenheitToCelsius */
InvRegistry()->RegisterMethodInfo(__delphirtti(TempConvertSoap), "FahrenheitToCelsius", "",
"[ReturnName='FahrenheitToCelsiusResult']", IS_OPTN);
/* TempConvertSoap.CelsiusToFahrenheit */
InvRegistry()->RegisterMethodInfo(__delphirtti(TempConvertSoap), "CelsiusToFahrenheit", "",
"[ReturnName='CelsiusToFahrenheitResult']", IS_OPTN);
/* TempConvertHttpPost */
InvRegistry()->RegisterInterface(__delphirtti(TempConvertHttpPost), L"http://www.w3schools.com/webservices/", L"utf-8");
InvRegistry()->RegisterDefaultSOAPAction(__delphirtti(TempConvertHttpPost), L"");
}
#pragma startup RegTypes 32
Does someone have any idea why this might be happening? I tried on two other Samsung phones and it didn't work. The error that shuts the program down is "Segmentation fault(11)", and more precisely it stops at the following line of code in "System.pas" file :
u_strFromUTF8(PUChar(Dest), MaxDestChars, DestLen, MarshaledAString(Source), SourceBytes, ErrorConv);
Here is some info that I've found about the function:
u_strFromUTF8 - function that converts a UTF-8 string to UTF-16.
UCHAR is a Byte(in Delphi), so PUCHAR is a pointer to Byte.
I cannot se what could possibly go wrong with this function which apparently only converts a string.
So my question is why does the project work on Windows 32 bit version, but on Android it throws Segmentation fault(11)?
I hope I could find a solution for this problem. I will keep looking.
Thank you,
Zdravko Donev :)
UPDATE:
I disassembled the line:
InvRegistry()->RegisterInterface(__delphirtti(TempConvertSoap), L"http://www.w3schools.com/webservices/", L"utf-16");
to get :
TInvokableClassRegistry *Class = InvRegistry();
TTypeInfo *Info = __delphirtti(TempConvertSoap);
UnicodeString Namespace = "http://www.w3schools.com/webservices/";
UnicodeString WSDLEncoding = "utf-8";
Class->RegisterInterface(Info, Namespace, WSDLEncoding);
And I saw that the problem occurs when calling InvRegistry() function, but I still haven't found the problem as I cannot reach the source code of the function.
I found a solution.
I deleted the line
#pragma startup RegTypes 32
and called the method RegTypes() on my own when I create the form and it worked.
I want to access a android device from python to download some photos.
libmtp works from the CLI.
Than pymtp. It's been around for a while but it's designed for python 2 and i'm using python 3. Meanwhile fixed several minor issues but i'm stuck at an error from function get_filelisting
specially this section:
ret = []
next = files
while next:
ret.append(next.contents)
if (next(next.contents) is None):
break
next = next(next.contents)
The error is related to the "next".
That section looks strange to me, i've been coding in python for a while but i'm new to ctypes. Tried a lot of variants, they all failed. The "next" could be confusing with python buildin function so i renamed it to nextpointer and came to this code:
ret = []
nextpointer = files
while nextpointer:
ret.append(nextpointer.contents)
nextpointer = nextpointer.contents.next
It seems to work but did it work by accident ? does it have any design flaws ? Could anyone with experience on python ctypes confirm this a solution ? Any suggestion welcome.
From python2.7 documentation
next(iterator[, default])
Retrieve the next item from the iterator by calling its next() method. If default is given, it is returned if the iterator is
exhausted, otherwise StopIteration is raised.
from python3 documentation
next(iterator[, default])
Retrieve the next item from the iterator by calling its __next__() method. If default is given, it is returned if the iterator is
exhausted, otherwise StopIteration is raised.
Notice that next() method was removed from python3 but the function still exists.
This is all I can say about the next function and .next()/__next__() methods.
I downloaded the pymtp module and get_filelisting() is slightly different from what you posted in your ported code, here it is:
ret = []
next = files
while next:
ret.append(next.contents)
if (next.contents.next == None):
break
next = next.contents.next
If none of this helped you (which probably didn't :D), the version of pymtp library that I am using is 0.0.6 download using pip.
I want to save some user credentials in my qt application that runs on Android.
I use QSettings for this like so:
QString appPath = QCoreApplication::applicationDirPath()+QLatin1Char('/');
set = new QSettings(appPath+"test",
QSettings::NativeFormat);
set->setValue ( "user/username", "NameOfTheUser" );
set->setValue ( "user/password", "UserPassword" );
set->sync();
I restart the app and inside an initialize() method I have:
QString username(set->value("user/username",
( QVariant ) tr ( "defaultUser" ) ).toString());
QString password(set->value("user/password",
( QVariant ) tr ( "defaultPass" ) ).toString());
The username and password vars are not read from the QSettings.
The same code is working on Windows.
Thank you
I also ran into similar problem and found out that 2 things should be done:
path to settings file should be specified
QSettings::sync() should be explicitly called after every settings change.
So on Windows I had this working:
QSettings settings("settings.ini", QSettings::IniFormat);
settings.setValue(GRID_ENABLED, enabled);
On Android I have to use the following code:
QSettings settings("/sdcard/settings.ini", QSettings::NativeFormat); //can be IniFormat, no difference
settings.setValue(GRID_ENABLED, enabled);
settings.sync();
Probably using "sdcard" is not good enough and you should use other directory.
You can try to specify the location of the setting file to a writable location which exists even if the application is removed :
#include <QSettings>
#include <QStandardPaths>
QString path ;
QString filename;
path = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) ;
filename = “config.ini” ;
QSettings settings(path + “/”+ filename,QSettings::IniFormat) ;
Here QStandardPaths::GenericDataLocation returns a directory location where persistent data shared across applications can be stored and it is never empty.
Also you can set the application and organization name in the main of your application once :
qApp->setOrganizationName("Company");
qApp->setApplicationName("App");
As noted, a re-deploy of the application from Qt Creator wipes the settings.
This is still true in Qt Creator 3.3.2 with the following caveat. When you deploy the app on Android and look at the Application Output window, there is a tool bar with a "stop" button (red square) and a "Re-run this run configuration" button (green triangle).
The initial deploy from Qt starts the app. The QSettings object is cleared or empty. Any changes to the QSettings object will be saved in the object.
If you stop the app with the red button, then immediately restart the app with the green Re-run button, the app will restart and all changes to the QSettings object in the previous run will still be there.
I assume this emulates the start, exit, restart of the app on a device.
Hi I've found the solution, tested on 3 different Android device. You can set the following path for your settings.
mPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
QString filename = "se.ini";
mPath = mPath + "/" + filename;
By following code you save your info under above location.
void ProfileManager::saveToRegistery()
{
QSettings settings(mPath , QSettings::NativeFormat);
settings.setValue("SE/Mail" , mMail);
settings.setValue("SE/Pass" , mPass);
settings.sync();
}
If you have any trouble with saving that place, you ask user permission for accessing any file with:
bool QAndroidPermissions::requestPermissions()
{
QtAndroid::PermissionResult r =
QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
if(r == QtAndroid::PermissionResult::Denied) {
QtAndroid::requestPermissionsSync( QStringList() <<
"android.permission.WRITE_EXTERNAL_STORAGE" );
r =QtAndroid::checkPermission("android.permission.WRITE_EXTERNAL_STORAGE");
if(r == QtAndroid::PermissionResult::Denied) {
return false;
}
}
return true;
}
Hope this helps,
I had a problem similar to the above, and it turned out that everything worked just fine. That is it did work with a simple QSettings object without any arguments.
HOWEVER, every time I re-deployed the application from Qt Creator, the settings file was destroyed, leading me to the conclusion that QSettings did not work.
The problem should, according to Bogdan himself, have been fixed in Qt Creator 3.2
The only problem with your code is that for Android you have to use QStandartPaths to get path and not the QCoreApplication::applicationDirPath().
QCoreApplication::applicationDirPath() will give you the windows application path to your Android Application, which won't work on Android.