Skip to content

Commit

Permalink
LinuxOsRelease
Browse files Browse the repository at this point in the history
  • Loading branch information
edocevoli committed Sep 15, 2018
1 parent fd68393 commit 23d7457
Show file tree
Hide file tree
Showing 5 changed files with 188 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ if(WIN32 AND NOT UNIX)
set(MIKTEX_NATIVE_WINDOWS TRUE)
else()
set(MIKTEX_UNIX_ALIKE TRUE)
if(NOT APPLE)
set(MIKTEX_LINUX TRUE)
endif()

endif()

if(CMAKE_SYSTEM_NAME MATCHES "BSD/OS")
Expand Down
21 changes: 21 additions & 0 deletions Libraries/MiKTeX/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ if(MIKTEX_NATIVE_WINDOWS)
list(APPEND public_headers ${public_headers_win})
endif()

if(MIKTEX_LINUX)
set(public_headers_tux
${CMAKE_CURRENT_SOURCE_DIR}/include/miktex/Core/tux/LinuxOsRelease
${CMAKE_CURRENT_SOURCE_DIR}/include/miktex/Core/tux/LinuxOsRelease.h
)
list(APPEND public_headers ${public_headers_tux})
endif()

set(cfg_sources
${CMAKE_CURRENT_SOURCE_DIR}/Cfg/Cfg.cpp
)
Expand Down Expand Up @@ -334,6 +342,11 @@ else()
list(APPEND misc_sources
${CMAKE_CURRENT_SOURCE_DIR}/unx/unx.cpp
)
if(MIKTEX_LINUX)
list(APPEND misc_sources
${CMAKE_CURRENT_SOURCE_DIR}/tux/LinuxOsRelease.cpp
)
endif()
endif()

set(pathname_sources
Expand Down Expand Up @@ -573,6 +586,14 @@ if(INSTALL_MIKTEX_HEADERS)
${MIKTEX_HEADER_DESTINATION_DIR}/miktex/Core/win
)
endif()
if(MIKTEX_LINUX)
install(
FILES
${public_headers_tux}
DESTINATION
${MIKTEX_HEADER_DESTINATION_DIR}/miktex/Core/tux
)
endif()
endif()

if(NOT LINK_EVERYTHING_STATICALLY)
Expand Down
24 changes: 24 additions & 0 deletions Libraries/MiKTeX/Core/include/miktex/Core/tux/LinuxOsRelease
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* miktex/Core/LinuxOsVersion: -*- C++ -*-
Copyright (C) 2018 Christian Schenk
This file is part of the MiKTeX Core Library.
The MiKTeX Core Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The MiKTeX Core Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the MiKTeX Core Library; if not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */

#pragma once

#include "LinuxOsRelease.h"
47 changes: 47 additions & 0 deletions Libraries/MiKTeX/Core/include/miktex/Core/tux/LinuxOsRelease.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* LinuxOsRelease.h: -*- C++ -*-
Copyright (C) 2018 Christian Schenk
This file is part of the MiKTeX Core Library.
The MiKTeX Core Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The MiKTeX Core Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the MiKTeX Core Library; if not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */

#pragma once

#include <miktex/Core/config.h>

#include <string>

class LinuxOsRelease
{
public:
std::string id;

public:
std::string name;

public:
std::string pretty_name;

public:
std::string version_id;

public:
std::string version;

public:
static MIKTEXCORECEEAPI(LinuxOsRelease) Get();
};
92 changes: 92 additions & 0 deletions Libraries/MiKTeX/Core/tux/LinuxOsRelease.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/* LinuxOsRelease.cpp:
Copyright (C) 2018 Christian Schenk
This file is part of the MiKTeX Core Library.
The MiKTeX Core Library is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2, or
(at your option) any later version.
The MiKTeX Core Library is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the MiKTeX Core Library; if not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA. */

#include "StdAfx.h"

#include "internal.h"

#include "miktex/Core/Cfg.h"
#include "miktex/Core/tux/LinuxOsRelease.h"

using namespace MiKTeX::Core;
using namespace std;


string Unquote(const string& s)
{
size_t len = s.length();
if (len < 2 || s[0] != '"' || s[len - 1] != '"')
{
return s;
}
return s.substr(1, len - 1);
}

LinuxOsRelease ReadOsRelease()
{
LinuxOsRelease result;
unique_ptr<Cfg> cfg = Cfg::Create();
cfg->Read("/etc/os-release");
for (const shared_ptr<Cfg::Key>& key : cfg->GetKeys())
{
for (const shared_ptr<Cfg::Value>& val : key->GetValues())
{
if (val->GetName() == "ID")
{
result.id = Unquote(val->GetValue());
}
else if (val->GetName() == "PRETTY_NAME")
{
result.pretty_name = Unquote(val->GetValue());
}
else if (val->GetName() == "VERSION_ID")
{
result.version_id = Unquote(val->GetValue());
}
else if (val->GetName() == "VERSION")
{
result.version = Unquote(val->GetValue());
}
}
}
return result;
}

class LazyLinuxOsRelease
{
private:
LinuxOsRelease linuxOsRelease;
public:
operator LinuxOsRelease()
{
if (linuxOsRelease.id.empty())
{
linuxOsRelease = ReadOsRelease();
}
}
};

LazyLinuxOsRelease linuxOsRelease;

LinuxOsRelease LinuxOsRelease::Get()
{
return linuxOsRelease;
}

0 comments on commit 23d7457

Please sign in to comment.