aboutsummaryrefslogtreecommitdiff
path: root/mayaPlug/shaveIcon.cpp
blob: 6c1aaf72ef6066b2c29540541b964d5cb0c7a74a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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();
}