1/******************************************************************************
2	NintendoWare for CTR Maya Plugin
3
4	File:         NW4C_CommonProc.mel
5	Description:  common procedure
6	Date:         2009/09/02
7
8	Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
9******************************************************************************/
10
11// NW4C_ShowHelp
12// NW4C_SetCurDirFromFile
13
14/******************************************************************************
15	show help
16******************************************************************************/
17global proc NW4C_ShowHelp(string $file, string $label)
18{
19	string $rootPath = getenv("NW4C_ROOT");
20	if (size($rootPath) == 0)
21	{
22		error "NW4C_ROOT is not defined";
23	}
24	if (size(match("/$", $rootPath)) == 0)
25	{
26		$rootPath += "/";
27	}
28	string $helpPath = $rootPath + "documents/DccPlugin/Maya/" + $file;
29	//if (!`filetest -f $helpPath`)
30	//{
31	//	error ("Help file is not found: " + $helpPath);
32	//}
33	if (size($label) != 0)
34	{
35		$helpPath += "#" + $label;
36	}
37	$helpPath = "file:///" + $helpPath;
38	showHelp -a $helpPath;
39}
40
41/******************************************************************************
42	get unix file path
43		convert "\" to "/"
44		multi-byte is supported for 8.5-
45******************************************************************************/
46global proc string NW4C_GetUnixFilePath(string $path)
47{
48	int $size = size($path);
49	string $dst = "";
50	int $ic;
51	for ($ic = 1; $ic <= $size; ++$ic)
52	{
53		$c = substring($path, $ic, $ic);
54		if ($c == "\\")
55		{
56			$c = "/";
57		}
58		$dst += $c;
59	}
60	return $dst;
61}
62
63/******************************************************************************
64	set current directory from file
65
66		for fileBrowserDialog
67******************************************************************************/
68global proc NW4C_SetCurDirFromFile(string $path)
69{
70	if (size($path) == 0)
71	{
72		return;
73	}
74
75	string $projPath = `workspace -q -rd`;
76	string $dirPath = dirname($path);
77	string $checks[] =
78	{
79		$path,
80		$projPath + $path,
81		$dirPath,
82		$projPath + $dirPath
83	};
84
85	for ($check in $checks)
86	{
87		if (`filetest -d $check`)
88		{
89			workspace -dir $check;
90			return;
91		}
92	}
93}
94