152: def self.state_file(mode = 0644)
153: return @state_file unless @state_file.nil?
154:
155: @mode = mode
156:
157: begin
158: require 'Win32API'
159:
160: csidl_common_appdata = 0x0023
161: path = 0.chr * 260
162: get_folder_path = Win32API.new('shell32', 'SHGetFolderPath', 'LLLLP', 'L')
163: get_folder_path.call 0, csidl_common_appdata, 0, 1, path
164:
165: state_dir = File.join(path.strip)
166: rescue LoadError
167: state_dir = File.join('', 'var', 'tmp')
168: end
169:
170: @state_file = File.join(state_dir, 'ruby-uuid')
171:
172: if !File.writable?(state_dir) || (File.exists?(@state_file) && !File.writable?(@state_file)) then
173: @state_file = File.expand_path('.ruby-uuid', '~')
174: end
175:
176: @state_file
177: end