mirror of https://github.com/FreeRDP/FreeRDP
libfreerdp-utils: purge old file utils
This commit is contained in:
parent
edf6e7258d
commit
068f0de4d4
|
@ -35,7 +35,6 @@
|
|||
#include <freerdp/channels/channels.h>
|
||||
#include <freerdp/svc.h>
|
||||
#include <freerdp/addin.h>
|
||||
#include <freerdp/utils/file.h>
|
||||
#include <freerdp/utils/event.h>
|
||||
#include <freerdp/utils/debug.h>
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#include <freerdp/utils/event.h>
|
||||
#include <freerdp/constants.h>
|
||||
#include <freerdp/locale/keyboard.h>
|
||||
#include <freerdp/utils/file.h>
|
||||
|
||||
#include <android/bitmap.h>
|
||||
#include <machine/cpu-features.h>
|
||||
|
@ -533,11 +532,13 @@ JNIEXPORT void JNICALL jni_freerdp_set_data_directory(JNIEnv *env, jclass cls, j
|
|||
rdpSettings * settings = inst->settings;
|
||||
|
||||
const jbyte *directory = (*env)->GetStringUTFChars(env, jdirectory, NULL);
|
||||
|
||||
free(settings->HomePath);
|
||||
free(settings->ConfigPath);
|
||||
|
||||
settings->HomePath = strdup(directory);
|
||||
settings->ConfigPath = NULL;
|
||||
freerdp_detect_paths(settings);
|
||||
|
||||
(*env)->ReleaseStringUTFChars(env, jdirectory, directory);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* File Utils
|
||||
*
|
||||
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FREERDP_UTILS_FILE_H
|
||||
#define FREERDP_UTILS_FILE_H
|
||||
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/settings.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
FREERDP_API void freerdp_mkdir(char* path);
|
||||
FREERDP_API char* freerdp_get_home_path(rdpSettings* settings);
|
||||
FREERDP_API char* freerdp_get_config_path(rdpSettings* settings);
|
||||
FREERDP_API char* freerdp_construct_path(char* base_path, char* relative_path);
|
||||
FREERDP_API void freerdp_detect_paths(rdpSettings* settings);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* FREERDP_UTILS_FILE_H */
|
|
@ -31,8 +31,6 @@
|
|||
#include <openssl/pem.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
#include <freerdp/utils/file.h>
|
||||
|
||||
#include "certificate.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -29,11 +29,12 @@
|
|||
#endif
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/sysinfo.h>
|
||||
#include <winpr/registry.h>
|
||||
|
||||
#include <freerdp/settings.h>
|
||||
#include <freerdp/utils/file.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#pragma warning(push)
|
||||
|
@ -409,7 +410,8 @@ rdpSettings* freerdp_settings_new(void* instance)
|
|||
malloc(sizeof(ADDIN_ARGV*) * settings->DynamicChannelArraySize);
|
||||
ZeroMemory(settings->DynamicChannelArray, sizeof(ADDIN_ARGV*) * settings->DynamicChannelArraySize);
|
||||
|
||||
freerdp_detect_paths(settings);
|
||||
settings->HomePath = GetKnownPath(KNOWN_PATH_HOME);
|
||||
settings->ConfigPath = GetKnownSubPath(KNOWN_PATH_CONFIG, "freerdp");
|
||||
|
||||
settings_load_hkey_local_machine(settings);
|
||||
}
|
||||
|
|
|
@ -27,12 +27,12 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/path.h>
|
||||
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/rsa.h>
|
||||
|
||||
#include <freerdp/utils/file.h>
|
||||
|
||||
static const char certificate_store_dir[] = "certs";
|
||||
static const char certificate_known_hosts_file[] = "known_hosts";
|
||||
|
||||
|
@ -40,21 +40,19 @@ static const char certificate_known_hosts_file[] = "known_hosts";
|
|||
|
||||
void certificate_store_init(rdpCertificateStore* certificate_store)
|
||||
{
|
||||
char* config_path;
|
||||
rdpSettings* settings;
|
||||
|
||||
settings = certificate_store->settings;
|
||||
|
||||
config_path = freerdp_get_config_path(settings);
|
||||
certificate_store->path = freerdp_construct_path(config_path, (char*) certificate_store_dir);
|
||||
certificate_store->path = GetCombinedPath(settings->ConfigPath, (char*) certificate_store_dir);
|
||||
|
||||
if (PathFileExistsA(certificate_store->path) == FALSE)
|
||||
{
|
||||
freerdp_mkdir(certificate_store->path);
|
||||
CreateDirectoryA(certificate_store->path, 0);
|
||||
printf("creating directory %s\n", certificate_store->path);
|
||||
}
|
||||
|
||||
certificate_store->file = freerdp_construct_path(config_path, (char*) certificate_known_hosts_file);
|
||||
certificate_store->file = GetCombinedPath(settings->ConfigPath, (char*) certificate_known_hosts_file);
|
||||
|
||||
if (PathFileExistsA(certificate_store->file) == FALSE)
|
||||
{
|
||||
|
|
|
@ -22,7 +22,6 @@ set(${MODULE_PREFIX}_SRCS
|
|||
event.c
|
||||
bitmap.c
|
||||
list.c
|
||||
file.c
|
||||
passphrase.c
|
||||
pcap.c
|
||||
profiler.c
|
||||
|
|
|
@ -1,105 +0,0 @@
|
|||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Implementation
|
||||
* File Utils
|
||||
*
|
||||
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/path.h>
|
||||
|
||||
#include <freerdp/types.h>
|
||||
#include <freerdp/settings.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#include <direct.h>
|
||||
#define getcwd _getcwd
|
||||
#endif
|
||||
|
||||
#include <winpr/windows.h>
|
||||
#include <freerdp/utils/file.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#define PATH_SEPARATOR_STR "/"
|
||||
#define PATH_SEPARATOR_CHR '/'
|
||||
#else
|
||||
#define PATH_SEPARATOR_STR "\\"
|
||||
#define PATH_SEPARATOR_CHR '\\'
|
||||
#endif
|
||||
|
||||
#define FREERDP_CONFIG_DIR ".freerdp"
|
||||
|
||||
void freerdp_mkdir(char* path)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
mkdir(path, S_IRUSR | S_IWUSR | S_IXUSR);
|
||||
#else
|
||||
CreateDirectoryA(path, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
char* freerdp_get_home_path(rdpSettings* settings)
|
||||
{
|
||||
settings->HomePath = GetKnownPath(KNOWN_PATH_HOME);
|
||||
return settings->HomePath;
|
||||
}
|
||||
|
||||
char* freerdp_get_config_path(rdpSettings* settings)
|
||||
{
|
||||
if (settings->ConfigPath != NULL)
|
||||
return settings->ConfigPath;
|
||||
|
||||
settings->ConfigPath = (char*) malloc(strlen(settings->HomePath) + sizeof(FREERDP_CONFIG_DIR) + 2);
|
||||
sprintf(settings->ConfigPath, "%s" PATH_SEPARATOR_STR "%s", settings->HomePath, FREERDP_CONFIG_DIR);
|
||||
|
||||
if (!PathFileExistsA(settings->ConfigPath))
|
||||
freerdp_mkdir(settings->ConfigPath);
|
||||
|
||||
return settings->ConfigPath;
|
||||
}
|
||||
|
||||
char* freerdp_construct_path(char* base_path, char* relative_path)
|
||||
{
|
||||
char* path;
|
||||
int length;
|
||||
int base_path_length;
|
||||
int relative_path_length;
|
||||
|
||||
base_path_length = strlen(base_path);
|
||||
relative_path_length = strlen(relative_path);
|
||||
length = base_path_length + relative_path_length + 1;
|
||||
|
||||
path = malloc(length + 1);
|
||||
sprintf(path, "%s" PATH_SEPARATOR_STR "%s", base_path, relative_path);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void freerdp_detect_paths(rdpSettings* settings)
|
||||
{
|
||||
freerdp_get_home_path(settings);
|
||||
freerdp_get_config_path(settings);
|
||||
}
|
|
@ -33,12 +33,13 @@
|
|||
#include <sys/select.h>
|
||||
|
||||
#include <winpr/crt.h>
|
||||
#include <winpr/file.h>
|
||||
#include <winpr/path.h>
|
||||
#include <winpr/synch.h>
|
||||
|
||||
#include <freerdp/freerdp.h>
|
||||
#include <freerdp/locale/keyboard.h>
|
||||
#include <freerdp/codec/color.h>
|
||||
#include <freerdp/utils/file.h>
|
||||
#include <freerdp/locale/keyboard.h>
|
||||
|
||||
#include "xf_input.h"
|
||||
#include "xf_encode.h"
|
||||
|
@ -544,13 +545,13 @@ void* xf_peer_main_loop(void* arg)
|
|||
|
||||
/* Initialize the real server settings here */
|
||||
|
||||
server_file_path = freerdp_construct_path(settings->ConfigPath, "server");
|
||||
server_file_path = GetCombinedPath(settings->ConfigPath, "server");
|
||||
|
||||
if (!PathFileExistsA(server_file_path))
|
||||
freerdp_mkdir(server_file_path);
|
||||
CreateDirectoryA(server_file_path, 0);
|
||||
|
||||
settings->CertificateFile = freerdp_construct_path(server_file_path, "server.crt");
|
||||
settings->PrivateKeyFile = freerdp_construct_path(server_file_path, "server.key");
|
||||
settings->CertificateFile = GetCombinedPath(server_file_path, "server.crt");
|
||||
settings->PrivateKeyFile = GetCombinedPath(server_file_path, "server.key");
|
||||
|
||||
settings->RemoteFxCodec = TRUE;
|
||||
settings->ColorDepth = 32;
|
||||
|
|
|
@ -257,18 +257,23 @@ WINPR_API BOOL FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData
|
|||
|
||||
WINPR_API BOOL FindClose(HANDLE hFindFile);
|
||||
|
||||
WINPR_API BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
|
||||
WINPR_API BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
|
||||
|
||||
#ifdef UNICODE
|
||||
#define CreateFile CreateFileW
|
||||
#define DeleteFile DeleteFileW
|
||||
#define FindFirstFile FindFirstFileW
|
||||
#define FindFirstFileEx FindFirstFileExW
|
||||
#define FindNextFile FindNextFileW
|
||||
#define CreateDirectory CreateDirectoryW
|
||||
#else
|
||||
#define CreateFile CreateFileA
|
||||
#define DeleteFile DeleteFileA
|
||||
#define FindFirstFile FindFirstFileA
|
||||
#define FindFirstFileEx FindFirstFileExA
|
||||
#define FindNextFile FindNextFileA
|
||||
#define CreateDirectory CreateDirectoryA
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -266,6 +266,8 @@ WINPR_API PCWSTR PathGetSharedLibraryExtensionW(unsigned long dwFlags);
|
|||
#define KNOWN_PATH_RUNTIME 6
|
||||
|
||||
WINPR_API char* GetKnownPath(int id);
|
||||
WINPR_API char* GetKnownSubPath(int id, char* path);
|
||||
WINPR_API char* GetCombinedPath(char* basePath, char* subPath);
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
|
|
|
@ -426,5 +426,18 @@ BOOL FindClose(HANDLE hFindFile)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
||||
{
|
||||
if (!mkdir(lpPathName, S_IRUSR | S_IWUSR | S_IXUSR))
|
||||
return TRUE;
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -719,7 +719,7 @@ HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags
|
|||
{
|
||||
size_t index;
|
||||
|
||||
if (dwFlags & PATH_STYLE_WINDOWS)
|
||||
if (dwFlags == PATH_STYLE_WINDOWS)
|
||||
{
|
||||
for (index = 0; index < cchPath; index++)
|
||||
{
|
||||
|
@ -727,7 +727,7 @@ HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags
|
|||
pszPath[index] = PATH_BACKSLASH_CHR;
|
||||
}
|
||||
}
|
||||
else if (dwFlags & PATH_STYLE_UNIX)
|
||||
else if (dwFlags == PATH_STYLE_UNIX)
|
||||
{
|
||||
for (index = 0; index < cchPath; index++)
|
||||
{
|
||||
|
@ -735,7 +735,7 @@ HRESULT PathCchConvertStyleA(PSTR pszPath, size_t cchPath, unsigned long dwFlags
|
|||
pszPath[index] = PATH_SLASH_CHR;
|
||||
}
|
||||
}
|
||||
else if (dwFlags & PATH_STYLE_NATIVE)
|
||||
else if (dwFlags == PATH_STYLE_NATIVE)
|
||||
{
|
||||
if (PATH_SEPARATOR_CHR == PATH_BACKSLASH_CHR)
|
||||
{
|
||||
|
@ -776,7 +776,7 @@ HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlag
|
|||
{
|
||||
size_t index;
|
||||
|
||||
if (dwFlags & PATH_STYLE_WINDOWS)
|
||||
if (dwFlags == PATH_STYLE_WINDOWS)
|
||||
{
|
||||
for (index = 0; index < cchPath; index++)
|
||||
{
|
||||
|
@ -784,7 +784,7 @@ HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlag
|
|||
pszPath[index] = PATH_BACKSLASH_CHR;
|
||||
}
|
||||
}
|
||||
else if (dwFlags & PATH_STYLE_UNIX)
|
||||
else if (dwFlags == PATH_STYLE_UNIX)
|
||||
{
|
||||
for (index = 0; index < cchPath; index++)
|
||||
{
|
||||
|
@ -792,7 +792,7 @@ HRESULT PathCchConvertStyleW(PWSTR pszPath, size_t cchPath, unsigned long dwFlag
|
|||
pszPath[index] = PATH_SLASH_CHR;
|
||||
}
|
||||
}
|
||||
else if (dwFlags & PATH_STYLE_NATIVE)
|
||||
else if (dwFlags == PATH_STYLE_NATIVE)
|
||||
{
|
||||
if (PATH_SEPARATOR_CHR == PATH_BACKSLASH_CHR)
|
||||
{
|
||||
|
|
|
@ -252,6 +252,51 @@ char* GetKnownPath(int id)
|
|||
return path;
|
||||
}
|
||||
|
||||
char* GetKnownSubPath(int id, char* path)
|
||||
{
|
||||
char* subPath;
|
||||
char* knownPath;
|
||||
|
||||
knownPath = GetKnownPath(id);
|
||||
subPath = GetCombinedPath(knownPath, path);
|
||||
|
||||
free(knownPath);
|
||||
|
||||
return subPath;
|
||||
}
|
||||
|
||||
char* GetCombinedPath(char* basePath, char* subPath)
|
||||
{
|
||||
int length;
|
||||
HRESULT status;
|
||||
char* path = NULL;
|
||||
int basePathLength;
|
||||
int subPathLength;
|
||||
|
||||
basePathLength = strlen(basePath);
|
||||
subPathLength = strlen(subPath);
|
||||
|
||||
length = basePathLength + subPathLength + 1;
|
||||
path = (char*) malloc(length + 1);
|
||||
|
||||
CopyMemory(path, basePath, basePathLength);
|
||||
path[basePathLength] = '\0';
|
||||
|
||||
PathCchConvertStyleA(path, basePathLength, PATH_STYLE_NATIVE);
|
||||
|
||||
if (!subPath)
|
||||
return path;
|
||||
|
||||
subPath = _strdup(subPath);
|
||||
PathCchConvertStyleA(subPath, subPathLength, PATH_STYLE_NATIVE);
|
||||
|
||||
status = NativePathCchAppendA(path, length + 1, subPath);
|
||||
|
||||
free(subPath);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
BOOL PathFileExistsA(LPCSTR pszPath)
|
||||
|
|
|
@ -27,6 +27,9 @@ int TestPathShell(int argc, char* argv[])
|
|||
path = GetKnownPath(KNOWN_PATH_RUNTIME);
|
||||
printf("KNOWN_PATH_RUNTIME: %s\n", path);
|
||||
|
||||
path = GetKnownSubPath(KNOWN_PATH_CONFIG, "freerdp");
|
||||
printf("KNOWN_PATH_CONFIG SubPath: %s\n", path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue