Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 089486972756
Choose a base ref
...
head repository: ngscopeclient/scopehal-apps
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 973cdeba73c2
Choose a head ref
  • 7 commits
  • 4 files changed
  • 2 contributors

Commits on Sep 26, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    c48bd36 View commit details
  2. Some smaller fixes

    nshcat committed Sep 26, 2020
    Copy the full SHA
    6419085 View commit details
  3. Copy the full SHA
    c9af2ca View commit details
  4. Fixed some stupid bugs -_-

    nshcat committed Sep 26, 2020
    Copy the full SHA
    113a525 View commit details

Commits on Sep 27, 2020

  1. Moved FS utilties to new file

    nshcat committed Sep 27, 2020
    Copy the full SHA
    5ffd6a9 View commit details
  2. Spaces -> Tabs ;)

    nshcat committed Sep 27, 2020
    Copy the full SHA
    6ce8d02 View commit details
  3. Merge pull request #198 from nshcat/master

    Replace `system()` usage in SerializeWaveforms
    azonenberg authored Sep 27, 2020
    Copy the full SHA
    973cdeb View commit details
Showing with 152 additions and 3 deletions.
  1. +1 −0 src/glscopeclient/CMakeLists.txt
  2. +96 −0 src/glscopeclient/FileSystem.cpp
  3. +48 −0 src/glscopeclient/FileSystem.h
  4. +7 −3 src/glscopeclient/OscilloscopeWindow.cpp
1 change: 1 addition & 0 deletions src/glscopeclient/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ add_executable(glscopeclient
ChannelPropertiesDialog.cpp
FileProgressDialog.cpp
FilterDialog.cpp
FileSystem.cpp
Framebuffer.cpp
HaltConditionsDialog.cpp
HistoryWindow.cpp
96 changes: 96 additions & 0 deletions src/glscopeclient/FileSystem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include "FileSystem.h"

#ifdef _WIN32
#include <windows.h>
#include <shlwapi.h>
#include <fileapi.h>
#include <shellapi.h>
#else
#include <glob.h>
#include <stdlib.h>
#include <fcntl.h>
#include <ftw.h>
#include <stdio.h>
#endif


using namespace std;


vector<string> Glob(const string& pathPattern, bool onlyDirectories)
{
vector<string> result{ };

#ifdef _WIN32
WIN32_FIND_DATA findData{ };
HANDLE fileSearch{ };

fileSearch = FindFirstFileEx(
pathPattern.c_str(),
FindExInfoStandard,
&findData,
onlyDirectories ? FindExSearchLimitToDirectories : 0,
NULL,
0
);

if(fileSearch != INVALID_HANDLE_VALUE)
{
while(FindNextFile(fileSearch, &findData))
{
const auto* dir = findData.cFileName;

if(!strcmp(dir, "..") || !strcmp(dir, "."))
continue;

if(!onlyDirectories || (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
results.push_back(string{dir});
}
}
}
#else
glob_t globResult{ };
glob(pathPattern.c_str(), onlyDirectories ? GLOB_ONLYDIR : 0, NULL, &globResult);

if(globResult.gl_pathc > 0)
{
for(auto ix = 0U; ix < globResult.gl_pathc; ++ix)
{
const auto* dir = globResult.gl_pathv[ix];
result.push_back(string{dir});
}
}

globfree(&globResult);
#endif

return result;
}

void RemoveDirectory(const string& basePath)
{
#ifdef _WIN32
SHFILEOPSTRUCT deleteDir = {
NULL,
FO_DELETE,
basePath.c_str(),
NULL,
FOF_SILENT | FOF_NOERRORUI | FOF_NOCONFIRMATION,
FALSE,
NULL,
NULL
};

SHFileOperation(&deleteDir);
#else
const auto deleteTree =
[](const char* path, const struct stat*, int, struct FTW*) -> int
{
::remove(path);
return 0;
};

nftw(basePath.c_str(), deleteTree, 32, FTW_DEPTH);
#endif
}
48 changes: 48 additions & 0 deletions src/glscopeclient/FileSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***********************************************************************************************************************
* *
* ANTIKERNEL v0.1 *
* *
* Copyright (c) 2012-2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL *
* THE AUTHORS BE HELD LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
* POSSIBILITY OF SUCH DAMAGE. *
* *
***********************************************************************************************************************/

/**
@file
@author Katharina B
@brief Common file system utilities
*/

#ifndef FileSystem_h
#define FileSystem_h

#include <string>
#include <vector>

// Find all files/directories matching given pattern
std::vector<std::string> Glob(const std::string& pathPattern, bool onlyDirectories);

// Remove given directory and all its contents
void RemoveDirectory(const std::string& basePath);

#endif // FileSystem_h
10 changes: 7 additions & 3 deletions src/glscopeclient/OscilloscopeWindow.cpp
Original file line number Diff line number Diff line change
@@ -40,6 +40,7 @@
#include "TriggerPropertiesDialog.h"
#include "TimebasePropertiesDialog.h"
#include "FileProgressDialog.h"
#include "FileSystem.h"
#include <unistd.h>
#include <fcntl.h>

@@ -1535,12 +1536,15 @@ string OscilloscopeWindow::SerializeUIConfiguration(IDTable& table)
*/
void OscilloscopeWindow::SerializeWaveforms(IDTable& table)
{
//Remove all old waveforms in the data directory.
//TODO: better way that doesn't involve system()
char cwd[PATH_MAX];
getcwd(cwd, PATH_MAX);
chdir(m_currentDataDirName.c_str());
system("rm -rf scope_*");

const auto directories = ::Glob("scope_*", true);

for(const auto& directory: directories)
::RemoveDirectory(directory);

chdir(cwd);

//Serialize waveforms for each of our instruments