diff --git a/uppsrc/Core/App.cpp b/uppsrc/Core/App.cpp index f13ae6c52..0f9d25b37 100644 --- a/uppsrc/Core/App.cpp +++ b/uppsrc/Core/App.cpp @@ -466,12 +466,26 @@ void LaunchWebBrowser(const String& url) #endif +String sDataPath; + +void SetDataPath(const char *path) +{ + sDataPath = path; +} + String GetDataFile(const char *filename) { + if(sDataPath.GetCount()) + return AppendFileName(sDataPath, filename); String s = GetEnv("UPP_MAIN__"); return s.GetCount() ? AppendFileName(s, filename) : GetExeDirFile(filename); } +String LoadDataFile(const char *filename) +{ + return LoadFile(GetDataFile(filename)); +} + String GetComputerName() { char temp[256]; diff --git a/uppsrc/Core/App.h b/uppsrc/Core/App.h index e5f30a100..e1b8fa676 100644 --- a/uppsrc/Core/App.h +++ b/uppsrc/Core/App.h @@ -76,6 +76,8 @@ void ConsoleMainFn_() #endif String GetDataFile(const char *filename); +String LoadDataFile(const char *filename); +void SetDataPath(const char *path); void LaunchWebBrowser(const String& url); diff --git a/uppsrc/Core/src.tpp/AppEnv$en-us.tpp b/uppsrc/Core/src.tpp/AppEnv$en-us.tpp index 4e3552964..168d35056 100644 --- a/uppsrc/Core/src.tpp/AppEnv$en-us.tpp +++ b/uppsrc/Core/src.tpp/AppEnv$en-us.tpp @@ -106,9 +106,20 @@ application was started from `'theide`' `- in that case theide passes a reference to main package directory through environment variable `"UPP`_MAIN`_`_`" and the resulting file is in this directory. When started standalone, the function is equivalent -to GetExeDirFile.&] +to GetExeDirFile. Alternatively, application can call SetDataPath +to define the directory.&] [s3; &] [s4; &] +[s5;:LoadDataFile`(const char`*`): [_^String^ String]_[* LoadDataFile]([@(0.0.255) const]_[@(0.0.255) c +har]_`*[*@3 filename])&] +[s2;%% Same as LoadFile(GetDataFile([%-*@3 filename])).&] +[s3;%% &] +[s4; &] +[s5;:SetDataPath`(const char`*`): [@(0.0.255) void]_[* SetDataPath]([@(0.0.255) const]_[@(0.0.255) c +har]_`*[*@3 path])&] +[s2;%% Defines explicit directory to be used with GetDataFile.&] +[s3;%% &] +[s4; &] [s5;:GetComputerName`(`): [_^String^ String]_[* GetComputerName]()&] [s2;%% Returns the name of computer.&] [s3; &] diff --git a/uppsrc/plugin/lzma/lzma.cpp b/uppsrc/plugin/lzma/lzma.cpp index d0bc741f6..500cd306a 100644 --- a/uppsrc/plugin/lzma/lzma.cpp +++ b/uppsrc/plugin/lzma/lzma.cpp @@ -221,6 +221,20 @@ int64 LZMADecompress(Stream& out, Stream& in, Gate2 progress) return Decode(&lout.s, &lin.s, progress) == SZ_OK && !in.IsError() && !out.IsError() ? lout.len : -1; } +String LZMADecompress(const void *data, int64 len, Gate2 progress) +{ + StringStream out; + MemReadStream in(data, len); + if(LZMADecompress(out, in, progress) >= 0) + return out; + return String::GetVoid(); +} + +String LZMADecompress(const String& s, Gate2 progress) +{ + return LZMADecompress(~s, s.GetLength(), progress); +} + bool LZMACompressFile(const char *dstfile, const char *srcfile, Gate2 progress, int lvl) { FileIn in(srcfile);