Can i open directory from jump list - wpf

Im writing WPF application and want to add ability to call jump list and open program configuration, app.config or log directory from it. Is it possible(cant find the way to do that..just JumpTasks with application path and JumpPath with path to file, and not just path to be opened via explorer)?

Found answer here. Seems that JumpList wasnt designed for opening anything but files or applications, associated with current program. So that when we see directories in explorer tasklist -it actually means: use explorer with parameters. By the way ill try to use it.
Update
made it with such code:
string explorerPath = #"%windir%\explorer.exe";
JumpTask path = new JumpTask
{
CustomCategory = "Paths",
Title = "Open program directory",
IconResourcePath = explorerPath,
ApplicationPath = explorerPath,
Arguments = #"/root," + AppDomain.CurrentDomain.BaseDirectory,
Description = AppDomain.CurrentDomain.BaseDirectory
};
Im leaving this answer here, because someone can have similar incomprehension.

Related

Sshj library for download multifiles in remote server

I use Java 8 and my condition is to download multiple file in a remote server using sftp protocol, is not necessary to filter file for his name but necessary to download all file in a specific remote folder.
i see the library com.hierynomus » sshj for this scope, but looking on the net i haven't found what i need, only for download a single file.
What i think is i could use this method,
String localDir = "/home";
String remoteFile = "/home/folder/*"
SSHClient sshClient = setupSshj();
SFTPClient sftpClient = sshClient.newSFTPClient();
sftpClient.get(remoteFile, localDir);
but i'm not sure if the asterisk in the "remoteFile" will be useful for my purpose...
Unfortunately for now i can't try this on remote server ...
Someone can help me?
Thank's everyone
You need to LIST all the files you want to download:
List<RemoteResourceInfo> entries = sftpClient.ls("/home/folder")
After that you will loop the entries to download them one by one:
for (RemoteResourceInfo remoteFile : entries) {
if(remoteFile.isRegularFile()){
sftpClient.get(remoteFile.getPath(), localDir);
}
}
E: Also you should check if the list entry is really a file, edited the code accordingly. Though I am not sure whether using !remoteFile.isDirectory() would be better.

Access Shared Preferences externally / Store a value into a new file and access it externally

I have the two following methods and I am using them to store a special value locally and be able to access it on application restart:
(Store value locally:)
private void SaveSet(string key, string value)
{
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
ISharedPreferencesEditor prefEditor = prefs.Edit();
prefEditor.PutString(key, value);
// editor.Commit(); // applies changes synchronously on older APIs
prefEditor.Apply(); // applies changes asynchronously on newer APIs
}
(Read it again:)
private string RetrieveSet(string key)
{
ISharedPreferences prefs = PreferenceManager.GetDefaultSharedPreferences(this);
return prefs.GetString(key, null);
}
This works perfectly. Now is it possible to access and edit this Shared Preferences externally? Unfortunately, I cannot find any file when searching in folder
Phone\Android\data\com.<company_name>.<application_name>\files
nor anywhere else. I want / try to edit this value from my computer, after connecting the phone to it. Is this possible?
Alternatively: Can anyone maybe show me how to create a new file in the given path above, write/read it programmatically and how it stays there, even if application is closed / started again? So I can then edit this file with my computer anyhow?
I tried it with the following code, but unfortunately it doesn't work / no file is created or at least i cannot see it in the given path above:
//"This code snippet is one example of writing an integer to a UTF-8 text file to the internal storage directory of an application:"
public void SaveValueIntoNewFile(int value)
{
var backingFile = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "newFile.txt");
using (var writer = System.IO.File.CreateText(backingFile))
{
writer.WriteLine(value.ToString());
}
}
Would be very happy about every answer, thanks in advance and best regards
What you're looking for is where Android stores the Shared Preference file for applications that make use of it's default PreferenceManager.
I'd refer to this SO post which answers your question pretty well
SharedPreferences are stored in an xml file in the app data folder,
i.e.
/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PREFS_NAME.xml
or the default preferences at:
/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml
SharedPreferences added during runtime are not stored in the Eclipse
project.
Note: Accessing /data/data/ requires superuser
privileges
A simple method is to use Android Device Monotor,you can open it by clicking Tools--> android-->Android Device Monotor...
For example:
The path in my device is as follows:
/data/data/YOUR_PACKAGE_NAME/shared_prefs/YOUR_PACKAGE_NAME_preferences.xml
And we notice three buttons in the upper right corner of the picture.
The first one is used toPull a file from the device,the second one is used to Push a file onto the device,and the last one is used to delete the preferences.xml file.
So we can pull the preferences.xml file from current device to our computer and edit it as we want, and then push the updated preferences.xml to the folder again.Then we will get the value of preferences.xml file .

Copying a file to the root path in Codename One

