aboutsummaryrefslogtreecommitdiff
path: root/mayaPlug/shaveIcon.cpp
diff options
context:
space:
mode:
authorBen Marsh <[email protected]>2019-10-22 09:07:59 -0400
committerBen Marsh <[email protected]>2019-10-22 09:07:59 -0400
commitbd0027e737c6512397f841c22786274ed74b927f (patch)
treef7ffbdb8f3741bb7f24635616cc189cba5cb865c /mayaPlug/shaveIcon.cpp
downloadarchived-shave-and-a-haircut-bd0027e737c6512397f841c22786274ed74b927f.tar.xz
archived-shave-and-a-haircut-bd0027e737c6512397f841c22786274ed74b927f.zip
Adding Shave-and-a-Haircut 9.6
Diffstat (limited to 'mayaPlug/shaveIcon.cpp')
-rw-r--r--mayaPlug/shaveIcon.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/mayaPlug/shaveIcon.cpp b/mayaPlug/shaveIcon.cpp
new file mode 100644
index 0000000..6c1aaf7
--- /dev/null
+++ b/mayaPlug/shaveIcon.cpp
@@ -0,0 +1,98 @@
+// Shave and a Haircut
+// (c) 2019 Epic Games
+// US Patent 6720962
+
+#ifndef OSMac_
+#include <sys/types.h>
+#else
+#include "shaveMacCarbon.h"
+#endif
+
+#include <sys/stat.h>
+
+#ifndef _WIN32
+#include <unistd.h>
+#endif
+
+#include <maya/MIntArray.h>
+#include <maya/MString.h>
+#include <maya/MStringArray.h>
+
+#include "shaveIcon.h"
+
+MStringArray shaveIcon::mIcons;
+MIntArray shaveIcon::mTimestamps;
+
+
+//
+// See header file for documentation.
+//
+bool shaveIcon::needsReload(MString iconFile)
+{
+#ifdef _WIN32
+ struct _stat fileInfo;
+ bool fileExists = (_stat(iconFile.asChar(), &fileInfo) == 0);
+#else
+ struct stat fileInfo;
+
+# if defined(OSMac_) && !defined(OSMac_MachO_)
+ MString hfsFileName = shaveMacCarbon::makeMacFilename(iconFile);
+ bool fileExists = (stat(hfsFileName.asChar(), &fileInfo) == 0);
+#else
+ bool fileExists = (stat(iconFile.asChar(), &fileInfo) == 0);
+# endif
+#endif
+ bool reload = false;
+
+ unsigned int i;
+ unsigned int numEntries = mIcons.length();
+
+ for (i = 0; i < numEntries; i++)
+ if (mIcons[i] == iconFile) break;
+
+ if (fileExists)
+ {
+ if (i == numEntries)
+ {
+ //
+ // New icon.
+ //
+ mIcons.append(iconFile);
+ mTimestamps.append((long)fileInfo.st_mtime);
+ }
+ else
+ {
+ if (fileInfo.st_mtime != mTimestamps[i])
+ {
+ //
+ // File has been modified since we last saw it, so update
+ // its timestamp and force a reload.
+ //
+ mTimestamps[i] = (long)fileInfo.st_mtime;
+ reload = true;
+ }
+ }
+ }
+ else
+ {
+ if (i < numEntries)
+ {
+ //
+ // This file used to exist, but no longer does, so force a
+ // reload and reset the timestamp to zero so that if it shows
+ // up again, we'll force another reload.
+ //
+ reload = true;
+ mTimestamps[i] = 0L;
+ }
+ }
+
+ return reload;
+}
+
+
+void shaveIcon::cleanup()
+{
+ mIcons.clear();
+ mTimestamps.clear();
+}