Gavin Andresen: implementation of autostart on system startup option on Linux
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@101 1a98c847-1fd6-4fd8-948a-caf3550aa51b
This commit is contained in:
parent
50d49d9c2e
commit
20c6bfad1e
5 changed files with 86 additions and 6 deletions
|
@ -58,6 +58,7 @@
|
|||
#include <boost/bind.hpp>
|
||||
#include <boost/function.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/filesystem/fstream.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/interprocess/sync/interprocess_mutex.hpp>
|
||||
#include <boost/interprocess/sync/interprocess_recursive_mutex.hpp>
|
||||
|
|
77
init.cpp
77
init.cpp
|
@ -117,9 +117,86 @@ void SetStartOnSystemStartup(bool fAutoStart)
|
|||
CoUninitialize();
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(__WXGTK__)
|
||||
|
||||
//
|
||||
// Follow the Desktop Application Autostart Spec:
|
||||
// http://standards.freedesktop.org/autostart-spec/autostart-spec-latest.html
|
||||
//
|
||||
|
||||
boost::filesystem::path GetAutostartDir()
|
||||
{
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
char* pszConfigHome = getenv("XDG_CONFIG_HOME");
|
||||
if (pszConfigHome) return fs::path(pszConfigHome) / fs::path("autostart");
|
||||
char* pszHome = getenv("HOME");
|
||||
if (pszHome) return fs::path(pszHome) / fs::path(".config/autostart");
|
||||
return fs::path();
|
||||
}
|
||||
|
||||
boost::filesystem::path GetAutostartFilePath()
|
||||
{
|
||||
return GetAutostartDir() / boost::filesystem::path("bitcoin.desktop");
|
||||
}
|
||||
|
||||
bool GetStartOnSystemStartup()
|
||||
{
|
||||
boost::filesystem::ifstream optionFile(GetAutostartFilePath());
|
||||
if (!optionFile.good())
|
||||
return false;
|
||||
// Scan through file for "Hidden=true":
|
||||
string line;
|
||||
while (!optionFile.eof())
|
||||
{
|
||||
getline(optionFile, line);
|
||||
if (line.find("Hidden") != string::npos &&
|
||||
line.find("true") != string::npos)
|
||||
return false;
|
||||
}
|
||||
optionFile.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SetStartOnSystemStartup(bool fAutoStart)
|
||||
{
|
||||
if (!fAutoStart)
|
||||
{
|
||||
unlink(GetAutostartFilePath().native_file_string().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
boost::filesystem::create_directories(GetAutostartDir());
|
||||
|
||||
boost::filesystem::ofstream optionFile(GetAutostartFilePath(), ios_base::out|ios_base::trunc);
|
||||
if (!optionFile.good())
|
||||
{
|
||||
wxMessageBox(_("Cannot write autostart/bitcoin.desktop file"), "Bitcoin");
|
||||
return;
|
||||
}
|
||||
// Write a bitcoin.desktop file to the autostart directory:
|
||||
char pszExePath[MAX_PATH+1];
|
||||
memset(pszExePath, 0, sizeof(pszExePath));
|
||||
readlink("/proc/self/exe", pszExePath, sizeof(pszExePath)-1);
|
||||
optionFile << "[Desktop Entry]\n";
|
||||
optionFile << "Type=Application\n";
|
||||
optionFile << "Name=Bitcoin\n";
|
||||
optionFile << "Exec=" << pszExePath << "\n";
|
||||
optionFile << "Terminal=false\n";
|
||||
optionFile << "Hidden=false\n";
|
||||
optionFile.close();
|
||||
}
|
||||
}
|
||||
#else
|
||||
|
||||
// TODO: OSX startup stuff; see:
|
||||
// http://developer.apple.com/mac/library/documentation/MacOSX/Conceptual/BPSystemStartup/Articles/CustomLogin.html
|
||||
|
||||
bool GetStartOnSystemStartup() { return false; }
|
||||
void SetStartOnSystemStartup(bool fAutoStart) { }
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ class CDataStream;
|
|||
class CAutoFile;
|
||||
|
||||
static const int VERSION = 300;
|
||||
static const char* pszSubVer = ".1";
|
||||
static const char* pszSubVer = ".2";
|
||||
|
||||
|
||||
|
||||
|
|
6
ui.cpp
6
ui.cpp
|
@ -1444,8 +1444,10 @@ COptionsDialog::COptionsDialog(wxWindow* parent) : COptionsDialogBase(parent)
|
|||
//m_listBox->Append(_("Test 2"));
|
||||
m_listBox->SetSelection(0);
|
||||
SelectPage(0);
|
||||
#ifndef __WXMSW__
|
||||
m_checkBoxMinimizeOnClose->SetLabel(_("&Minimize on close"));
|
||||
#ifdef __WXGTK__
|
||||
m_checkBoxStartOnSystemStartup->SetLabel(_("&Start Bitcoin on window system startup"));
|
||||
#endif
|
||||
#ifdef __WXMAC_OSX__
|
||||
m_checkBoxStartOnSystemStartup->Enable(false); // not implemented yet
|
||||
#endif
|
||||
|
||||
|
|
6
util.cpp
6
util.cpp
|
@ -559,9 +559,9 @@ string MyGetSpecialFolderPath(int nFolder, bool fCreate)
|
|||
|
||||
string GetDefaultDataDir()
|
||||
{
|
||||
// Windows: C:\Documents and Settings\username\Application Data\Appname
|
||||
// Mac: ~/Library/Application Support/Appname
|
||||
// Unix: ~/.appname
|
||||
// Windows: C:\Documents and Settings\username\Application Data\Bitcoin
|
||||
// Mac: ~/Library/Application Support/Bitcoin
|
||||
// Unix: ~/.bitcoin
|
||||
#ifdef __WXMSW__
|
||||
// Windows
|
||||
return MyGetSpecialFolderPath(CSIDL_APPDATA, true) + "\\Bitcoin";
|
||||
|
|
Loading…
Reference in a new issue