In my code I am prompting the user to load a json file.
I am then attempting to copy this file into an sqlite database.
Once I have the data I am then able to manipulate it as needed - but I need to get it there in the first place.
So step 1 is to get the data in.
I have progressed as far as prompting the user to navigate to the file they want - but when I try and read the file I get this error ..
ERROR: resources must reside in the root directory thus must start with a '/' character in Codename One! Invalid resource: file:///tmp/temp3257201851214246357..json
So I think that I need to copy this file to the root directory
I cannot find a link that shows me how to do this.
Here is my code so far ...
case "Import Script":
try
{
JSONParser json = new JSONParser();
if (FileChooser.isAvailable()) {
FileChooser.showOpenDialog(".json", e2-> {
String file = (String)e2.getSource();
if (file == null) {
home.add("No file was selected");
home.revalidate();
} else {
home.add("Please wait - busy importing");
home.revalidate();
String extension = null;
if (file.lastIndexOf(".") > 0) {
extension = file.substring(file.lastIndexOf(".")+1);
}
if ("json".equals(extension)) {
FileSystemStorage fs = FileSystemStorage.getInstance();
try {
InputStream fis = fs.openInputStream(file);
try(Reader r = new InputStreamReader(Display.getInstance().getResourceAsStream(getClass(), file), "UTF-8"))
{
Map<String, Object> data = json.parseJSON(r);
Result result = Result.fromContent(data);
...... I progress from here
The error is occurring on this line ...
try(Reader r = new InputStreamReader(Display.getInstance().getResourceAsStream(getClass(), file), "UTF-8"))
If I hard code a filename and manually place it in the /src folder it works ... like this ...
try(Reader r = new InputStreamReader(Display.getInstance().getResourceAsStream(getClass(), '/test.json'), "UTF-8"))
But that defeats the purpose of them selecting a file
Any help would be appreciated
Thanks
I suggest watching this video.
It explains the different ways data is stored. One of the core sources of confusion is the 3 different ways to store files:
Resources
File System
Storage
getResourceAsStream returns a read only path that's physically embedded in the jar. It's flat so all paths to getResourceAsStream must start with / and must have only one of those. I would suggest avoiding more than one . as well although this should work in theory.
The sqlite database must be stored in file system which is encapsulated as FileSystemStorage and that's really the OS native file system. But you can't store it anywhere you want you need to give the DB name to the system and it notifies you where the file is stored and that's whats explained in the code above.

how to create files under /WEB-INF/

I am working on an application that stores files under /WEB-INF/someFolder/. But I dont find the right way to create files under this folder. I did this, but it is not working:
File newFile = new File("/WEB-INF/fileName.xml");
When I try to check the creation:
boolean isCreated = newFile.createNewFile();
I get :
java.io.IOException: No such file or directory
Please help me doing it in the right way.
Update:
I did this workaround, it is working but I dont see that it is performant solution.
ServletContext servletContext = getServletContext();
String path = servletContext.getRealPath("/WEB-INF/");
File newFile2 = new File(path+"/fileName.xml");
Any ideas?
You shall use ServletContext.getRealPath(String) and build the entire classpath manually
String webInfPath = getServletConfig().getServletContext().getRealPath("WEB-INF");
OR go step by step:
ServletConfig scfg= getServletConfig();
ServletContext scxt = scfg.getServletContext();
String webInfPath = sxct.getRealPath("WEB-INF");
And than use the webInfPath to create a File object inside WEB-INF
File newFile = new File(webInfPath + "/fileName.xml");
make sure you applaction have the permissions to write.
you can get the path ues like this:
String path=Thread.currentThread().getContextClassLoader().getResource("com/youpackage/");
Now you get the path which is your class folder path,so you can get the WEB-INF path.
ps: i remember when create file you must writer some content,otherwies it may not create.

Specifying Qt Output Directory

In Qt in a Linux environment, how would I go about specifying that one file my application creates goes into a specific, hard-coded directory while another file created at the same time goes into a different hard-coded directory?
I am not sure what you want to do but does this work?
QFile aFile("/some/hard/coded/path/filename");
QFile anotherFile("/another/hard/coded/path/filename");
I'm not sure about files other than MOC, obj, ui, rcc, and executable files, but you can specify where each of them go with the following:
Release:DESTDIR = release
Release:OBJECTS_DIR = release/.obj
Release:MOC_DIR = release/.moc
Release:RCC_DIR = release/.rcc
Release:UI_DIR = release/.ui
Debug:DESTDIR = debug
Debug:OBJECTS_DIR = debug/.obj
Debug:MOC_DIR = debug/.moc
Debug:RCC_DIR = debug/.rcc
Debug:UI_DIR = debug/.ui
If you want to set the output path for other files that are generated, I don't know if it is possible (you might need a custom build step, though I might be wrong)

Resources